@pacedyn/mcp 1.31.5 → 1.31.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +46 -46
- package/dist/worker.js +7 -7
- package/package.json +1 -1
package/dist/worker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{parentPort as wP,workerData as XG}from"node:worker_threads";import{readFileSync as ax}from"node:fs";import{join as sx}from"node:path";var vl=e=>e.format!=="points"&&!e.field;var pt=e=>e?.kind==="ice";var _x={packVoltageMax:600,segmentVoltageMax:120,powerLimitKw:80};var je=e=>typeof e=="number"&&Number.isFinite(e);function CP(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(je))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(je))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(je))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(je))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(je))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 TP(e){return!e||typeof e!="object"?"The cell has no curve.":e.kind==="table"?CP(e):e.kind==="analytic"?!je(e.vCut)||!je(e.vNom)||!je(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?!je(e.r0)||e.r0<0?"The cell resistance must be a number and cannot be negative.":e.socAtNom!==void 0&&(!je(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 kl(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(!je(t.capacityAh)||t.capacityAh<=0)return"The cell capacity must be a positive number of amp-hours.";if(!je(t.vMin)||t.vMin<0)return"The cut-off voltage must be a number and cannot be negative.";if(!je(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(!je(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&&(!je(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&&(!je(t.massKg)||t.massKg<0))return"The cell mass must be a number and cannot be negative.";let r=TP(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(!je(o.heatCapacityJPerK)||o.heatCapacityJPerK<=0)return"The cell heat capacity must be a positive number of joules per kelvin.";if(!je(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&&!je(o.startC))return"The starting temperature must be a number.";if(o.entropicVPerK!==void 0&&!je(o.entropicVPerK))return"The entropic coefficient must be a number.";if(o.derateFromC!==void 0){if(!je(o.derateFromC))return"The temperature the derate starts at must be a number.";if(o.derateToC!==void 0){if(!je(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(!je(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 ao(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 Ue(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 Ml(e,t,r,n,o){let a=e.length,s=t.length;if(a===0||s===0)return 0;let i=ao(e,n),c=ao(t,o),l=Math.min(i.i+1,a-1),u=Math.min(c.i+1,s-1),m=r[c.i][i.i],d=r[c.i][l],p=r[u][i.i],h=r[u][l],f=m+i.t*(d-m),b=p+i.t*(h-p);return f+c.t*(b-f)}var pa=[0,.05,.1,.2,.3,.4,.5,.6,.7,.8,.9,1],Fd={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]},Nx=[0,.05,.1,.2,.5,.8,1],Ox=[2.2,1.55,1.3,1.12,1,.97,.98];function Vx(e){return Ue(Nx,Ox,e)}var Bx=[-20,-10,0,10,25,40,60],$x=[4,2.8,2,1.4,1,.82,.75];function Cd(e){return Ue(Bx,$x,e)}var Gx=.5;function Td(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=Fd[t]??Fd.other,l=e.socAtNom??Gx,u=pa.includes(l)?[...pa]:[...pa,l].sort((f,b)=>f-b),m=Ue(pa,c,l),d=m>0&&m<1?Math.log(i)/Math.log(m):1,p=[],h=[];for(let f of u){let b=Ue(pa,c,f);p.push(o+s*Math.pow(b,d)),h.push(e.constantResistance?a:a*Vx(f))}return{kind:"table",soc:u,ocv:p,r0:h}}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+=(Ue(t,r,s)+Ue(t,r,i))/2*(i-s)}return o}var da=25,Kx=new WeakMap;function jr(e){let t=Kx.get(e);if(t)return t;let r=kl(e);if(r)throw new Error(r);let{cell:n,pack:o}=e,a=n.curve.kind==="table"?n.curve:Td(n.curve,n.chemistry),s=o.series,i=o.parallel,c=s/i,l=a.rTempC,u=a.rGrid,m=i*n.capacityAh,d=s*n.vMin,p=n.iMaxA>0?i*n.iMaxA:1/0,h=n.iMaxChargeA!==void 0&&n.iMaxChargeA>0?n.iMaxChargeA:n.iMaxA/4,f=h>0?i*h:1/0,b=A=>s*Ue(a.soc,a.ocv,A),g=(A,F=da)=>{let T=l&&u?Ml(a.soc,l,u,A,F):Ue(a.soc,a.r0,A)*Cd(F);return c*T+o.busResistance},y=(A,F,T)=>b(A)-F*g(A,T),x=(A,F,T)=>{if(!(A>0))return 0;let P=b(F),S=g(F,T);if(!(S>0))return A/P;let w=P*P-4*S*A;return w<0?NaN:2*A/(P+Math.sqrt(w))},k=(A,F,T)=>{if(!(A>0))return 0;let P=b(F),S=g(F,T);return S>0?2*A/(P+Math.sqrt(P*P+4*S*A)):A/P},v=A=>{let F=e.thermal;if(!F||F.derateFromC===void 0)return 1;let T=F.derateToC??F.derateFromC;return A<=F.derateFromC?1:!(T>F.derateFromC)||A>=T?0:1-(A-F.derateFromC)/(T-F.derateFromC)},R=(A,F,T=0)=>{let P=b(A),S=g(A,F),w=S>0?P/(2*S):1/0,C=K=>{if(!(S>0))return K*P;let D=Math.min(K,w);return D*(P-D*S)},L=S>0?Math.max(0,(P-d)/S):1/0,E=T>0&&Number.isFinite(T)?T:1/0,_=S>0?C(L):1/0,O=Number.isFinite(p)?C(p):1/0,I=S>0?P*P/(4*S):1/0,z=[["rules",E],["voltage-floor",_],["current",O],["matched-load",I]],B=z[0][0],V=z[0][1];for(let[K,D]of z)D<V&&(V=D,B=K);let j=v(F??da);j<1&&(V=Number.isFinite(V)?V*j:V,B="temperature");let q=Number.isFinite(V)?x(V,A,F):1/0;return{watts:V,binding:B,rules:E,voltageFloor:_,current:O,matchedLoad:I,derate:j,amps:q,volts:Number.isFinite(q)?P-q*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:d,currentCeiling:p,chargeCurrentCeiling:f,massKg:n.massKg!==void 0?s*i*n.massKg:null,thermal:e.thermal?{heatCapacityJPerK:s*i*e.thermal.heatCapacityJPerK,coolingWPerK:s*i*e.thermal.coolingWPerK,...e.thermal.startC!==void 0?{startC:e.thermal.startC}:{},entropicVPerK:s*(e.thermal.entropicVPerK??0)}:null,derateAt:v,ocv:b,resistance:g,terminalVoltage:y,currentFor:x,chargeCurrentFor:k,maxPower:R};return Kx.set(e,M),M}function Ld(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 Hx={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},zx={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},Yx={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 Dd(){return{name:"Formula Student accumulator",cell:Ld(Hx),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 Ed(){return{name:"LFP pack",cell:Ld(zx),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 Id(){return{name:"Road car pack",cell:Ld(Yx),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 _d(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 Sl(e){if(e.kind==="ice"){let n=e.gearbox.efficiency;return{model:e,maxTorque:o=>o>e.limitRpm?0:Ue(e.rpm,e.torque,o),efficiency:()=>n}}let t=n=>Ue(e.rpm,e.torque,n),r=e.kind==="simple"?()=>e.efficiency:(n,o)=>Ml(e.effRpm,e.effTorque,e.effGrid,n,o);return{model:e,maxTorque:t,efficiency:r}}function Nd(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=h=>Math.max(0,e.terminalResistanceOhm*(1+.00393*(h-t))),l=h=>n>0&&o>0?n*Math.pow(Math.max(0,h)/o,a):0,u=(h,f,b)=>{let g=r>0?Math.abs(f)/r:0;return 1.5*c(b)*g*g+l(h)},m=(h,f)=>{let b=e.coolingWPerK*(f-e.coolantC)-l(h);return!(b>0)||r<=0?0:r*Math.sqrt(b/(1.5*c(f)))},d=e.coolingWPerK>0?e.heatCapacityJPerK/e.coolingWPerK:1/0,p=Number.isFinite(d)?.25*d:1/0;return{spec:e,startC:e.startC??e.coolantC,lossW:u,step(h,f,b){if(!(b>0)||!(e.heatCapacityJPerK>0))return h;let g=Number.isFinite(p)?Math.max(1,Math.ceil(b/p)):1,y=b/g,x=h;for(let k=0;k<g;k++)x+=(f-e.coolingWPerK*(x-e.coolantC))*y/e.heatCapacityJPerK;return x},continuousTorque:m,derate(h,f,b){if(s===void 0||i===void 0||!(i>s)||!(b>0)||f<=s)return 1;let g=Math.min(1,m(h,i)/b);return f>=i?g:1-(1-g)*(f-s)/(i-s)},equilibriumC(h){return e.coolingWPerK>0?e.coolantC+h/e.coolingWPerK:1/0}}}function lt(e,t){return t==="rear"&&e.tireRateRear!==void 0?e.tireRateRear:e.tireRate}function Od(e,t){let r=e.tyreFreeRadiusRear;return(t==="rear"&&r!==void 0?r:e.tyreFreeRadius)??0}var Al=9.81,Wx=(e,t)=>e*(t*t)/2*(Math.PI/180)/1e3,_s=(e,t)=>e+t>0?e*t/(e+t):0,jx=.5;function wl(e,t,r){if(!(r>0))return 1;let n=e*Al*t*(Math.PI/180)/r;return 1/(1-Math.min(jx,n))}function Vd(e,t,r){return r>0?e*Al*t/(r*r):0}function Ux(e,t,r,n,o){if(!(n>0)||!(o>0))return 1;let a=Vd(e,t,r)*(1/n+1/o);return 1/(1-Math.min(jx,a))}function Be(e){let t=4*e.unsprungPerCorner,r=Math.max(0,e.massTotal-t),n=r*e.frontMassFrac,o=r*(1-e.frontMassFrac),a=lt(e,"front"),s=lt(e,"rear"),i=e.wheelRateFront+(e.heaveSpringFront??0),c=e.wheelRateRear+(e.heaveSpringRear??0),l=_s(i,a),u=_s(c,s),m=(O,I)=>{let z=I/2;return z>0?1/(2*Math.PI)*Math.sqrt(O*1e3/z):0},d=m(l,n),p=m(u,o),h=_s(e.wheelRateFront+e.arbFront,a),f=_s(e.wheelRateRear+e.arbRear,s),b=Wx(h,e.trackFront),g=Wx(f,e.trackRear),y=b+g,x=y>0?b/y:.5,k=e.rcHeightFront+(e.rcHeightRear-e.rcHeightFront)*(1-e.frontMassFrac),v=(e.cgHeight-k)/1e3,R=r*Al*v,M=wl(r,v,y),A=y>0?R/y*M:0,F=e.massTotal*Al*e.cgHeight/e.wheelbase,T=2*l,P=2*u,S=Ux(r,e.cgHeight,e.wheelbase,T,P),C=(T>0&&P>0?(F/T+F/P)/e.wheelbase*S:0)*(180/Math.PI),L=e.wheelbase*e.wheelbase*_s(T,P)*(Math.PI/180)/1e3,E=e.damperFront??2.5,_=e.damperRear??2.5;return{sprungMass:r,sprungFront:n,sprungRear:o,rideRateFront:l,rideRateRear:u,rideFreqFront:d,rideFreqRear:p,rollRateFront:b,rollRateRear:g,rollRateTotal:y,rollWheelRateFront:h,rollWheelRateRear:f,frontRollStiffFrac:x,rollGradient:A,pitchGradient:C,pitchRate:L,cgRollGain:M,cgPitchGain:S,rideDampingFront:E+(e.heaveDamperFront??0),rideDampingRear:_+(e.heaveDamperRear??0),rollDampingFront:E+(e.rollDamperFront??0),rollDampingRear:_+(e.rollDamperRear??0)}}var Fn=["clFront","clRear","cd"],Cn=e=>e.frame?.kind==="pitch";function fa(e){return Cn(e)?{x:e.axes.h,y:e.axes.pitch}:{x:e.axes.hFront,y:e.axes.hRear}}var Fl=e=>e.frame?.kind==="pitch",Xx=e=>e.kind==="map";var Cl=45,dt=e=>typeof e=="number"&&Number.isFinite(e);function Tl(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(dt))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 qx(e,t){if(t===void 0)return null;for(let r of Fn){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(dt)||!n.factor.every(dt))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 Qx(e,t){return t===void 0?null:!dt(t.dCl)||!dt(t.dBalance)||!dt(t.dCd)?`The ${e} slopes must be numbers.`:!dt(t.maxDeg)||!(t.maxDeg>0)?`The ${e} response needs a positive angle to be valid to.`:null}function Ns(e){if(!e||typeof e!="object")return"Not an aero model.";if(!dt(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=Tl("front ride-height",e.axes?.hFront);if(i)return i;let c=Tl("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(!dt(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=Tl("ride-height",e.axes?.h);if(i)return i;let c=Tl("pitch",e.axes?.pitch,"\xB0","pitch");if(c)return c;let l=e.axes.pitch.find(u=>Math.abs(u)>=Cl);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 Fn){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(dt))return`${i} contains a value that is not a number.`}}return qx("yaw",e.attitude?.yaw)??qx("roll",e.attitude?.roll)}if(e.kind==="sensitivity"){let t;if(e.frame==null)t=["hFront","hRear"];else if(e.frame?.kind==="pitch"){if(!dt(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||!dt(r[t[0]])||!dt(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 Fn){if(!e.at||!dt(e.at[s]))return`${s} at the reference must be a number.`;let i=n?.[s];if(!i||!dt(i[t[0]])||!dt(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||!dt(i[0])||!dt(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])>=Cl||Math.abs(i[1])>=Cl))return`A pitch range reaching ${Math.abs(i[0])>=Cl?i[0]:i[1]}\xB0 is not a car's attitude. Pitch is in degrees.`}return Qx("yaw",e.attitude?.yaw)??Qx("roll",e.attitude?.roll)}return`Unknown aero model kind "${e.kind}".`}var Zx=180/Math.PI;function ha(e,t,r,n){let o=(n-r)/t;return{h:r+e.refX*o,pitch:Math.atan(o)*Zx}}function ba(e,t,r,n){let o=Math.tan(n/Zx);return{hFront:r-e.refX*o,hRear:r+(t-e.refX)*o}}var NK=180/Math.PI,PP=["hFront","hRear"],LP=["h","pitch"],Gd=e=>e?.kind==="pitch"?LP:PP,Yt=(e,t)=>e[t],Pl=(e,t)=>e[t],Bd=(e,t)=>({[e[0]]:t(e[0]),[e[1]]:t(e[1])});function DP(e){if(!(!e.yaw&&!e.roll))return{...e.yaw?{yaw:{...e.yaw}}:{},...e.roll?{roll:{...e.roll}}:{}}}function Kd(e){let t=Gd(e.frame),r=e.balanceFront,n=e.cl*r,o=e.cl*(1-r),a=Bd(t,c=>Yt(e.dCl,c)*r+e.cl*Yt(e.dBalance,c)),s=Bd(t,c=>Yt(e.dCl,c)*(1-r)-e.cl*Yt(e.dBalance,c)),i=DP(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:Bd(t,c=>Yt(e.dCd,c))},range:{[t[0]]:[...Pl(e.range,t[0])],[t[1]]:[...Pl(e.range,t[1])]},provenance:{...e.provenance},...i?{attitude:i}:{}}}function Ll(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 $d(e,t,r=11){let n=Array.from({length:r},(a,s)=>t.maxDeg*s/(r-1)),o=n.map(a=>Ll(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 Jx(e){if(!(!e.attitude?.yaw&&!e.attitude?.roll))return{...e.attitude.yaw?{yaw:$d(e.at,e.attitude.yaw)}:{},...e.attitude.roll?{roll:$d(e.at,e.attitude.roll)}:{}}}function eR(e,t,r,n=0,o=0){let[a,s]=Gd(e.frame),i=t-Yt(e.ref,a),c=r-Yt(e.ref,s),l={clFront:e.at.clFront+Yt(e.slope.clFront,a)*i+Yt(e.slope.clFront,s)*c,clRear:e.at.clRear+Yt(e.slope.clRear,a)*i+Yt(e.slope.clRear,s)*c,cd:e.at.cd+Yt(e.slope.cd,a)*i+Yt(e.slope.cd,s)*c},u=e.attitude?.yaw?Ll(e.at,e.attitude.yaw,n):{clFront:1,clRear:1,cd:1},m=e.attitude?.roll?Ll(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 Hd(e){let[t,r]=Gd(e.frame),n=[...Pl(e.range,t)],o=[...Pl(e.range,r)],a=i=>o.map(c=>n.map(l=>i(eR(e,l,c)))),s=Jx(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 zd=180/Math.PI,tR=new WeakMap,rR=new WeakMap,Yd=new WeakMap;function Tn(e,t){let r=rR.get(e);if(r)return r;let n=t?.wheelbase,o=n!==void 0?Yd.get(e)?.get(n):void 0;if(o)return o;let a=EP(e),s=a.map;if(!Cn(s)){let l=IP(e,a);return rR.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=_P(e,a,s.frame,n),c=Yd.get(e);return c||(c=new Map,Yd.set(e,c)),c.set(n,i),i}function EP(e){let t=tR.get(e);if(t)return t;let r=Ns(e);if(r)throw new Error(r);let n=e.kind==="map"?e:Hd(e),{x:o,y:a}=fa(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},d=(y,x)=>{let k=Math.abs(x),v=y.clFront.deg[y.clFront.deg.length-1];return{clFront:Ue(y.clFront.deg,y.clFront.factor,k),clRear:Ue(y.clRear.deg,y.clRear.factor,k),cd:Ue(y.cd.deg,y.cd.factor,k),clamped:k>v}},p=(y,x)=>{if(!u)return m;let k=c?d(c,y):m,v=l?d(l,x):m;return{clFront:k.clFront*v.clFront,clRear:k.clRear*v.clRear,cd:k.cd*v.cd,clamped:k.clamped||v.clamped}},h=(y,x,k=0,v=0)=>{let R=ao(o,y),M=ao(a,x),A=Math.min(R.i+1,s-1),F=Math.min(M.i+1,i-1),T=S=>{let w=S[M.i][R.i],C=S[M.i][A],L=S[F][R.i],E=S[F][A],_=w+R.t*(C-w),O=L+R.t*(E-L);return _+M.t*(O-_)},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:R.clamped||M.clamped,clampedAttitude:P.clamped}},f={x:[o[0],o[s-1]],y:[a[0],a[i-1]]},b=(y,x,k=!1,v=0,R=0)=>{let M=p(v,R),A=ao(o,k?Math.min(Math.max(y,f.x[0]),f.x[1]):y),F=ao(a,k?Math.min(Math.max(x,f.y[0]),f.y[1]):x),T=Math.min(A.i+1,s-1),P=Math.min(F.i+1,i-1),S=T>A.i?o[T]-o[A.i]:0,w=P>F.i?a[P]-a[F.i]:0,C={};for(let L of Fn){let E=n[L],_=E[F.i][A.i],O=E[F.i][T],I=E[P][A.i],z=E[P][T],B=A.clamped||S===0?0:((O-_)*(1-F.t)+(z-I)*F.t)/S,V=F.clamped||w===0?0:((I-_)*(1-A.t)+(z-O)*A.t)/w;C[L]=u?{x:B*M[L],y:V*M[L]}:{x:B,y:V}}return C},g={map:n,x:f.x,y:f.y,hasAttitude:u,factors:p,at:h,slopes:b};return tR.set(e,g),g}function IP(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 Fn)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 _P(e,t,r,n){let o=r.refX,a=o/n,s=(l,u,m=0,d=0)=>{let p=(u-l)/n;return t.at(l+o*p,Math.atan(p)*zd,m,d)},i=(l,u,m=!1,d=0,p=0)=>{let h=(u-l)/n,f=t.slopes(l+o*h,Math.atan(h)*zd,m,d,p),b=zd/(n*(1+h*h)),g={};for(let y of Fn)g[y]={hFront:f[y].x*(1-a)-f[y].y*b,hRear:f[y].x*a+f[y].y*b};return g},c={frame:r,x:t.x,y:t.y,at:t.at,toAxles:(l,u)=>ba(r,n,l,u),fromAxles:(l,u)=>{let m=ha(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 Wd(e){let t=e.clFront+e.clRear;return{cl:t,balanceFront:t!==0?e.clFront/t:.5}}var Se=(e,t)=>e*t/100,ut=e=>e/100,nR={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:Se(3,-.4),hRear:Se(3,.1)},dBalance:{hFront:ut(-.3),hRear:ut(.15)},dCd:{hFront:Se(1.3,-.1),hRear:Se(1.3,.05)},yaw:{dCl:Se(3,-1),dBalance:ut(-.3),dCd:Se(1.3,.5),maxDeg:10},roll:{dCl:Se(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."},oR={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:Se(3,-.3),hRear:Se(3,-.15)},dBalance:{hFront:ut(-.15),hRear:ut(.15)},dCd:{hFront:Se(.9,-.15),hRear:Se(.9,-.05)},yaw:{dCl:Se(3,-1.5),dBalance:ut(.2),dCd:Se(.9,.8),maxDeg:8},roll:{dCl:Se(3,-1),dBalance:ut(-.3),dCd:0,maxDeg:2},note:"Assumed class-level sensitivities for a ground-effect floor, ride height, yaw and roll; not measured."},aR={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:Se(1.4,-.3),hRear:Se(1.4,.05)},dBalance:{hFront:ut(-.25),hRear:ut(.15)},dCd:{hFront:Se(.42,-.1),hRear:0},yaw:{dCl:Se(1.4,-.8),dBalance:ut(-.2),dCd:Se(.42,.6),maxDeg:10},roll:{dCl:Se(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."},sR={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:Se(.3,.5),maxDeg:10},note:"Assumed class-level sensitivities for a road car with no aero devices; not measured."},iR={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:Se(.45,-.4),hRear:Se(.45,.05)},dBalance:{hFront:ut(-.25),hRear:ut(.15)},dCd:{hFront:Se(.4,-.1),hRear:0},yaw:{dCl:Se(.45,-1.2),dBalance:ut(-.2),dCd:Se(.4,.6),maxDeg:10},roll:{dCl:Se(.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."},cR={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:Se(.6,-.35),hRear:Se(.6,.05)},dBalance:{hFront:ut(-.25),hRear:ut(.15)},dCd:{hFront:Se(.45,-.1),hRear:0},yaw:{dCl:Se(.6,-1),dBalance:ut(-.2),dCd:Se(.45,.6),maxDeg:10},roll:{dCl:Se(.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."},lR={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:Se(2.5,-.35),hRear:Se(2.5,.05)},dBalance:{hFront:ut(-.25),hRear:ut(.15)},dCd:{hFront:Se(.9,-.1),hRear:Se(.9,.05)},yaw:{dCl:Se(2.5,-1),dBalance:ut(-.3),dCd:Se(.9,.5),maxDeg:10},roll:{dCl:Se(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."},uR={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:Se(.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 Ur(e){return Kd({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 jd=()=>Ur(nR),Ud=()=>Ur(oR),Xd=()=>Ur(aR),qd=()=>Ur(sR),Qd=()=>Ur(iR),Zd=()=>Ur(cR),Jd=()=>Ur(lR),ef=()=>Ur(uR);function so(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,lt(e,"front")))/r,rear:(t.sprungMass*(1-n)+o*a(t.rideRateRear,lt(e,"rear")))/r}}function El(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 tf(e,t){return e.wheelbase>0?e.massTotal*t*9.81/e.wheelbase:0}function ga(e,t,r){let n=2*t.rideRateFront,o=2*t.rideRateRear;return!(n>0)||!(o>0)?0:Math.min(Vd(t.sprungMass,r,e.wheelbase),.5*n*o/(n+o))}function Os(e,t,r,n,o){let a=e.cgHeight,s=tf(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,d=0,p=0;for(let f=0;f<6;f++){p=ga(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,d=(g*(c-p)-p*b)/k}else m=c>0?b/c:0,d=l>0?g/l:0;let y=El(a,i,m,d),x=Math.abs(y-u);if(u=y,x<1e-9)break}let h=m-d;return{height:u,forward:e.wheelbase>0?u*h/e.wheelbase:0,noseLoad:p*h,dropFront:m,dropRear:d}}var rf={yawDeg:0,rollDeg:0},mR=1e-4,NP=40,pR=50;function Pn(e,t,r=0){let n=e.aero?.model;if(!(!n||!Tn(n,e).hasAttitude))return{yawDeg:r,rollDeg:Be(e).rollGradient*t}}function ya(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 ba(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=Fl(r)?n(r.frame,r.ref.h,r.ref.pitch):r.ref;else if(r){let{x:a,y:s}=fa(r),i=(a[0]+a[a.length-1])/2,c=(s[0]+s[s.length-1])/2;o=Cn(r)?n(r.frame,i,c):{hFront:i,hRear:c}}return{hFront:e.rideHeightFront??o.hFront,hRear:e.rideHeightRear??o.hRear}}var dR=new WeakMap;function Xr(e,t,r=0,n){let o=e.aero;if(!o?.model)return null;let a=dR.get(e);a||(a=new Map,dR.set(e,a));let s=n&&Tn(o.model,e).hasAttitude?n:rf,i=s===rf?`${t}|${r}`:`${t}|${r}|${s.yawDeg.toFixed(3)}|${s.rollDeg.toFixed(3)}`,c=a.get(i);if(c)return c;let l=OP(e,o,t,r,s);return a.size>4096&&a.clear(),a.set(i,l),l}function OP(e,t,r,n,o){let a=Tn(t.model,e),s=Be(e),i=2*s.rideRateFront,c=2*s.rideRateRear,l=ya(t,e.wheelbase),u=.5*t.rho*r*r,m=a.area,d=e.wheelbase>0?t.copHeight/e.wheelbase:0,p=Dl(e,s),h=tf(e,n),f=(T,P)=>El(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),w=u*m*S.clFront,C=u*m*S.clRear,L=u*m*S.cd,E=L*d,_=f(T,P),O=h*_,I=ga(e,s,_)*b(T,P),z=w-O-E+I,B=C+O+E-I,V=T-l.hFront+(i>0?z/i:0),j=P-l.hRear+(c>0?B/c:0);return{c:S,downFront:w,downRear:C,drag:L,rF:V,rR:j,norm:Math.hypot(V,j)}},y=(T,P,S=!1)=>{let w=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*(w.clFront.hFront-d*w.cd.hFront),C*(w.clFront.hRear-d*w.cd.hRear)],[L*(w.clRear.hFront+d*w.cd.hFront),L*(w.clRear.hRear+d*w.cd.hRear)]]},x=l.hFront,k=l.hRear,v=g(x,k),R=0;for(;v.norm>=mR&&R<NP;){R++;let T=y(x,k),P=i>0?h/i:0,S=c>0?h/c:0,w=ga(e,s,f(x,k)),C=i>0?w/i:0,L=c>0?w/c:0,E=1+T[0][0]-P*p.front-C,_=T[0][1]-P*p.rear+C,O=T[1][0]+S*p.front+L,I=1+T[1][1]+S*p.rear-L,z=E*I-_*O,B,V;Math.abs(z)>1e-9?(B=-(I*v.rF-_*v.rR)/z,V=-(-O*v.rF+E*v.rR)/z):(B=-.5*v.rF,V=-.5*v.rR);let j=Math.max(1,Math.abs(B)/pR,Math.abs(V)/pR);B/=j,V/=j;let q=1;for(let K=0;K<6;K++){let D=g(x+q*B,k+q*V);if(D.norm<=v.norm||K===5){x+=q*B,k+=q*V,v=D;break}q*=.5}}let M=y(x,k,!0),A=2+M[0][0]+M[1][1],F=(1+M[0][0])*(1+M[1][1])-M[0][1]*M[1][0];return{v:r,axG:n,hFront:x,hRear:k,cgHeight:f(x,k),cgForward:e.wheelbase>0?f(x,k)*b(x,k)/e.wheelbase:0,cgNoseLoad:ga(e,s,f(x,k))*b(x,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:VP(M),stable:F>0&&A>0,converged:v.norm<mR,iterations:R,clampedRide:v.c.clampedRide,yawDeg:o.yawDeg,rollDeg:o.rollDeg,clampedAttitude:v.c.clampedAttitude}}function VP(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 Vs(e,t,r=0,n){let o=Xr(e,t,r,n);return o?{downforce:o.downforce,drag:o.drag,downFront:o.downFront,downRear:o.downRear}:e.aero?so(e.aero,t):{downforce:0,drag:0,downFront:0,downRear:0}}function BP(e,t,r,n){let o=so(t,r),a=Be(e),s=ya(t,e.wheelbase),i=e.wheelbase>0?o.drag*t.copHeight/e.wheelbase:0,c=Os(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 nf(e,t,r=0,n){let o=Xr(e,t,r,n);return o||(e.aero?BP(e,e.aero,t,r):null)}function Il(e,t=0,r=0,n,o){if(e.aero&&t>0){if(e.aero.model){let i=Xr(e,t,r,n);return{height:i.cgHeight,forward:i.cgForward,noseLoad:i.cgNoseLoad}}let a=so(e.aero,t),s=e.wheelbase>0?a.drag*e.aero.copHeight/e.wheelbase:0;return Os(e,o??Be(e),r,a.downFront-s,a.downRear+s)}return r===0?{height:e.cgHeight,forward:0,noseLoad:0}:Os(e,o??Be(e),r,0,0)}var fR=[0,1,0],of=[0,0,1],oe=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],G=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Q=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],af=e=>[-e[0],-e[1],-e[2]],J=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],le=(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]],$P=e=>J(e,e),Ln=e=>Math.sqrt(J(e,e)),Bs=(e,t)=>$P(G(e,t)),Ee=(e,t)=>Ln(G(e,t)),te=e=>{let t=Ln(e);return t<1e-12?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]};var Dn=(e,t,r)=>{let n=te(r),o=G(e,t);return oe(t,Q(n,J(o,n)))},hR=(e,t,r)=>Ee(e,Dn(e,t,r));var KP=1e-6;function HP(e){if(e<KP){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 Mt(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]=HP(r),a=le(e,t),s=le(e,a);return oe(t,oe(Q(a,n),Q(s,o)))}function nr(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 Mt(Q(o,r),e)}function Ar(e,t){let r=t.length,n=e.map(a=>a.slice()),o=t.slice();return gR(n,o,r,new Array(r).fill(0))}function bR(e,t,r){return gR(e,t,t.length,r)}function gR(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 d=s;d<r;d++)e[u][d]-=m*e[s][d];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 yR=e=>{let t=0;for(let r of e)t=Math.max(t,Math.abs(r));return t},xR=e=>{let t=0;for(let r of e)t+=r*r;return t},zP=Math.sqrt(Number.EPSILON);function RR(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=yR(c),u=xR(c),m=.001,d=1,p=c.length,h=Array.from({length:p},()=>new Array(a).fill(0)),f=Array.from({length:a},()=>new Array(a).fill(0)),b=Array.from({length:a},()=>new Array(a).fill(0)),g=new Array(a).fill(0),y=new Array(a).fill(0),x=new Array(a).fill(0),k=new Array(a).fill(0),v=new Array(a).fill(0);for(let R=0;R<n;R++){if(l<o)return{x:i,residualNorm:l,iterations:R,converged:!0,condProxy:d};for(let T=0;T<a;T++){let P=zP*Math.max(Math.abs(i[T]),s[T]);for(let w=0;w<a;w++)k[w]=i[w];k[T]+=P;let S=e(k);for(let w=0;w<p;w++)h[w][T]=(S[w]-c[w])/P}let M=0;for(let T=0;T<a;T++){for(let S=0;S<a;S++){let w=0;for(let C=0;C<p;C++)w+=h[C][T]*h[C][S];f[T][S]=w}let P=0;for(let S=0;S<p;S++)P+=h[S][T]*c[S];g[T]=P,M=Math.max(M,f[T][T])}let A=Math.max(M,1e-9),F=!1;for(let T=0;T<18;T++){let P=m*A;for(let w=0;w<a;w++){let C=f[w],L=b[w];for(let E=0;E<a;E++)L[E]=w===E?C[E]+P:C[E];y[w]=-g[w]}let S=bR(b,y,x);if(d=Math.max(d,S.condProxy),!S.singular){for(let L=0;L<a;L++)v[L]=i[L]+x[L];let w=e(v),C=xR(w);if(C<u){for(let L=0;L<a;L++)i[L]=v[L];c=w,u=C,l=yR(c),m=Math.max(m*.3,1e-12),F=!0;break}}m=Math.min(m*4,1e12)}if(!F)break}return{x:i,residualNorm:l,iterations:n,converged:l<o,condProxy:d}}function $s(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 sf(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 vR=e=>[e[0],-e[1],-e[2],-e[3]];function kR(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 MR(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 SR(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 cf(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],d=n+i+m;if(d>=n&&d>=i&&d>=m){let f=Math.sqrt(1+d),b=.5/f;return[.5*f,(c-u)*b,(l-a)*b,(o-s)*b]}if(n>=i&&n>=m){let f=Math.sqrt(1+n-i-m),b=.5/f;return[(c-u)*b,.5*f,(s+o)*b,(l+a)*b]}if(i>=m){let f=Math.sqrt(1-n+i-m),b=.5/f;return[(l-a)*b,(s+o)*b,.5*f,(u+c)*b]}let p=Math.sqrt(1-n-i+m),h=.5/p;return[(o-s)*h,(l+a)*h,(u+c)*h,.5*p]}function AR(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 wR(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 YP(e){let t=Math.abs(e[0])<.6?[1,0,0]:[0,1,0],r=te(le(e,t));return[r,le(e,r)]}function WP(e){let t=e.hardpoints,r=te(G(t.damperChassis,t.pushrodOuter)),[n,o]=YP(r);return{top:t.damperChassis,lower0:t.pushrodOuter,axis0:r,e1:n,e2:o}}function lf(e){let t=e.hardpoints,r=t.wheelCenter,n=te(G(t.ucaRear,t.ucaFront)),o=G(t.uprightUpper,t.ucaFront),a=J(o,n),s=G(o,Q(n,a)),i=J(s,s),c=te(G(t.lcaRear,t.lcaFront)),l=G(t.uprightLower,t.lcaFront),u=Bs(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:te(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:WP(e)}:{}}}function or(e,t,r){let n=[t[3],t[4],t[5]],o=[t[0],t[1],t[2]],a=G(r,e.c0);return oe(oe(Mt(n,a),e.c0),o)}function uf(e,t){return oe(e.lcaFront,nr(e.lbjRel0,e.lcaDir,t))}function io(e,t){return e.steerMovesRack?oe(e.tieInner0,Q(e.rackAxis,t)):e.tieInner0}function mf(e,t,r,n){let o=or(e,t,e.lbj0),a=uf(e,r),s=o[0]-a[0],i=o[1]-a[1],c=o[2]-a[2],l,u;if(e.strut){let h=e.strut,f=[t[3],t[4],t[5]],b=G(h.top,or(e,t,h.lower0));l=J(b,Mt(f,h.e1)),u=J(b,Mt(f,h.e2))}else{let h=or(e,t,e.ubj0),f=G(h,e.ucaFront),b=J(f,e.ucaDir),g=G(f,Q(e.ucaDir,b));l=b-e.ubjAxial0,u=(J(g,g)-e.ubjRadius2)/e.ubjRadiusRef}let m=or(e,t,e.tro0),d=io(e,n),p=(Bs(m,d)-e.tieLen2)/e.tieLenRef;return[s,i,c,l,u,p]}var Gs=e=>Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]),_l=e=>{let t=Gs(e);return[e[0]/t,e[1]/t,e[2]/t]},jP=(e,t)=>G(e,Q(t,J(e,t))),pf=e=>_l(le(e,Math.abs(e[0])<.6?[1,0,0]:[0,1,0]));function UP(e,t){let r=e.ucaDir,n=oe(e.ucaFront,Q(r,e.ubjAxial0)),o=Math.sqrt(e.ubjRadius2),a=jP(G(e.ubj0,e.ucaFront),r),s=Gs(a)>1e-9?_l(a):pf(r),i=le(r,s),c=G(e.ubj0,e.lbj0),l=J(c,c);if(!(l>1e-18))return"free";let u=G(n,t),m=J(u,u),d=$s(2*o*J(s,u),2*o*J(i,u),l-m-o*o,2*o*Math.sqrt(m));if(d.free)return"free";let p=_l(c),h=(f,b)=>{let g=oe(n,oe(Q(s,o*f),Q(i,o*b))),y=_l(G(g,t));return{q1:MR(p,y),k:y,margin:d.margin,ok:d.ok}};return d.margin>0?[h(d.c1,d.s1),h(d.c2,d.s2)]:[h(d.c1,d.s1)]}function XP(e,t,r){let n=t.axis0,o=oe(t.lower0,Q(n,J(G(e.lbj0,t.lower0),n))),a=G(o,e.lbj0),s=Gs(a),i=s>1e-9?Q(a,1/s):pf(n),c=G(t.top,r),l=Gs(c);if(!(l>1e-9))return"free";let u=Q(c,1/l),m=s/l,d=1-m,p=d>=0?Math.sqrt((1-m)*(1+m)):0,h=pf(u),f=b=>{let g=b*p,y=oe(Q(u,g),Q(h,Math.min(m,1))),x=G(Q(u,Math.min(m,1)),Q(h,g));return{q1:sf(cf(x,y,le(x,y)),vR(cf(i,n,le(i,n)))),k:u,margin:d,ok:d>=0}};return d>0?[f(1),f(-1)]:[f(1)]}function qP(e,t,r,n){let{k:o}=n,a=kR(n.q1,G(e.tro0,e.lbj0)),s=J(a,o),i=G(a,Q(o,s)),c=Gs(i);if(!(c>1e-9))return"free";let l=Q(i,1/c),u=le(o,l),m=oe(t,Q(o,s)),d=G(m,r),p=J(d,d),h=$s(2*c*J(d,l),2*c*J(d,u),e.tieLen2-p-c*c,2*c*Math.sqrt(p));if(h.free)return"free";let f=(g,y)=>({q:sf(SR(o,g,y),n.q1)});return{roots:h.margin>0?[f(h.c1,h.s1),f(h.c2,h.s2)]:[f(h.c1,h.s1)],margin:h.margin,ok:h.ok}}function FR(e,t,r,n=[0,0,0,0,0,0]){let o=uf(e,t),a=io(e,r),s=AR([n[3],n[4],n[5]]),i=f=>Math.abs(f[0]*s[0]+f[1]*s[1]+f[2]*s[2]+f[3]*s[3]),c=e.strut?XP(e,e.strut,o):UP(e,o);if(c==="free")return{x:n.slice(),converged:!1,margin:0,free:!0};let l=null,u=null;for(let f of c){let b=qP(e,o,a,f);if(b==="free")return{x:n.slice(),converged:!1,margin:0,free:!0};let g=Math.min(f.margin,b.margin),y=b.ok&&f.ok;for(let{q:x}of b.roots){let k=i(x);y&&(!l||k>l.near)&&(l={q:x,margin:g,near:k}),!y&&(!u||k>u.near)&&(u={q:x,margin:g,near:k})}}let{q:m,margin:d}=l??u,p=wR(m),h=G(G(o,e.c0),Mt(p,G(e.lbj0,e.c0)));return{x:[h[0],h[1],h[2],p[0],p[1],p[2]],converged:l!==null,margin:d,free:!1}}function TR(e){let t=te(G(e.rockerPivotB,e.rockerPivotA));return{pivotA:e.rockerPivotA,axis:t,rprRel0:G(e.rockerToPushrod,e.rockerPivotA),rdmRel0:G(e.rockerToDamper,e.rockerPivotA),damperChassis:e.damperChassis,rodLen2:Bs(e.pushrodOuter,e.rockerToPushrod),damperLen0:Ee(e.rockerToDamper,e.damperChassis)}}var QP=(e,t)=>oe(e.pivotA,nr(e.rprRel0,e.axis,t)),df=(e,t)=>oe(e.pivotA,nr(e.rdmRel0,e.axis,t));function xa(e,t){return{pushrod:QP(e,t),damper:df(e,t)}}function PR(e,t,r=0){let n=J(e.rprRel0,e.axis),o=G(e.rprRel0,Q(e.axis,n)),a=le(e.axis,o),s=G(oe(e.pivotA,Q(e.axis,n)),t),i=J(o,o),c=J(s,s),l=$s(2*J(s,o),2*J(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:Ee(df(e,r),e.damperChassis),converged:p,margin:0}}let u=CR(Math.atan2(l.s1,l.c1),r),m=CR(Math.atan2(l.s2,l.c2),r),d=Math.abs(m-r)<Math.abs(u-r)?m:u;return{phi:d,damperLength:Ee(df(e,d),e.damperChassis),converged:l.ok,margin:l.margin}}function CR(e,t){let r=2*Math.PI;return e+r*Math.round((t-e)/r)}function LR(e,t,r,n){return oe(t,Mt(Q(te(r),n),G(e,t)))}function DR(e,t,r,n){let o=te(n),a=d=>{let p=G(d,r);return G(p,Q(o,J(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,J(s,i)/(c*l))),m=J(le(s,i),o)/(c*l);return Math.atan2(m,u)}function ER(e,t,r,n){return oe(t,Mt(Q(te(r),n),G(e,t)))}var Nl=180/Math.PI,ZP=(e,t,r)=>Math.max(t,Math.min(r,e)),IR=[NaN,NaN,NaN];function Ks(e){let t=te(e.spinAxis),r=te(G(e.uprightUpper,e.uprightLower)),n=-Math.asin(ZP(t[2],-1,1))*Nl,o=Math.atan2(t[0],t[1])*Nl,a=Math.atan2(-r[0],r[2])*Nl,s=Math.atan2(-r[1],r[2])*Nl,i=te(oe([0,0,-1],Q(t,t[2]))),c=oe(e.wheelCenter,Q(i,e.loadedRadius)),l=e.patchShift?[c[0]+e.patchShift.x,c[1]+e.patchShift.y,c[2]]:c,u=e.uprightLower,m=Math.abs(r[2])>1e-9,d=F=>oe(u,Q(r,(F-u[2])/r[2])),p=m?d(l[2]):IR,h=m?d(e.wheelCenter[2]):IR,f=l[1]-p[1],b=p[0]-l[0],g=te(le(t,[0,0,1])),y=le([0,0,1],g),x=G(l,p),k=J(x,y),v=-J(x,g),R=e.wheelCenter[1]-h[1],M=h[0]-e.wheelCenter[0],A=hR(e.tieOuter,u,r);return{camber:n,toe:o,caster:a,kpi:s,scrubRadius:f,mechanicalTrail:b,scrubAtWheel:k,trailAtWheel:v,kingpinOffset:R,casterOffset:M,steeringArm:A,contactPatch:l,kingpinGround:p,kingpinAtHub:h}}function gt(e){return{corner:e,inv:lf(e),rocker:TR(e.hardpoints)}}var JP=[20,20,20,.2,.2,.2];function NR(e,t,r,n=[0,0,0,0,0,0]){let o=FR(e,t,r,n);if(!o.free)return o;let a=eL(e,t,r,n);return{x:a.x,converged:a.converged,margin:0}}function eL(e,t,r,n=[0,0,0,0,0,0]){return RR(o=>mf(e,o,t,r),n,{scales:JP,tol:1e-10,maxIter:40})}var tL=.01,Ol=1.2,Lt=e=>e.ok?e.state:null,St=e=>e.ok?e.state:e.nearest;function we(e,t,r,n,o){let a=0,s=qe(e,a,r,n,o);if(Math.abs(s.travel-t)<1e-4)return _R(s,t,!1);let c=(qe(e,.02,r,ff(s),o).travel-s.travel)/.02;(!Number.isFinite(c)||Math.abs(c)<1e-6)&&(c=1);let l=d=>Math.max(-Ol,Math.min(Ol,d)),u=l((t-s.travel)/c),m=qe(e,u,r,ff(s),o);for(let d=0;d<12&&!(Math.abs(m.travel-t)<1e-4);d++){let p=m.travel-s.travel,h=Math.abs(p)<1e-9?u:u-(m.travel-t)*((u-a)/p);a=u,s=m,u=l(h),m=qe(e,u,r,ff(s),o)}return _R(m,t,Math.abs(u)===Ol)}function _R(e,t,r){let n=e.travel-t,o=Math.abs(n)<=tL,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 ff(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 rL(e,t,r,n,o){switch(e){case"upright":return or(t,r,o.pushrodOuter);case"upperArm":{let a=or(t,r,t.ubj0),s=DR(t.ubj0,a,t.ucaFront,t.ucaDir);return ER(o.pushrodOuter,t.ucaFront,t.ucaDir,s)}default:return LR(o.pushrodOuter,t.lcaFront,t.lcaDir,n)}}function qe(e,t,r,n,o){let{inv:a,corner:s}=e,i=n?.q??[0,0,0,0,0,0],c=NR(a,t,r,i),l=c.x,u=[l[3],l[4],l[5]],m={t:[l[0],l[1],l[2]],omega:u},d=s.hardpoints,p=s.config,h=a.strut,f=h?h.top:or(a,l,d.uprightUpper),b=or(a,l,d.uprightLower),g=or(a,l,d.tieOuter),y=or(a,l,d.wheelCenter),x=te(Mt(u,p.spinAxis)),k=rL(h?"upright":p.pushrodAttach,a,l,t,d),v=h?h.top:d.damperChassis,R=h||p.actuation==="direct"?{phi:0,damperLength:Ee(k,v),converged:!0,margin:1}:PR(e.rocker,k,n?.phi??0),M=Ks({uprightUpper:f,uprightLower:b,wheelCenter:y,spinAxis:x,tieOuter:g,loadedRadius:o?.loadedRadius??p.loadedRadius,patchShift:o?.patchShift});return{pose:m,beta:t,travel:l[2],steer:r,points:{uprightUpper:f,uprightLower:b,tieOuter:g,wheelCenter:y,pushrodOuter:k,spinAxis:x,contactPatch:M.contactPatch,kingpinGround:M.kingpinGround,kingpinAtHub:M.kingpinAtHub,rockerAngle:R.phi,damperLength:R.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:R.damperLength},converged:c.converged&&R.converged,margin:Math.min(c.margin,R.margin)}}var Ra=e=>e==="FL"||e==="FR"?"front":"rear",VR=e=>e==="FL"||e==="RL"?"left":"right";function Qe(e,t){return e.corners?.[t]??nL(e[Ra(t)],VR(t))}function BR(e){let t=e.config.springSplit;return e.config.actuation==="decoupled"||t===void 0||!Number.isFinite(t)||Math.abs(t)>=1?0:t}var OR=new WeakMap;function nL(e,t){let r=BR(e);if(r===0)return e;let n=OR.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)},OR.set(e,n)}return n[t]}var wr=["FL","FR","RL","RR"],Ot=e=>2*e.hardpoints.wheelCenter[1],ar=(e,t)=>t?Ot(Qe(e,"FL"))/2+Ot(Qe(e,"FR"))/2:Ot(Qe(e,"RL"))/2+Ot(Qe(e,"RR"))/2;function nt(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 Wt(e,t){return[t.axleX+e[0],t.sideSign*e[1],e[2]]}function qr(e,t){return[e[0],t.sideSign*e[1],e[2]]}function En(e){return e.frontAxleX-e.wheelbase/2}function hf(e,t,r){return t[2]+e.heave+(t[0]-r)*Math.sin(e.pitch)-t[1]*Math.sin(e.roll)}function In(e,t,r,n){let o=nt(e,t),a=(n?ar(n,o.isFront):o.isFront?t.trackFront:t.trackRear)/2,s=o.sideSign*a,i=o.axleX-En(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 oL={travelMin:-40,travelMax:40,steps:41,steer:0};function Hs(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 ot(e,t={}){let r={...oL,...t},n=gt(e);return va(n,r)}function va(e,t){let r=t.steer,n=.01,o=qe(e,n,r),a=qe(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=qe(e,0,r);u.push({beta:0,travel:m.travel,warm:Hs(m),converged:m.converged});let d=Hs(m);for(let x=1;x<=l;x++){let k=c*x/l,v=qe(e,k,r,d);d=Hs(v),u.push({beta:k,travel:v.travel,warm:d,converged:v.converged})}d=Hs(m);for(let x=1;x<=l;x++){let k=-c*x/l,v=qe(e,k,r,d);d=Hs(v),u.push({beta:k,travel:v.travel,warm:d,converged:v.converged})}u.sort((x,k)=>x.beta-k.beta);let p=u[u.length-1].travel>=u[0].travel,h=!1;for(let x=1;x<u.length;x++){let k=u[x].travel-u[x-1].travel;(p&&k<-1e-6||!p&&k>1e-6)&&(h=!0)}let f=u.filter(x=>x.converged).map(x=>x.travel),b=f.length?[Math.min(...f),Math.max(...f)]:[0,0],g=f.length>0&&b[0]<=t.travelMin+1e-6&&b[1]>=t.travelMax-1e-6,y=[];for(let x=0;x<t.steps;x++){let k=t.steps===1?t.travelMin:t.travelMin+(t.travelMax-t.travelMin)*x/(t.steps-1),v=aL(u,k,p),R=sL(u,v);y.push(qe(e,v,r,R))}return iL(y,e.corner.config.actuation==="decoupled"?0:e.corner.config.springRate),{samples:y,covered:g,reach:b,fold:h,unconverged:y.filter(x=>!x.converged).length}}function aL(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 sL(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 bf(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 iL(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=bf(n,r,s),c=bf(o,r,s),l=-bf(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 Vl=e=>e!==void 0&&Number.isFinite(e)&&e>0;function cL(e){return e&&Vl(e.helperRate)&&Vl(e.helperTravel)?{rate:e.helperRate,travel:e.helperTravel}:null}function gf(e,t,r){let n=t/e;return r?n+Math.min(t/r.rate,r.travel):n}function zs(e,t,r,n){if(!(e>0)||!Number.isFinite(e)||!(t>0)||!Number.isFinite(t))return null;let o=cL(n),a=-gf(e,t,o),s=ka(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 ka(e,t){if(!Number.isFinite(e))return{droop:null,bump:null};let r=Vl(t?.extended)&&t.extended>e?t.extended:null,n=r!==null&&Vl(t?.stroke)?r-t.stroke:null;return{droop:r!==null?e-r:null,bump:n!==null&&n<e?e-n:null}}function yf(e,t){if(!(e>0)||!Number.isFinite(e))return null;let r=ka(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 lL(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=gf(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 uL(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=gf(r,n,o)+t;return a<=0?0:a>=o.rate*o.travel/r+o.travel?r:r*o.rate/(r+o.rate)}function Ma(e,t){let r=lL(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 xf(e,t){let r=uL(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 Rf(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 Bl={min:-60,max:60,steps:61},vf=e=>({travel:[e.min,e.max],force:[0,0],motionRatio:[0,0],spring:null}),$R=new WeakMap;function mL(e,t){let r=$R.get(e.corner);r||$R.set(e.corner,r=new Map);let n=`${t.min}|${t.max}|${t.steps}`,o=r.get(n);return o||r.set(n,o=va(e,{travelMin:t.min,travelMax:t.max,steps:t.steps,steer:0})),o}function Ws(e,t,r=Bl,n=e.corner.config.coilover){let o=e.corner.config;if(o.actuation==="decoupled")return vf(r);let a=mL(e,r),s=dL(e,o.springRate,a.samples),i=[];for(let f of a.samples){let b=f.metrics.motionRatio;!f.converged||b===void 0||!Number.isFinite(b)||!Number.isFinite(f.metrics.damperLength)||i.length>0&&f.travel<=i[i.length-1].t+1e-6||i.push({t:f.travel,L:f.metrics.damperLength,mr:b})}if(i.length<2)return vf(r);let c=hL(i,0);if(!(Math.abs(c.mr)>1e-6))return vf(r);let l=t/c.mr,u=zs(s,l,c.L,n),m=u?pL(i,Rf(u).map(f=>c.L-f)):i,d=m.map(f=>(u?Ma(u,c.L-f.L):l+s*(c.L-f.L))*f.mr-t),p=f=>f===null?null:m.find(b=>b.L===c.L-f)?.t??null,h=u?Rf(u).map(p).filter(f=>f!==null):[];return{travel:m.map(f=>f.t),force:d,motionRatio:m.map(f=>f.mr),spring:{rate:s,preload:l,length0:c.L,law:u},...u?{stops:{droop:p(u.droop),bump:p(u.bump)}}:{},...h.length?{kinks:h}:{},length:m.map(f=>f.L)}}function kf(e,t){if(!e.spring)return null;let r=e.travel.length,n=e.length;if(n&&n.length===r&&r>=2){let s=Fr(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+=(Ys(e,i)+Ys(e,c))/2*(c-i)}return a}function pL(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 dL(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:fL(e,n,r);return!(o>0)||!Number.isFinite(o)?t:t*o/(t+o)}function fL(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=xa(e.rocker,n.points.rockerAngle),s=te(G(o.rockerPivotB,o.rockerPivotA)),i=(m,d)=>Math.abs(J(s,le(G(m,o.rockerPivotA),te(G(d,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 Ys(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.motionRatio[0];let n=Fr(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 Qr(e,t,r){if(!e.spring)return dr(e,t);let{rate:n,preload:o,length0:a,law:s}=e.spring,i=Ys(e,0),c=a-r;return(s?Ma(s,c):o+n*c)*Ys(e,t)-o*i}function hL(e,t){let r=Fr(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 Fr(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 dr(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.force[0];let n=Fr(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 Sa(e,t){let r=e.travel.length;if(r<3)return js(e,t);let n=Fr(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 js(e,t){if(e.travel.length<2)return 0;let n=Fr(e.travel,t);return(e.force[n+1]-e.force[n])/(e.travel[n+1]-e.travel[n])}function ze(e,t,r){let n=e.hardpoints;switch(t.attach){case"upright":{let o=G(t.outer,n.wheelCenter);return oe(oe(Mt(r.pose.omega,o),n.wheelCenter),r.pose.t)}case"lowerArm":{let o=te(G(n.lcaRear,n.lcaFront));return oe(n.lcaFront,Mt(Q(o,r.beta),G(t.outer,n.lcaFront)))}case"rocker":{let o=te(G(n.rockerPivotB,n.rockerPivotA));return oe(n.rockerPivotA,nr(G(t.outer,n.rockerPivotA),o,r.points.rockerAngle))}}}function _n(e,t,r){return e.config.actuation==="decoupled"&&t.attach==="rocker"&&r==="coil"}function Mf(e,t,r){return _n(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 Sf(e,t,r.kind,ot(e,{travelMin:n,travelMax:o,steps:a}).samples)}function Sf(e,t,r,n){let o=te(G(t.outer,Mf(e,t,r))),a=[],s=[],i=t.outer;for(let p of n)a.push(p.travel),s.push(J(G(ze(e,t,p),i),o));let c=a.length,l=new Array(c).fill(0);for(let p=0;p<c;p++){let h=Math.max(0,p-1),f=Math.min(c-1,p+1),b=a[f]-a[h];l[p]=b!==0?(s[f]-s[h])/b:0}let u=l[0];for(let p=1;p<c;p++)if(a[p]>=0){let h=a[p]-a[p-1],f=h!==0?(0-a[p-1])/h:0;u=l[p-1]+f*(l[p]-l[p-1]);break}let m=l.filter(p=>Math.abs(p)>1e-9).map(Math.sign),d=m.length>0&&m.some(p=>p!==m[0]);return{travel:a,ratio:l,linkTravel:s,atDesign:u,reverses:d}}function Af(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 wf(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 Us=e=>e.mount??{kind:"rockerToRocker"},zR=e=>[e[0],0,e[2]],bL=e=>2*Math.abs(e[1]),gL=(e,t)=>Math.hypot(e[0]-t[0],e[2]-t[2]);function Gl(e,t){return t.kind==="chassis"?gL(e,t.anchor):bL(e)}function Xs(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 co(e,t,r={}){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return Ff(e,t,ot(e,{travelMin:n,travelMax:o,steps:a}).samples)}function Ff(e,t,r){let n=Us(t),o=h=>ze(e,{...t,inner:t.outer},r[h]),a=[],s=[],i=[];for(let h=0;h<r.length;h++)a.push(r[h].travel),i.push(Gl(o(h),n));let c=KR(a,i,0);for(let h of i)s.push(c-h);let l=a.length,u=new Array(l).fill(0);for(let h=0;h<l;h++){let f=Math.max(0,h-1),b=Math.min(l-1,h+1),g=a[b]-a[f];u[h]=g!==0?(s[b]-s[f])/g:0}let m=GR(a,20),d=GR(a,-20),p=Xs(o(m),o(d),n);return{travel:a,ratio:u,springTravel:s,atDesign:KR(a,u,0),installedLength:c,rollSensitivity:c-p}}function GR(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 KR(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 Cf(e,t,r){let n={outer:t.outer,attach:t.attach},o=ot(e,{travelMin:-5,travelMax:5,steps:3}),a=h=>zR(ze(e,{...n,inner:n.outer},o.samples[h])),s=a(1),i=a(2),c=a(0),l=i[0]-c[0],u=i[2]-c[2],m=Math.hypot(l,u),d=m>1e-9?[l/m,u/m]:[0,1],p=r??Math.max(80,2*Math.abs(t.outer[1])*.5);return[s[0]+d[0]*p,0,s[2]+d[1]*p]}function Tf(e,t){let r=e.hardpoints,n=r.rockerPivotA,o=HR($l(r.rockerPivotB,r.rockerPivotA)),a=Math.max(30,.6*YR($l(r.rockerToDamper,n))),s=$l(r.rockerToDamper,n),i=HR($l(s,yL(o,xL(s,o)))),c=RL(o,i),l=null,u=-1/0;for(let m=0;m<360;m+=10){let d=m*Math.PI/180,h={outer:[n[0]+a*(Math.cos(d)*i[0]+Math.sin(d)*c[0]),n[1]+a*(Math.cos(d)*i[1]+Math.sin(d)*c[1]),n[2]+a*(Math.cos(d)*i[2]+Math.sin(d)*c[2])],attach:"rocker"},f=t==="chassis"?{...h,mount:{kind:"chassis",anchor:Cf(e,h)}}:h,b;try{b=co(e,f,{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=f)}return l??{outer:r.rockerToDamper,attach:"rocker"}}var $l=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],yL=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],xL=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],YR=e=>Math.hypot(e[0],e[1],e[2]),HR=e=>{let t=YR(e)||1;return[e[0]/t,e[1]/t,e[2]/t]},RL=(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,vL=e=>({outer:e.outer,inner:e.outer,attach:e.attach}),JR=(e,t,r)=>(Gl(e.at0,t)-Gl(r,t))/2,kL=(e,t)=>J(G(t,e.pickup.at0),e.axis);function Lf(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=>Lf(e,t.map(o=>o[n])));return t.map((n,o)=>[r[0][o],r[1][o],r[2][o]])}function Df(e){return{travel:e,heave:e.map(t=>t/2),heaveRatio:e.map(()=>.5),roll:[...e],rollRatio:e.map(()=>1)}}function jR(e,t,r,n){let o=e.corner;if(!t.heave&&!t.roll)return{side:Df([n.min,n.max]),pickups:{}};let a=St(we(e,0,0)),s={};if(t.heave&&r){let f=vL(t.heave);s.heave={corner:o,link:f,at0:ze(o,f,a)}}if(t.roll){let f=t.roll;s.roll={pickup:{corner:o,link:f,at0:ze(o,f,a)},axis:te(G(f.outer,Mf(o,f,t.rollKind??"coil")))}}let i=t.roll&&_n(o,t.roll,t.rollKind??"coil")?{near:t.roll,far:{...t.roll,outer:t.roll.inner}}:null,c=va(e,{travelMin:n.min,travelMax:n.max,steps:n.steps,steer:0}),l=[],u=[],m=[],d=[],p=[];for(let f of c.samples)!f.converged||l.length>0&&f.travel<=l[l.length-1]+1e-6||(l.push(f.travel),u.push(s.heave&&r?JR(s.heave,r,ze(o,s.heave.link,f)):f.travel/2),m.push(s.roll?kL(s.roll,ze(o,s.roll.pickup.link,f)):f.travel),i&&(d.push(ze(o,i.near,f)),p.push(ze(o,i.far,f))));if(l.length<2)return{side:Df([n.min,n.max]),pickups:{}};let h={travel:l,heave:u,heaveRatio:Lf(l,u),roll:m,rollRatio:Lf(l,m)};return i&&(h.eyes={near:d,nearRatio:WR(l,d),far:p,farRatio:WR(l,p)}),{side:h,pickups:s}}function Kl(e,t,r){let n=Fr(e,r);return t[n]+(r-e[n])/(e[n+1]-e[n])*(t[n+1]-t[n])}function UR(e,t,r){let n=Fr(e,r);return(t[n+1]-t[n])/(e[n+1]-e[n])}function Ze(e,t){return{h:Kl(e.travel,e.heave,t),dh:Kl(e.travel,e.heaveRatio,t),ddh:UR(e.travel,e.heaveRatio,t),r:Kl(e.travel,e.roll,t),dr:Kl(e.travel,e.rollRatio,t),ddr:UR(e.travel,e.rollRatio,t)}}function XR(e,t,r,n){let o=Fr(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 Ef=(e,t)=>Math.hypot(e[0]-t[0],e[1]+t[1],e[2]-t[2]);function If(e,t){let r=e.side[0].eyes,n=e.side[1].eyes;if(!r||!n)return null;let o=XR(e.side[0].travel,r.near,r.nearRatio,t[0]),a=XR(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]],d=J(c,l),p=J(c,u),h=(J(l,u)-d*p)/i;return{L:i,dL:[d,p],ddL:[[(J(l,l)-d*d)/i+J(c,o.dd),h],[h,(J(u,u)-p*p)/i+J(c,m)]]}}var ev=(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,ML=(e,t)=>e.bump!==null&&t>e.bump||e.droop!==null&&t<e.droop?e.rate:0;function qs(e,t,r,n,o=0){let a=e.rollStop;if(!a)return r;let s=If(e,t);if(!s)return r;let i=ev(a,a.length0-(n??s.L+o));return i===0?r:[r[0]-i*s.dL[0],r[1]-i*s.dL[1]]}function Hl(e,t){let r=Df(e.travel);return t==="heave"?{...e,heave:r.heave,heaveRatio:r.heaveRatio}:{...e,roll:r.roll,rollRatio:r.rollRatio}}var zl=(e,t)=>e?e.law?Ma(e.law,t):e.preload+e.rate*t:0,qR=(e,t)=>e?e.law?xf(e.law,t):e.rate:0;function Qs(e,t,r,n,o){let a=zl(e.heave,n),s=zl(e.roll,o);return[a*t.dh+s*t.dr,a*r.dh-s*r.dr]}var QR=(e,t)=>Ze(e[0],t).h+Ze(e[1],t).h;function SL(e,t){let r=e.gap>0?QR(t,e.gap):0;return e.bothWays?{free:r,pull:e.gap>0?QR(t,-e.gap):0}:{free:r,pull:null}}function AL(e,t,r){let n={...t,outer:t.inner},o=(u,m)=>{let d=Lt(we(e[0],u,0)),p=Lt(we(e[1],m,0));if(!d||!p)return NaN;let h=ze(e[0].corner,t,d),f=ze(e[1].corner,n,p);return Math.hypot(h[0]-f[0],h[1]+f[1],h[2]-f[2])},a=1,s=o(0,0),i=o(-a,a)-o(a,-a),c=Ze(r[0],a).r-Ze(r[1],-a).r-(Ze(r[0],-a).r-Ze(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 tv(e,t,r,n=Bl){let o=r.heave?Us(r.heave):void 0,a=jR(e[0],r,o,n),s=e[1].corner===e[0].corner?a:jR(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,d=(t[0].arbRate+t[1].arbRate)/2,p=i.map(w=>Ze(w,0));c&&!(Math.abs(p[0].dh+p[1].dh)>Pf)&&(i=[Hl(i[0],"heave"),Hl(i[1],"heave")],c=!1),l&&!(Math.abs(p[0].dr+p[1].dr)>Pf)&&(i=[Hl(i[0],"roll"),Hl(i[1],"roll")],l=!1),p=i.map(w=>Ze(w,0));let h=p[0].dh+p[1].dh,f=p[0].dr+p[1].dr,b=m>0?2*m/(h*h):0,g=d>0?2*d/(f*f):0,y=0,x=0;if(r.carriesLoad){let w=[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=(-w[0]*p[1].dr-w[1]*p[0].dr)/C,x=(p[0].dh*w[1]-p[1].dh*w[0])/C)}else b>0?y=(w[0]+w[1])/h:g>0&&(x=(w[0]-w[1])/f)}let k={};if(c&&o){let w=[a.pickups.heave,s.pickups.heave];k.heave={pickups:w,mount:o,span0:Xs(w[0].at0,w[1].at0,o)}}let v=k.heave?k.heave.span0:NaN,R=k.heave?r.coilover:void 0,M=r.carriesLoad?zs(b,y,v,R):u?yf(b,{...SL(u,i),length0:v,coilover:R}):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&&_n(e[0].corner,r.roll,r.rollKind??"coil"))){let w=AL(e,r.roll,i);w&&(k.roll.unit=w)}let F=g>0?{rate:g,preload:x}:null,T={side:i,heave:A,roll:F,force0:[0,0],carriesLoad:r.carriesLoad,read:k},P=k.roll?.unit,S=P&&g>0&&i[0].eyes&&i[1].eyes?ka(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=qs(T,[0,0],Qs(T,p[0],p[1],p[0].h+p[1].h,p[0].r-p[1].r)),T}function Zs(e,t,r){let n=Ze(e.side[0],t[0]),o=Ze(e.side[1],t[1]),a=r?qs(e,t,Qs(e,n,o,n.h+o.h+r.heave,n.r-o.r+r.roll),void 0,r.unit):qs(e,t,Qs(e,n,o,n.h+o.h,n.r-o.r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function _f(e,t,r){let n=Ze(e.side[0],t[0]),o=Ze(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=qR(e.heave,a),c=qR(e.roll,s),l=zl(e.heave,a),u=zl(e.roll,s),m=i*n.dh*o.dh-c*n.dr*o.dr,d=[[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,h=p?If(e,t):null;if(!p||!h)return d;let f=p.length0-(r?h.L+r.unit:h.L),b=ML(p,f);if(b===0)return d;let g=ev(p,f),y=(k,v)=>b*h.dL[k]*h.dL[v]-g*h.ddL[k][v],x=m+y(0,1);return[[d[0][0]+y(0,0),x],[x,d[1][1]+y(1,1)]]}function Nf(e,t,r){let n=_f(e,t);return n[r][0]+n[r][1]}function wL(e,t,r){let n=e.read.heave;if(!n)return Ze(e.side[0],t[0]).h+Ze(e.side[1],t[1]).h;let[o,a]=n.pickups;return n.span0-Xs(ze(o.corner,o.link,r[0]),ze(a.corner,a.link,r[1]),n.mount)}function FL(e,t,r){let n=e.read.roll;if(!n)return Ze(e.side[0],t[0]).r-Ze(e.side[1],t[1]).r;let o=a=>J(G(ze(n.pickups[a].corner,n.pickups[a].link,r[a]),n.pickups[a].at0),n.axes[a]);return o(0)-o(1)}function CL(e,t){let r=e.read.roll;if(!e.rollStop||!r)return;let[n,o]=r.pickups;return Ef(ze(n.corner,n.link,t[0]),ze(o.corner,{...o.link,outer:o.link.inner},t[1]))}function Js(e,t,r){let n=Ze(e.side[0],t[0]),o=Ze(e.side[1],t[1]),a=qs(e,t,Qs(e,n,o,wL(e,t,r),FL(e,t,r)),CL(e,r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function Of(e,t,r,n){let o=Ze(e.side[0],r),a=Ze(e.side[1],r),s=e.read.heave,i=s?.pickups[t],c=s&&i&&n?2*JR(i,s.mount,ze(i.corner,i.link,n)):o.h+a.h,l=e.rollStop&&n?e.read.roll?.pickups[t]:void 0,u=l&&n?Ef(ze(l.corner,l.link,n),ze(l.corner,{...l.link,outer:l.link.inner},n)):void 0;return qs(e,[r,r],Qs(e,o,a,c,n?0:o.r-a.r),u)[t]-e.force0[t]}function Vf(e,t,r,n){let o=Sa(e,r[n]);return t?.carriesLoad?o+Nf(t,r,n):o}function rv(e,t){return Ze(e.side[0],t[0]).h+Ze(e.side[1],t[1]).h}function nv(e,t){return If(e,t)?.L??null}var Bf=e=>e==="FR"||e==="RR"?1:0,Yl=(e,t)=>e.elements?.[t==="FL"||t==="FR"?"front":"rear"]??null;var ov=e=>Number.isFinite(e)&&e>0?1/e:0;var av=(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},TL=(e,t)=>[e[0][0]*t[0]+e[0][1]*t[1],e[1][0]*t[0]+e[1][1]*t[1]],sv=1e-8,PL=40;function LL(e,t,r,n){return{force:(s,i)=>{if(r){let u=Zs(r,s,n);return[dr(t[0],s[0])+i[0]+u[0],dr(t[1],s[1])+i[1]+u[1]]}let c=(s[0]+s[1])/2,l=(s[0]-s[1])/2;return[dr(t[0],s[0])+i[0]+e[0].heaveRate*c+e[0].arbRate*l,dr(t[1],s[1])+i[1]+e[1].heaveRate*c-e[1].arbRate*l]},stiffness:(s,i=js)=>{if(r){let c=_f(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 wa(e,t,r,n,o,a=[0,0],s=[0,0],i=null,c){let l=[ov(r[0].tyreRate),ov(r[1].tyreRate)],u=[r[0].staticLoad,r[1].staticLoad],m=LL(r,n,i,c),d=C=>m.force(C,a),p=m.stiffness([0,0]),h=[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]))],f=(C,L)=>{let E=L===1?d(C):m.force(C,[a[0]*L,a[1]*L]),_=[E[0]+s[0]*L,E[1]+s[1]*L],O=[C[0]+t[0]*L+_[0]*l[0]-e[0]*L,C[1]+t[1]*L+_[1]*l[1]-e[1]*L],I=[h[0]*(u[0]+_[0]),h[1]*(u[1]+_[1])],z=[I[0]<O[0],I[1]<O[1]];return{f:_,on:O,off:I,lifted:z,r:[Math.min(O[0],I[0]),Math.min(O[1],I[1])]}},b=(C,L)=>[L[0]?[h[0]*C[0][0],h[0]*C[0][1]]:[1+C[0][0]*l[0],C[0][1]*l[0]],L[1]?[h[1]*C[1][0],h[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]],_=f(E,L),O=!1,I=0;for(;I<PL;I++){if(g(_.r)<sv){O=!0;break}let z=av(b(m.stiffness(E),_.lifted),[-_.r[0],-_.r[1]]);if(!z)break;let B=1,V=[E[0]+z[0],E[1]+z[1]],j=f(V,L);for(let q=0;q<8&&g(j.r)>g(_.r);q++)B/=2,V=[E[0]+B*z[0],E[1]+B*z[1]],j=f(V,L);E=V,_=j}return!O&&g(_.r)<sv&&(O=!0),{t:E,b:_,converged:O,it:I}},x=y(o?[o[0],o[1]]:[e[0]-t[0],e[1]-t[1]],1),k=x.it;if(!x.converged){let C=0,L=[0,0],E=.25;for(;C<1&&E>=1/256;){let _=Math.min(1,C+E),O=y(L,_);k+=O.it,O.converged?(C=_,L=O.t,_===1&&(x=O)):E/=2}}let{t:v,b:R,converged:M}=x,A=R.lifted,F=[A[0]?-u[0]:R.f[0],A[1]?-u[1]:R.f[1]],T=[A[0]?Math.max(0,R.on[0]):0,A[1]?Math.max(0,R.on[1]):0],P=m.stiffness(v,Sa),S=b(P,A);return{t:v,dF:F,lifted:A,clearance:T,converged:M,iterations:k,respond:(C,L,E=[0,0])=>{let _=[A[0]?-h[0]*E[0]:C[0]-L[0]-E[0]*l[0],A[1]?-h[1]*E[1]:C[1]-L[1]-E[1]*l[1]],O=av(S,_);if(!O)return[NaN,NaN];let I=TL(P,O);return[A[0]?0:I[0]+E[0],A[1]?0:I[1]+E[1]]}}}var lo=e=>!(Number.isFinite(e.tyreRate)&&e.tyreRate>0);function sr(e,t,r){return t?.input.corners[r].staticLoadedRadius??e}var $f=["FL","FR","RL","RR"],lv={front:["FL","FR"],rear:["RL","RR"]},DL=512,EL=5e-4,IL=8;function Wl(e,t){let r={},n={},o=new Map;for(let s of $f){let i=e.ctx[s],c=t.corners[s],l=c.staticLoadedRadius;n[s]=St(we(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=`${$f.findIndex(p=>Qe(e.vehicle,p)===Qe(e.vehicle,s))}|${c.springLoad}|${u?`${u.extended}/${u.stroke}`:""}`,d=o.get(m);d?r[s]=d:(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=lv[s];a[s]=tv([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 uv(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 _L=e=>`${e.heave}|${e.pitch}|${e.roll}|${e.steer}`;function Gf(e,t,r){return{travel:r.travel,steer:r.steer,ground:r.travel,tyreDeflection:0,load:NaN,loadedRadius:sr(Qe(e.vehicle,t).config.loadedRadius,e.kc,t),lifted:!1,contactLength:0,converged:!0,rigid:!0,rideRate:NaN,wheelRateAtLoad:NaN}}var NL=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 iv(e,t,r,n){let o=lv[n],a=e.vehicle.config,s=o.map(F=>In(F,a,r,e.vehicle)),i=[t.input.corners[o[0]],t.input.corners[o[1]]],c=t.loadCase;if(!c&&i.every(lo))return{corners:[Gf(e,o[0],s[0]),Gf(e,o[1],s[1])],respond:null};let l=o.map(F=>t.curve[F]),u=t.elements?.[n]??null,m=o.map(F=>sr(Qe(e.vehicle,F).config.loadedRadius,t,F)),d=[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],h=[c?.patchShift[o[0]],c?.patchShift[o[1]]],f=[0,0],b=[0,0],g,y=wa(d,f,i,l,void 0,void 0,p,u),x=[void 0,void 0],k=[!0,!0],v=[0,0],R=!1;for(let F=0;F<IL;F++){F>0&&(y=wa(d,f,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 w=0;w<2;w++){let C=we(e.ctx[o[w]],y.t[w],s[w].steer,NL(x[w]),{loadedRadius:m[w]-v[w],patchShift:h[w]}),L=St(C);x[w]=L,k[w]=C.ok,T[w]=L.points.contactPatch[2]-t.ground0[o[w]]-y.t[w]-v[w],P[w]=Qr(l[w],y.t[w],L.points.damperLength)-dr(l[w],y.t[w])}if(u){let w=Js(u,y.t,[x[0],x[1]]),C=Zs(u,y.t);P[0]+=w[0]-C[0],P[1]+=w[1]-C[1]}let S=Math.max(Math.abs(T[0]-f[0]),Math.abs(T[1]-f[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(f=T,b=P,g=y.t,S<EL){R=!0;break}}let M=y.respond([1,1],[0,0]);return{corners:[0,1].map(F=>{let T=x[F];return{travel:y.t[F],steer:s[F].steer,ground:d[F],tyreDeflection:v[F],load:i[F].staticLoad+y.dF[F],loadedRadius:m[F]-v[F],lifted:y.lifted[F],clearance:y.clearance[F],contactLength:uv(m[F]-v[F],i[F].staticLoad+y.dF[F],i[F].tyreRate),converged:y.converged&&R&&k[F],rigid:!1,state:T,solved:k[F],rideRate:M[F],wheelRateAtLoad:Vf(l[F],u,y.t,F)}}),respond:y.respond}}function mv(e,t){let r=e.kc,n=_L(t),o=r.memo.get(n);if(o)return o;let a=iv(e,r,t,"front"),s=iv(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>=DL&&r.memo.clear(),r.memo.set(n,i),i}function Vt(e,t){if(!e.kc){let r={};for(let n of $f)r[n]=Gf(e,n,In(n,e.vehicle.config,t,e.vehicle));return r}return mv(e,t).corners}function jl(e,t,r){return e.kc?mv(e,t).respond[r]:null}function ei(e,t,r,n=0){let o=e.kc;if(!o)return r;let a=o.input.corners[t];if(lo(a))return r;let s=In(t,e.vehicle.config,{heave:0,pitch:0,roll:0,steer:n},e.vehicle).steer,i=sr(Qe(e.vehicle,t).config.loadedRadius,o,t),c=o.loadCase,l=c?.linkLoad[t]??0,u=c?.patchShift[t],m=St(we(e.ctx[t],r,s,void 0,{loadedRadius:i,patchShift:u})),d=Yl(o,t),p=Qr(o.curve[t],r,m.points.damperLength)+(d?Of(d,Bf(t),r,m):a.heaveRate*r),f=Math.max(p+l,-a.staticLoad)/a.tyreRate;return(f===0?m:St(we(e.ctx[t],r,s,void 0,{loadedRadius:i-f,patchShift:u}))).points.contactPatch[2]-o.ground0[t]-(c?.ground[t]??0)}var OL=180/Math.PI,VL=[0,0,1];function BL(e,t){let r=qr(e,t),n=Q(le(VL,r),-t.sideSign);return-Math.atan2(n[1],n[0])*OL}var pv=e=>1/Math.tan(e*Math.PI/180),dv=.05,fv=.001;function hv(e,t,r){if(!Number.isFinite(e)||!Number.isFinite(t))return NaN;if(!(Math.abs(e)<fv&&Math.abs(t)<fv))return e>0&&t>0?100*(pv(t)-pv(e))/r:NaN}function $L(e,t){let r=ar(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=[dv,-dv].map(l=>{let{inner:u,outer:m}=a(t("FL",l).deg-n,t("FR",l).deg-o);return hv(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:d,outer:p}=a(l.deg-n,u.deg-o),h=hv(d,p,r);return{steerL:l.deg,steerR:u.deg,inner:d,outer:p,toeDiff:d-p,ackermannPct:h??i(),inside:h===void 0?null:m?"left":"right",converged:l.ok&&u.ok}}}function Kf(e,t){let r=e.vehicle.config,n={FL:nt("FL",r),FR:nt("FR",r)},o=t.travel??0,a=$L(e,(i,c)=>{let l=Lt(we(e.ctx[i],o,n[i].sideSign*c));return{deg:l?BL(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 bv=35,gv=55,Bt=e=>e.rackTravel&&e.rackTravel>0?e.rackTravel:bv,Hf=e=>e.rackRatio&&e.rackRatio>0?e.rackRatio:gv;var zf=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 yv(e,t,r,n,o){let a=we(e,n,0,void 0,o),s=St(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 h=[l],f=zf(s);for(let b=1;b<=r;b++){let g=p*(t*b)/r,y=qe(e,s.beta,g,f,o),x=Lt(we(e,n,g,zf(y),o));if(!x||!y.converged){i++,h.push({...h[h.length-1]});continue}h.push({steer:x.metrics.toe,camber:x.metrics.camber,lift:-(y.points.contactPatch[2]-c),contactPatch:y.points.contactPatch,spinAxis:y.points.spinAxis,yaw:-y.metrics.toe*Math.PI/180}),f=zf(y)}return h},m=u(1),d=u(-1);return{travelMm:n,unsolved:i,centre:l,positive:m,negative:d}}function GL(e,t){return e.map((r,n)=>{let o=n===0?0:n-1,a=n===e.length-1?e.length-1:n+1,s=t[a]-t[o];if(!(s>0))return{longitudinal:0,lateral:0,vertical:0,yaw:0};let i=Q(G(e[a].contactPatch,e[o].contactPatch),1/s),c=te(le(r.spinAxis,[0,0,1])),l=le([0,0,1],c);return{longitudinal:J(i,c),lateral:J(i,l),vertical:i[2],yaw:(e[a].yaw-e[o].yaw)/s}})}function xv(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:GL(o,t)});return{travelMm:e.travelMm,inner:n(r?e.positive:e.negative),outer:n(r?e.negative:e.positive)}}function KL(e){return e.positive[1].steer-e.centre.steer<0}function HL(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:Hf(e.config),innerJacobian:r.inner.jacobian,outerJacobian:r.outer.jacobian}}function Yf(e,t,r=13,n=-40,o=40,a=5,s){let i=gt(e),c=Array.from({length:r+1},(b,g)=>t*g/r),l=yv(i,t,r,0,s),u=KL(l),m=xv(l,c,u),d=Math.max(2,Math.floor(a)),p=Array.from({length:d},(b,g)=>n+(o-n)*g/(d-1));p.some(b=>Math.abs(b)<1e-9)||p.push(0),p.sort((b,g)=>b-g);let h=l.unsolved,f=p.map(b=>{if(Math.abs(b)<1e-9)return m;let g=yv(i,t,r,b,s);return h+=g.unsolved,xv(g,c,u)});return{...HL(e,c,m),...Rv(l.unsolved),travelSurface:{rackMm:c,rows:f,...Rv(h)}}}var Rv=e=>e>0?{unsolved:e}:{};function Cr(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 Ul(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 vv(e,t){let r=e.rows;if(r.length<=1||t<=r[0].travelMm)return{lo:0,hi:0,t:0};let n=r.length-1;if(t>=r[n].travelMm)return{lo:n,hi:n,t:0};let o=0,a=n;for(;a-o>1;){let s=o+a>>1;r[s].travelMm<=t?o=s:a=s}return{lo:o,hi:a,t:(t-r[o].travelMm)/(r[a].travelMm-r[o].travelMm)}}var uo=(e,t,r)=>e+r*(t-e);function Fa(e,t,r,n,o){let a=Cr(e.rackMm,e.rows[n.lo][t][r],o);if(n.lo===n.hi)return a;let s=Cr(e.rackMm,e.rows[n.hi][t][r],o);return uo(a,s,n.t)}function kv(e,t,r,n){let o=Ul(e.rackMm,e.rows[r.lo][t].jacobian,n);if(r.lo===r.hi)return o;let a=Ul(e.rackMm,e.rows[r.hi][t].jacobian,n);return{longitudinal:uo(o.longitudinal,a.longitudinal,r.t),lateral:uo(o.lateral,a.lateral,r.t),vertical:uo(o.vertical,a.vertical,r.t),yaw:uo(o.yaw,a.yaw,r.t)}}function Ca(e,t,r,n){let o=e.travelSurface;if(!o||o.rackMm.length<2||o.rows.length===0)return Ta(e,t);let a=vv(o,r),s=vv(o,n),i=(p,h,f)=>{let b=o.rows[h.lo][p].steerDeg[f];return h.lo===h.hi?b:uo(b,o.rows[h.hi][p].steerDeg[f],h.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],d=l>c[u];if(l<=c[0])m=o.rackMm[0],d=!1;else if(!d){let p=1;for(;p<c.length-1&&c[p]<l;)p++;let h=p-1,f=c[p]-c[h],b=Math.abs(f)>1e-12?(l-c[h])/f:0;m=uo(o.rackMm[h],o.rackMm[p],b)}return{innerDeg:Fa(o,"inner","steerDeg",a,m),outerDeg:Fa(o,"outer","steerDeg",s,m),innerCamber:Fa(o,"inner","camberDeg",a,m),outerCamber:Fa(o,"outer","camberDeg",s,m),innerLift:Fa(o,"inner","liftMm",a,m),outerLift:Fa(o,"outer","liftMm",s,m),innerJacobian:kv(o,"inner",a,m),outerJacobian:kv(o,"outer",s,m),atLock:d}}function Ta(e,t){let r=e.meanDeg.length-1;return{innerDeg:Cr(e.meanDeg,e.innerDeg,t),outerDeg:Cr(e.meanDeg,e.outerDeg,t),innerCamber:Cr(e.meanDeg,e.innerCamber,t),outerCamber:Cr(e.meanDeg,e.outerCamber,t),innerLift:e.innerLift?Cr(e.meanDeg,e.innerLift,t):0,outerLift:e.outerLift?Cr(e.meanDeg,e.outerLift,t):0,...e.innerJacobian&&e.outerJacobian?{innerJacobian:Ul(e.meanDeg,e.innerJacobian,t),outerJacobian:Ul(e.meanDeg,e.outerJacobian,t)}:{},atLock:r>=0&&t>e.meanDeg[r]}}var zL=()=>({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 Pa(e,t,r=Be(e),n){let o=e.steerFront;if(!o?.innerLift||!o.outerLift||o.meanDeg.length<2||Math.abs(t)<1e-12)return zL();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??Cr(o.meanDeg,o.innerLift,a),l=i?.outerLift??Cr(o.meanDeg,o.outerLift,a),u=s?c:l,m=s?l:c,d=.5*(u+m),p=r.rollWheelRateFront,h=r.rollWheelRateRear,f=e.trackFront,b=e.trackRear,g=p*f*f+h*b*b,y=g>0?p*f*(m-u)/g:0,x={FL:u-d+.5*f*y,FR:m-d-.5*f*y,RL:.5*b*y,RR:-.5*b*y};return{lift:{FL:u,FR:m,RL:0,RR:0},travel:x,load:{FL:p*x.FL,FR:p*x.FR,RL:h*x.RL,RR:h*x.RR},rollDeg:y===0?0:-Math.atan(y)*180/Math.PI}}function Wf(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 ti=9.81;function La(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?Xr(e,t,r,Pn(e,n,o)):so(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 jf(e,t,r=0,n=0,o=0){if(!e.aero?.model||t<=0)return!1;let a=Xr(e,t,r,Pn(e,n,o));return a!=null&&(a.clampedRide||a.clampedAttitude)}function mo(e){let t=e.loadFactor===void 0?e.massTotal*ti:e.massTotal*ti*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 Mv(e,t=Be(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*wl(t.sprungMass,c,t.rollRateTotal),d=(m*t.frontRollStiffFrac+t.sprungFront*a+l*u)/n,p=(m*(1-t.frontRollStiffFrac)+t.sprungRear*s+l*u)/o;return{cf:d,cr:p}}function Uf(e){let{cf:t,cr:r}=Mv(e);return t+r>0?t/(t+r):.5}function Sv(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 d=u>0?1:-1,p=(d*a-c)*t;d*u>=d*p?(c=d*a,u-=p):(c+=u/t,u=0);let h=(d*s-l)*r;u!==0&&(d*u>=d*h?(l=d*s,u-=h):(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 $e(e,t,r,n=0,o=0,a=0,s,i){return Xl(e,t,r,n,o,a,s,i).loads}function Xl(e,t,r,n=0,o=0,a=0,s,i){let c=mo(e),l=Be(e),u=Il(e,n,r,Pn(e,t,o),l),{cf:m,cr:d}=Mv(e,l,u.height),p=m*t*ti,h=d*t*ti,f=e.massTotal*(r*ti)*u.height/e.wheelbase-u.noseLoad,b=La(e,n,r,t,o),g=(i??Pa(e,a,l,s)).load,y={FL:c.FL-p-f/2+b.FL+g.FL,FR:c.FR+p-f/2+b.FR+g.FR,RL:c.RL-h+f/2+b.RL+g.RL,RR:c.RR+h+f/2+b.RR+g.RR};return Sv(y,e.trackFront,e.trackRear)}var Xf=Math.PI/180;function Ql(e,t){let r=8*Xf,n=0,o=0;for(let a=1;a<=90;a++){let s=a*.5,i=Math.abs(e.Fy(s*Xf,t,0));if(i>n&&(n=i,r=s*Xf,o=a),a>o+12&&i<.995*n)break}return{aPeak:r,fyPeak:n}}function Av(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 ni=.999;function jt(e,t,r,n,o){if(t<=0)return 0;let{aPeak:a,fyPeak:s}=o??Ql(e,t),i=Math.min(Math.abs(r),ni*s),c=n?-1:1,l=(v,R)=>Math.abs(e.forces({Fz:t,kappa:c*v,alpha:R}).Fy),u=.3,m=u,d=l(u,a);if(d<i){let v=0,R=u,M=NaN,A=d;for(let F=0;F<9;F++){let T=.5*(v+R),P=l(T,a);P>=i?(v=T,M=P):(R=T,A=P)}Number.isNaN(M)&&(M=l(0,a)),m=M<i?0:Av(v,M,R,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 R=0,M=a,A=NaN,F=NaN;for(let T=0;T<5;T++){let P=.5*(R+M),S=l(v,P);S<i?(R=P,A=S):(M=P,F=S)}return Number.isNaN(A)&&(A=l(v,0)),Number.isNaN(F)&&(F=l(v,a)),c*e.forces({Fz:t,kappa:c*v,alpha:Av(R,A,M,F,i)}).Fx},h=4,f=v=>m*v/h,b=[0],g=1;for(let v=1;v<=h;v++)b.push(p(f(v))),b[v]>b[g]&&(g=v);let[y,x]=g===h?[h-1,h-2]:b[g-1]>=b[g+1]?[g-1,g+1]:[g+1,g-1],k=UL(p,f(g-1),f(Math.min(h,g+1)),f(g),b[g],f(y),b[y],f(x),b[x],YL);return c*Math.max(0,k)}var YL=.01,WL=20,jL=(3-Math.sqrt(5))/2;function UL(e,t,r,n,o,a,s,i,c,l){o=-o,s=-s,c=-c;let u=r-t,m=0;for(let d=0;d<WL;d++){let p=l*Math.abs(n)+1e-10,h=.5*(t+r);if(Math.abs(n-h)<=2*p-.5*(r-t))break;let f=!0;if(Math.abs(u)>p){let y=(n-a)*(o-c),x=(n-i)*(o-s),k=(n-i)*x-(n-a)*y;x=2*(x-y),x>0&&(k=-k),x=Math.abs(x);let v=u;if(u=m,Math.abs(k)<Math.abs(.5*x*v)&&k>x*(t-n)&&k<x*(r-n)){m=k/x;let R=n+m;(R-t<2*p||r-R<2*p)&&(m=h>=n?p:-p),f=!1}}f&&(u=n>=h?t-n:r-n,m=jL*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 Zf(e,t,r){if(!(r<1))return 0;let n=Math.max(0,r);return Tv(o=>Math.hypot(o,n)/e.reach(t,o,n)-1)}function Cv(e,t,r){let n=Math.max(0,r);return Tv(o=>Math.hypot(n,o)/e.reach(t,n,o)-1)}function Tv(e){let t=0,r=1,n=e(t),o=e(r);if(!(n<0))return 0;if(!(o>0))return 1;let a=0;for(let s=0;s<60;s++){let i=(t*o-r*n)/(o-n),c=e(i);if(Math.abs(c)<1e-12||r-t<1e-12)return i;c>0?(r=i,o=c,a===-1&&(n/=2),a=-1):(t=i,n=c,a===1&&(o/=2),a=1)}return t-n*(r-t)/(o-n)}function Jf(e,t){return e.model?.kind==="simple"?null:Pv(e,t)}var wv=new WeakMap,qf=100,Fv=1.35,Qf=18,Tr=41,ql=41,ri=65;function Pv(e,t){let r=wv.get(e);if(r)return r;let n=Math.log(Fv),o=(p,h)=>{let f=M=>Math.abs(jt(e,p,M,h)),b=f(0),g=t.muY(p)*p,y=new Float64Array(Tr),x=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<ql;T++){let P=Math.sin(.5*Math.PI*T/(ql-1));M.push(P),A.push(T===0?1:T===ql-1?0:Math.min(A[T-1],f(P*g)/b))}let F=ql-1;for(let T=0;T<Tr;T++){let P=T/(Tr-1);for(;F>0&&A[F-1]<P;)F--;let S=F>0?A[F-1]-A[F]:0;y[T]=F===0?M[0]:M[F]+(S>0?(P-A[F])/S:0)*(M[F-1]-M[F])}y[0]=1,y[Tr-1]=0}let k=new Float64Array(ri),v=M=>Math.atan2(y[M],M/(Tr-1)/x),R=Tr-2;for(let M=0;M<ri;M++){let A=.5*Math.PI*M/(ri-1),F=Math.cos(A),T=Math.sin(A);for(;R>0&&v(R)<A;)R--;let P=R/(Tr-1)/x,S=y[R],w=(R+1)/(Tr-1)/x,C=y[R+1],L=F*(C-S)-T*(w-P),E=Math.abs(L)>1e-12?(P*(C-S)-S*(w-P))/L:Math.hypot(P,S);k[M]=E>0?E:Math.hypot(P,S)}return{room:y,scale:x,edge:k}},a=Array.from({length:Qf},(p,h)=>qf*Fv**h),s=a.map(p=>o(p,!1)),i=a.map(p=>o(p,!0)),c=(p,h)=>{let f=Math.min(1,Math.abs(h)*p.scale)*(Tr-1),b=Math.min(Tr-2,Math.floor(f));return p.room[b]+(f-b)*(p.room[b+1]-p.room[b])},l=p=>{let h=p>qf?Math.log(p/qf)/n:0;if(h>=Qf-1)return[Qf-2,1];let f=Math.floor(h);return[f,h-f]},u=(p,h,f)=>{if(f===0)return 1;let b=f<0?i:s,g=c(b[p],f);return h>0?g+h*(c(b[p+1],f)-g):g},m=(p,h,f)=>{let b=h<0?i:s,[g,y]=l(p),x=Math.atan2(Math.abs(f),Math.abs(h))/(.5*Math.PI)*(ri-1),k=Math.min(ri-2,Math.floor(x)),v=M=>M.edge[k]+(x-k)*(M.edge[k+1]-M.edge[k]),R=v(b[g]);return y>0?R+y*(v(b[g+1])-R):R},d={keeps(p,h){if(h===0)return 1;let[f,b]=l(p);return u(f,b,h)},atLoad(p){let[h,f]=l(p);return b=>u(h,f,b)},use(p,h,f){let b=Math.hypot(h,f);return b>0?Math.min(1,b/m(p,h,f)):0},reach:m};return wv.set(e,d),d}var XL=[["front","FL","FR"],["rear","RL","RR"]];function Da(e,t,r,n){let o={...e},a=0,s=ni;for(let[i,c,l]of XL){let u=(k,v)=>n(i,Math.max(0,v[k])).fyPeak,m=Math.min(s,e[c]),d=Math.min(s,e[l]),p=m*u(c,r)+d*u(l,r);if(!(p>0))continue;let h=u(c,t),f=u(l,t),b=m*h+d*f,g=b>0?p/b:1/0,y=m*g,x=d*g;y<=s?x<=s||(x=s,y=h>0?(p-s*f)/h:1/0):(y=s,x=f>0?(p-s*h)/f:1/0),(!(y<=s)||!(x<=s))&&(a+=Math.max(0,p-s*(h+f)),y=Math.min(s,y),x=Math.min(s,x)),o[c]=y,o[l]=x}return{util:o,short:a}}var Lv=.001,qL=1e-5,Dv=100;function QL(e,t,r,n){if(!(n>Lv))return r;let o=t,a=Math.abs(r-t)<Dv?t+Math.sign(r-t)*Dv:r;for(let s=0;s<60&&Math.abs(a-o)>qL;s++){let i=.5*(o+a);e(i)>Lv?a=i:o=i}return o}function Zl(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=QL(e,t,o,e(o));return a!==o&&(n=a),a},edge:()=>n}}function Jl(e,t){let r=n=>{try{return we(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 eh=40;function eu(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 Ev=[0,0,0];function ZL(e,t){let r=te(G(e.rockerPivotB,e.rockerPivotA)),n=te(G(e.rockerToPushrod,e.pushrodOuter)),o=te(G(e.damperChassis,e.rockerToDamper)),a=Math.abs(J(r,le(G(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(J(r,le(G(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}function tu(e,t,r){if(e.mcpherson)return JL(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 d=te(G(n[m].c,n[m].r)),p=le(G(n[m].r,o),d);a[0][m]=d[0],a[1][m]=d[1],a[2][m]=d[2],a[3][m]=p[0],a[4][m]=p[1],a[5][m]=p[2]}let s=le(G(e.contactPatch,o),t),i=r??Ev,c=[-t[0],-t[1],-t[2],-(s[0]+i[0]),-(s[1]+i[1]),-(s[2]+i[2])],l=Ar(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]:ZL(e,u[5]),condProxy:l.condProxy,singular:l.singular}}function JL(e,t,r){let n=e.wheelCenter,o=e.damperChassis,a=[{at:e.uprightLower,dir:te(G(e.lcaFront,e.uprightLower))},{at:e.uprightLower,dir:te(G(e.lcaRear,e.uprightLower))},{at:e.tieOuter,dir:te(G(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=le(G(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=le(G(e.contactPatch,n),t),c=r??Ev,l=[-t[0],-t[1],-t[2],-(i[0]+c[0]),-(i[1]+c[1]),-(i[2]+c[2])],u=Ar(s,l),m=u.x,d=[m[3],m[4],m[5]],p=te(G(o,e.pushrodOuter)),h=J(d,p),f=Math.hypot(d[0]-h*p[0],d[1]-h*p[1],d[2]-h*p[2]);return{ucaFront:NaN,ucaRear:NaN,lcaFront:m[0],lcaRear:m[1],tieRod:m[2],pushRod:u.singular?NaN:h,damper:u.singular?NaN:h,condProxy:u.condProxy,singular:u.singular,strutSide:u.singular?NaN:f,topMount:d}}function th(e,t){let r=te(e.spinAxis),n=le(G(e.contactPatch,e.wheelCenter),t),o=J(n,r);return[-o*r[0],-o*r[1],-o*r[2]]}var eD=[0,0,0];function oi(e,t,r,n){let o=e.direct?e.damperChassis:e.rockerToPushrod;if(e.mcpherson)return{...tu(e,r,n),armResidual:0};if(t==="upright")return{...tu(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=te(G(s.front,s.bj)),u=te(G(s.rear,s.bj)),m=te(G(e.tieInner,e.tieOuter)),d=[{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 H=0;H<6;H++){let W=d[H].dir,X=le(G(d[H].at,c),W);p[0][H]=W[0],p[1][H]=W[1],p[2][H]=W[2],p[3][H]=X[0],p[4][H]=X[1],p[5][H]=X[2]}let h=le(G(e.contactPatch,c),r),f=n??eD,b=[-r[0],-r[1],-r[2],-(h[0]+f[0]),-(h[1]+f[1]),-(h[2]+f[2])],g=Ar(p,b),y=g.singular,x=g.x,k=x[0],v=x[1],R=x[2],M=[x[3],x[4],x[5]],A=te(G(i.rear,i.front)),F=te(G(o,e.pushrodOuter)),T=Q(M,-1),P=(H,W)=>J(A,le(G(H,i.front),W)),S=P(e.pushrodOuter,F),w=Math.abs(S)>1e-9?-P(i.bj,T)/S:NaN,C=oe(T,Q(F,w)),L=Q(C,-1),E=te(G(i.front,i.bj)),_=te(G(i.rear,i.bj)),O=J(E,E),I=J(E,_),z=J(_,_),B=J(E,L),V=J(_,L),j=O*z-I*I,q=NaN,K=NaN,D=NaN;if(Math.abs(j)>1e-12){q=(B*z-V*I)/j,K=(O*V-I*B)/j;let H=oe(Q(E,q),Q(_,K)),W=G(L,H);D=Math.hypot(W[0],W[1],W[2])}let N=a?{f:k,r:v}:{f:q,r:K},Y=a?{f:q,r:K}:{f:k,r:v};return{ucaFront:N.f,ucaRear:N.r,lcaFront:Y.f,lcaRear:Y.r,tieRod:R,pushRod:w,damper:y||!Number.isFinite(w)||e.decoupled?NaN:e.direct?w:tD(e,w),condProxy:g.condProxy,singular:y,armResidual:D}}function tD(e,t){let r=te(G(e.rockerPivotB,e.rockerPivotA)),n=te(G(e.rockerToPushrod,e.pushrodOuter)),o=te(G(e.damperChassis,e.rockerToDamper)),a=Math.abs(J(r,le(G(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(J(r,le(G(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}var lz=Math.PI/180;function ai(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 _v=["QSX3","QSX8","QSX13","QSX14"],rD=["QSX1"],ru=["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",..._v];function nD(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 oD(e){let t=new Set(nD(e)),r=ru.filter(n=>!_v.includes(n));return[...r.filter(n=>!t.has(n)),...[...t].filter(n=>!r.includes(n)),...rD]}function aD(e,t){let r={...e};for(let n of t)r[n]!==void 0&&r[n]!==0&&(r[n]=-r[n]);return r}var Zr=(e,t,r)=>Number.isFinite(e[t])?e[t]:r;function Nv(e,t){return t!=="5.2"?Zr(e,"PKY6",0)*Zr(e,"LKYC",1):Zr(e,"PKY1",-15)*Math.sin(Zr(e,"PKY4",2)*Math.atan(1/Zr(e,"PKY2",2)))*Zr(e,"LKY",1)*Zr(e,"PHY3",0)+Zr(e,"PVY3",0)*Zr(e,"LMUY",1)}var Iv=.1;function Ov(e){if(e.fitData)return"sae";let t=Nv(e.coeffs,e.version);return t>Iv?"sae":t<-Iv?"iso":null}function si(e){return e.axisSystem??Ov(e)??"sae"}function nu(e){let t=new Set,r=n=>{for(let o of n)t.has(o)?t.delete(o):t.add(o)};return si(e)==="iso"&&r(ru),e.axisSystem&&e.side==="left"&&r(oD(e.version)),t.size?aD(e.coeffs,t):e.coeffs}var mz=Math.PI/180;var $=(e,t)=>Number.isFinite(e)?e:t;function Bv(e){let t=nu(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 Vv=new WeakMap;function ii(e){let t=Vv.get(e);return t===void 0&&(t=Bv(e),Vv.set(e,t)),t}var $v=e=>e>=0?1:-1;function ou(e,t,r=0,n){let o=ii(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,d=o.PCY1*o.LCY,p=m*a,h=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,f=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(h)>1e-6?h:1e-6*(h<0?-1:1),x=f?(o.PHY1+o.PHY2*c)*o.LHY+(b*s-g)/y:(o.PHY1+o.PHY2*c)*o.LHY+o.PHY3*s,k=f?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=d*p!==0?h/(d*p):0;return{Fz:a,g:s,dfz:c,dpi:l,Fz0p:i,R0:u,Cy:d,Dy:p,By:v,SHy:x,SVy:k,Kya:h,muy:m,EyA:o.PEY1+o.PEY2*c,EyG:1+o.PEY5*s*s,EyS:o.PEY3+o.PEY4*s,LEY:o.LEY}}function au(e,t,r=0,n){let o=ou(e,t,r,n),a=ii(e),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:m,muy:d,Kya:p,SVy:h,By:f,Cy:b,Dy:g,SHy:y}=o,x=(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,R=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*R!==0?M/(v*R):0,F=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 w=a.REY1+a.REY2*c;return w>1&&(w=1),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:m,Cy:b,Dy:g,By:f,SHy:y,SVy:h,Kya:p,muy:d,EyA:o.EyA,EyG:o.EyG,EyS:o.EyS,LEY:o.LEY,SHx:x,Cx:v,Dx:R,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:w,DVykA:d*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*f*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?h/p:0,sixOne:T,kk:M/F*(M/F),sS0:m*(a.SSZ1+(a.SSZ3+a.SSZ4*c)*i)*a.LS,sS2:m*a.SSZ2*a.LS/u}}function ci(e,t){let r=t+e.SHy,n=e.EyA*(e.EyG-e.EyS*$v(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 su(e,t){let r=t+e.SHx,n=e.ExA*(1-e.PEX4*$v(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 Gv(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 sD(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=Gv(e,o,r),i=e.Bt*s;return e.Dt*Math.cos(e.Ct*Math.atan(i-a*(i-Math.atan(i))))*n}function iD(e,t,r,n){return e.Dr*Math.cos(Math.atan(e.Br*Gv(e,t+e.SHy+e.arOff,r)))*n}function Kv(e,t,r,n,o,a){let s=Math.cos(t),i=sD(e,t,r,s),c=iD(e,t,r,s);return-i*(o-a)+c+(e.sS0+e.sS2*o)*n}function Hv(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*su(e,t)}function rh(e,t){let r=e.sS0===0&&e.sS2===0?0:Hv(e,0,t);return Kv(e,t,0,r,ci(e,t),0)}function iu(e,t,r){let n=ci(e,r),o=Hv(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:Kv(e,r,t,o,m,u)}}var li=(e,t)=>Math.max(.1,e.muY0+e.loadSensY*(t-e.nominalLoad)),ui=(e,t)=>Math.max(.1,e.muX0+e.loadSensX*(t-e.nominalLoad)),zv=(e,t,r)=>li(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cy*Math.atan(e.By*r)),Yv=(e,t,r)=>ui(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cx*Math.atan(e.Bx*r));function nh(e,t){let r=Math.max(1,t.Fz),n=li(e,r)*r,o=ui(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 Ea=Math.PI/180;function Nn(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 Wv(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?ai(r,t):1,s=n?ai(n,t):1,i=o?ai(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 Ia(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 _e(e){let t=Wv(e),r=t,n=t,o=null,a=NaN,s=NaN,i=NaN,c=(v,R,M)=>(o!==null&&v===a&&R===s&&M===i||(o=au(r,v,R,M),a=v,s=R,i=M),o),l=null,u=NaN,m=NaN,d=NaN,p=(v,R,M)=>(l!==null&&v===u&&R===m&&M===d||(l=ou(r,v,R,M),u=v,m=R,d=M),l),h=v=>e.kind==="magic"?iu(c(v.Fz,v.gamma??0,v.p),v.kappa,v.alpha):nh(n,v),f=(v,R,M=0,A)=>e.kind==="magic"?ci(p(R,M,A),v):zv(n,R,v),b=(v,R,M=0,A)=>e.kind==="magic"?su(c(R,M,A),v):Yv(n,R,v),g=(v,R,M=0,A)=>e.kind==="magic"?rh(c(R,M,A),v):h({Fz:R,kappa:0,alpha:v,gamma:M,p:A}).Mz,y=v=>e.kind==="simple"?li(n,v):Ia(R=>f(R*Ea,v),45,1)/Math.max(1,v),x=v=>e.kind==="simple"?ui(n,v):Ia(R=>b(R,v),.6,.02)/Math.max(1,v),k=v=>{let R=.1*Ea;return Math.abs((f(R,v)-f(-R,v))/(2*R))};return{model:e,forces:h,Fx:b,Fy:f,Mz:g,muX:x,muY:y,corneringStiffness:k,verticalStiffness:()=>e.verticalStiffness,rollingRadius:v=>{if(e.kind==="magic"&&e.missing?.includes("UNLOADED_RADIUS"))return 0;let R=e.unloadedR0??0;if(!(R>0))return 0;let M=e.verticalStiffness*1e3;if(!(M>0))return R;let A=e.rollingFraction??.306;return R-A*Math.max(0,v)/M},relaxationLength:v=>{let R=e.relaxation;if(!R)return 0;let M=R.carcassStiffness??0;if(!(M>0))return R.sigma;let A=k(Math.max(0,v));return A>0?A/(M*1e3):R.sigma}}}function _a(e){let t=Math.max(1,e.model.kind==="magic"?e.model.fnomin:e.model.nominalLoad);return e.Fy(2*Ea,t,0)-e.Fy(-2*Ea,t,0)>=0?1:-1}function mi(e,t=e.kind==="magic"?e.fnomin:e.nominalLoad){let r=_e(e),n=2*Ea,o=3*Ea,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 cD=Math.PI/180;function Fe(e,t){return e.axle?e.axle(t):e}function lu(e,t){if(e===t)return e;let r=_a(e)*_a(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,d)=>n(e.Fx(l,u,m,d),t.Fx(l,u,m,d)),i=(l,u,m=0,d)=>n(e.Fy(l,u,m,d),r*t.Fy(l,u,m,d)),c=(l,u,m=0,d)=>n(e.Mz(l,u,m,d),r*t.Mz(l,u,m,d));return{model:e.model,forces:a,Fx:s,Fy:i,Mz:c,muX:l=>Ia(u=>s(u,l),.6,.02)/Math.max(1,l),muY:l=>Ia(u=>i(u*cD,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 Dt(e){if(jv.has(e))return e;let t=Uv.get(e);if(t)return t;let r;if(e.axle){let n=e.axle("front"),o=e.axle("rear"),a=Dt(n),s=Dt(o);r=a===n&&s===o?e:lu(a,s)}else _a(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 jv.add(r),r!==e&&Uv.set(e,r),r}var jv=new WeakSet,Uv=new WeakMap;var uu=25*(Math.PI/180);function lD(e){let t=.6180339887,r=0,n=uu,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 pi(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=uu;if(s(uu)<=a){let u=lD(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(uu,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),d=s(m)-a;if(d<0?i=m:c=m,Math.abs(d)<=l)return m}return c}var oh={shaft:!1,trail:0,hub:[0,0,0]};function qv(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 ah(e,t,r){let n=r.shaft?th(e,t):[0,0,0];if(r.trail!==0){let a=qv(e),s=[t[0],t[1],0],i=G(s,Q(a,J(s,a)));n=oe(n,le(Q(a,-r.trail),i))}let o=r.hub;return(o[0]!==0||o[1]!==0||o[2]!==0)&&(n=G(n,le(G(e.contactPatch,e.wheelCenter),o))),{force:oe(t,o),moment:n}}var uD=(e,t)=>{let r=e!==void 0&&e>0?1/e:0,n=t!==void 0&&t>0?1/t:0;return r+n},mu={ucaFront:0,ucaRear:0,lcaFront:0,lcaRear:0,tieRod:0,pushRod:0,rack:0};function po(e){return!e.measured}function fo(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 di(e,t){let r=e.corner.hardpoints,n=xa(e.rocker,t.points.rockerAngle);return{ucaFront:r.ucaFront,ucaRear:r.ucaRear,lcaFront:r.lcaFront,lcaRear:r.lcaRear,tieInner:io(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 sh(e,t,r=0){let n=t.links??{},o=t.bushings??{},a=(l,u,m)=>{let d=uD(u,m);return d>0&&Number.isFinite(l)?l*d: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 Qv(e,t,r,n){let o=Ee(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 fi(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:oe(n.strut.top,t.topMount)}),t.ucaFront!==0||t.ucaRear!==0){let i=Qv(r.ucaFront,r.ucaRear,Ee(r.uprightUpper,r.ucaFront)+t.ucaFront,Ee(r.uprightUpper,r.ucaRear)+t.ucaRear);o.ubjAxial0=i.axial,o.ubjRadius2=i.radius2}if(t.lcaFront!==0||t.lcaRear!==0){let i=Qv(r.lcaFront,r.lcaRear,Ee(r.uprightLower,r.lcaFront)+t.lcaFront,Ee(r.uprightLower,r.lcaRear)+t.lcaRear),c=J(n.lbjRel0,n.lcaDir),l=G(n.lbjRel0,Q(n.lcaDir,c)),u=Math.hypot(l[0],l[1],l[2]);o.lbjRel0=u>1e-9?oe(Q(n.lcaDir,i.axial),Q(l,Math.sqrt(i.radius2)/u)):oe(Q(n.lcaDir,i.axial),l)}if(t.tieRod!==0){let i=Math.sqrt(n.tieLen2)+t.tieRod;o.tieLen2=i*i}if(t.rack!==0&&(o.tieInner0=oe(n.tieInner0,Q(n.rackAxis,t.rack))),t.pushRod===0)return{corner:e.corner,inv:o,rocker:e.rocker};let a=Math.sqrt(e.rocker.rodLen2)+t.pushRod,s={...e.rocker,rodLen2:a*a};return{corner:e.corner,inv:o,rocker:s}}var mD=8,pD=1e-5,dD=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 ih(e,t,r){let n=ah(e,r.force,r.extras??oh),o=r.alignMoment?oe(n.moment,[0,0,r.alignMoment]):n.moment;return oi(e,t,n.force,o)}function du(e,t,r,n,o,a,s=0){let i=qe(e,t,r,o,a),c=e.corner.compliance;if(!(fo(c)&&po(e.corner)))return{state:i,forces:ih(di(e,i),e.corner.config.pushrodAttach,n),deflection:mu,rigid:i,iterations:0,converged:!0,bypassed:!0};let u=i,m=e,d=e.corner.config.pushrodAttach,p=ih(di(e,i),d,n),h=mu,f=!1,b=0;for(;b<mD;b++){let g=di(m,u);if(p=ih(g,d,n),p.singular)break;h=sh(p,c,s),m=fi(e,h);let y=qe(m,t,r,dD(u),a),x=Ee(y.points.wheelCenter,u.points.wheelCenter);if(u=y,x<pD){f=!0;break}}return{state:u,forces:p,deflection:h,rigid:i,iterations:b+1,converged:f&&u.converged,bypassed:!1}}var pu=1e3,Zv=1e5;function Jv(e,t,r,n,o){let a=du(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 fu(e,t,r,n,o){let a={force:[0,0,n]},s=(b,g=0)=>Jv(e,t,r,{force:b,alignMoment:g},o),i=Jv(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,pu,n]),l=s([0,-pu,n]),u=s([pu,0,n]),m=s([-pu,0,n]),d=s([0,0,n],Zv),p=s([0,0,n],-Zv),h=(b,g)=>(b-g)/2,f=[i,c,l,u,m,d,p].every(b=>b.converged);return{toePerLateral:h(c.toe,l.toe),camberPerLateral:h(c.camber,l.camber),toePerLongitudinal:h(u.toe,m.toe),camberPerLongitudinal:h(u.camber,m.camber),toePerAligning:h(d.toe,p.toe),lateralPatch:h(c.patch[1],l.patch[1]),longitudinalPatch:h(u.patch[0],m.patch[0]),bypassed:!1,converged:f}}var fD=1e3;function ch(e,t=fD){if(!fo(e.compliance)||!po(e))return;let r=gt(e),n=qe(r,0,0),o=fu(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 Na(e,t=-eh,r=eh,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=ot(e,{travelMin:t,travelMax:r,steps:n}),s=ch(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 hu(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 On(e,t){return{motionRatio:hu(e.travel,e.motionRatio,t),camber:hu(e.travel,e.camber,t),toe:hu(e.travel,e.toe,t),damperLen:hu(e.travel,e.damperLen,t)}}var e1=Math.PI/180,hD=9.81;function Vn(e,t,r,n=0){let o=Be(e),a=e.wheelbase*(1-e.frontMassFrac),s=e.wheelbase*e.frontMassFrac,i=La(e,n),c=e.aero?.model?(k,v,R)=>La(e,n,v,k,R):()=>i,l=On(t,0),u=On(r,0),m=e.loadFactor,d=m!==void 0&&m!==1?(m-1)*e.massTotal*hD:0,p=d*e.frontMassFrac/2,h=d*(1-e.frontMassFrac)/2,f=(k,v)=>v>0&&Number.isFinite(v)&&k+v>0?v/(k+v):1,b=lt(e,"front"),g=lt(e,"rear"),y={F:f(e.wheelRateFront+(e.heaveSpringFront??0),b),R:f(e.wheelRateRear+(e.heaveSpringRear??0),g)},x={F:f(e.wheelRateFront+e.arbFront,b),R:f(e.wheelRateRear+e.arbRear,g)};return(k,v,R=0,M=0)=>{let A=c(k,v,R),F=o.rollGradient*k,T=F*e1,P=o.pitchGradient*v*e1,S=(O,I)=>{let z=I==="F"?e.trackFront:e.trackRear,B=I==="F"?o.rideRateFront:o.rideRateRear,V=(O==="R"?1:-1)*(z/2)*Math.tan(T),j=(I==="R"?s:-a)*Math.tan(P),q=`${I}${O}`,K=d?A[q]+(I==="F"?p:h):A[q],D=B>0?K/B:0;return{anti:V,sym:j+D}},w={FL:S("L","F"),FR:S("R","F"),RL:S("L","R"),RR:S("R","R")},C=O=>{let I=O[0];return w[O].sym*y[I]+w[O].anti*x[I]},L=Pa(e,M,o,{FL:C("FL"),FR:C("FR")}),E=F+L.rollDeg,_=(O,I)=>{let z=I==="F"?t:r,B=I==="F"?l:u,V=`${I==="F"?"F":"R"}${O}`,j=w[V].sym+w[V].anti+L.travel[V],q=C(V)+L.travel[V]*x[I],K=j-q,D=On(z,q),N=(O==="R"?1:-1)*D.camber;return{travel:q,tyre:K,ground:j,camber:N,camberRoad:N+E,toe:D.toe,bumpToe:D.toe-B.toe,damperTravel:B.damperLen-D.damperLen}};return{FL:_("L","F"),FR:_("R","F"),RL:_("L","R"),RR:_("R","R"),steeringJacking:L}}}var lh=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function ho(e){return{enabled:e?.enabled===!0,roadFeedbackGain:Math.min(2,Math.max(0,lh(e?.roadFeedbackGain,1))),turnInFrictionNm:Math.max(0,lh(e?.turnInFrictionNm,0)),columnStiffnessNmPerRad:Math.max(0,lh(e?.columnStiffnessNmPerRad,0))}}function uh(e,t,r){let n=ho(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 t1=()=>({totalNm:0,aligningNm:0,lateralNm:0,longitudinalNm:0,jackingNm:0});function bo(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 hi(e,t,r,n="model",o){let a=e.steerFront;if(!bo(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):Ta(a,Math.abs(t));if(!u.innerJacobian||!u.outerJacobian)return null;let m=(b,g)=>{let y=r[b],x=b==="FL"?-1:1,k=-x*y.Fy,R={aligning:1e3*(-x*y.Mz)*g.yaw,lateral:k*g.lateral,longitudinal:y.Fx*g.longitudinal,jacking:y.Fz*g.vertical},M=t1();M.aligningNm=-s*R.aligning*c,M.lateralNm=-s*R.lateral*c,M.longitudinalNm=-s*R.longitudinal*c,M.jackingNm=-s*R.jacking*c,M.totalNm=M.aligningNm+M.lateralNm+M.longitudinalNm+M.jackingNm;let A=-s*(R.aligning+R.lateral+R.longitudinal+R.jacking);return{moment:M,rackN:A}},d=m("FL",l?u.innerJacobian:u.outerJacobian),p=m("FR",l?u.outerJacobian:u.innerJacobian),h=t1();for(let b of[d.moment,p.moment])h.aligningNm+=b.aligningNm,h.lateralNm+=b.lateralNm,h.longitudinalNm+=b.longitudinalNm,h.jackingNm+=b.jackingNm,h.totalNm+=b.totalNm;let f=uh(h.totalNm,t,e.steeringSystem);return h.totalNm=f.driverNm,{...h,roadNm:f.roadNm,assistanceNm:f.assistanceNm,frictionNm:f.frictionNm,columnTwistDeg:f.columnTwistDeg,rackForceN:d.rackN+p.rackN,aligningSource:n,perWheel:{FL:d.moment,FR:p.moment}}}var bD=e=>"front"in e&&"rear"in e;function Oa(e,t){return bD(e)?e[t]:e}function ph(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)),d=(u-a[m])/o;return l[m]+d*(l[m+1]-l[m])};return{muX:l=>c(s,l),muY:l=>c(i,l)}}function mh(e,t){let r=Math.max(0,t.Fz);return n1(e.muX(r)*r,e.muY(r)*r,t)}function n1(e,t,r){if(!(t>0))return{fyUsed:0,fyMax:0,fyRes:0};let n=e>0?Math.min(1,Math.abs(r.Fx)/e):0,o=t*Math.sqrt(Math.max(0,1-n*n)),a=Math.abs(r.Fy);return{fyUsed:a,fyMax:o,fyRes:Math.max(0,o-a)}}function r1(e,t,r){let n=mh(e,t),o=mh(e,r);return{left:n,right:o,fyRes:n.fyRes+o.fyRes}}function Jr(e,t,r){let n=r1(Oa(e,"front"),t.FL,t.FR),o=r1(Oa(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 bi=[{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"}],yD=bi.flatMap(e=>[e.min,e.max]);function xD(e){let t={};for(let r of bi){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 bu(e){if(e.kind==="magic")return e.range??xD(e.coeffs)}function dh(e){return Math.max(1,e.kind==="magic"?e.fnomin:e.nominalLoad)}function o1(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 fr(e){let t=a1.get(e);if(t!==void 0)return t;let r=10*dh(e.model),{turnover:n,collapse:o}=vD(e,r),a=n??o??r;return a1.set(e,a),a}var a1=new WeakMap;function vD(e,t){let r=dh(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 d=o(m*s);if(d<c){i=o1(o,(m-2)*s,m*s,20,(p,h)=>p>h);break}c=d}let l=null,u=n(s);for(let m=2;m<=a;m++){let d=n(m*s);if(d>u){let p=o1(n,(m-2)*s,m*s,40,(h,f)=>h<f);n(p)<.05*n(r)&&(l=p);break}u=d}return{turnover:i,collapse:l}}var s1=.1;function gu(e,t=dh(e)){let r=_e(e).muX(t);return{muX:r,none:Number.isFinite(r)&&r<s1}}var i1=["FL","FR","RL","RR"],kD=e=>e==="FL"||e==="RL",MD=e=>e==="FL"||e==="FR"?"front":"rear";function yu(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 i1)a[l]={...t[l]};let s=l=>{let u=0;for(let d of i1)MD(d)===e.axle&&(a[d].Fx=e.sense*(d===e.strong?l-e.open/2:e.open/2),u-=(kD(d)?o:-o)*a[d].Fx);let m=Jr(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 SD=[["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]],AD=[["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]],wD=[["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]],FD=[["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]],CD=[["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]],l1=[["lateral",SD],["longitudinal",AD],["aligning",wD],["combined",FD],["scaling",CD]].flatMap(([e,t])=>t.map(([r,n,o])=>({key:r,section:e,text:n,fallback:o}))),f6=new Map(l1.map(e=>[e.key,e]));var TD=/^\$\s*EDITED\s+([A-Z][A-Z0-9_]*)\s+was\s+(absent|[-+0-9.eE]+)\s*$/;function u1(e){let t={};for(let r of e.split(/\r?\n/)){let n=r.trim().match(TD);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 LD=/^\s*\$\s*UNLOADED_RADIUS_STAND_IN\s*=\s*([0-9.eE+-]+)/,DD=/^\$-+ written by (?:PaceDynamics|PaceLab)\b/m,ED=/^\$\s*AXIS_SYSTEM\s*=\s*(ISO-W|SAE)\b/m;function ID(e){let t=e.match(ED);return t?{axisSystem:t[1]==="SAE"?"sae":"iso",trustSide:!0}:DD.test(e)?{axisSystem:"sae",trustSide:!1}:{axisSystem:"iso",trustSide:!0}}function _D(e){return e>=62?"6.2":e>=61?"6.1":"5.2"}var m1=new Map([["pa",1],["pascal",1],["kpa",1e3],["kilopascal",1e3],["mpa",1e6],["megapascal",1e6],["bar",1e5],["psi",6894.757293168]]);function ND(e,t,r){let n=r.PRESSURE?.trim().toLowerCase(),o=n===void 0?1:m1.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 OD=new Map([["radians",1],["radian",1],["rad",1],["degrees",Math.PI/180],["degree",Math.PI/180],["deg",Math.PI/180]]);function VD(e,t){let r=(s,i)=>s===void 0?1:i.get(s.trim().toLowerCase()),n=r(t.ANGLE,OD),o={fz:1,kappa:1,alpha:n,gamma:n,p:r(t.PRESSURE,m1)},a={};for(let s of bi){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 gi(e,t="imported",r={}){let n=ID(e),o=r.axisSystem??n.axisSystem,a={},s={},i={},c="",l;for(let g of e.split(/\r?\n/)){let y=g.match(LD);y&&(l=parseFloat(y[1]));let x=g.replace(/[$!].*$/,"").trim();if(!x)continue;if(x.startsWith("[")){c=(x.match(/^\[([^\]]*)/)?.[1]??"").trim().toUpperCase();continue}let k=x.indexOf("=");if(k<0)continue;let v=x.slice(0,k).trim().toUpperCase(),R=x.slice(k+1).trim(),M=R.match(/^'([^']*)'|^"([^"]*)"/);if(M){s[v]=M[1]??M[2]??"",c==="UNITS"&&(i[v]=s[v]);continue}let A=parseFloat(R);Number.isFinite(A)&&(a[v]=A)}let u=_D(a.FITTYP??62),m=u1(e),d=m?Object.fromEntries(Object.entries(m).filter(([g])=>a[g]!==void 0)):void 0,p=a.VERTICAL_STIFFNESS??a.KZ??0,h=ND(a,s,i),f=VD(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"),h===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:h??0,missing:b,...d&&Object.keys(d).length?{edited:d}:{},...f?{range:f}:{}}}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 xu(e){if(!e)return null;let t=e.sectionWidth;return t!==void 0&&t>0?t:null}var k6=Math.PI/180;var F6=Math.PI/180,C6=180/Math.PI;function yi(){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 f1=`$ AXIS_SYSTEM = SAE (authored in the evaluation frame: y right)
|
|
2
|
+
import{parentPort as CP,workerData as qG}from"node:worker_threads";import{readFileSync as ix}from"node:fs";import{join as cx}from"node:path";var vl=e=>e.format!=="points"&&!e.field;var pt=e=>e?.kind==="ice";var Ox={packVoltageMax:600,segmentVoltageMax:120,powerLimitKw:80};var je=e=>typeof e=="number"&&Number.isFinite(e);function PP(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(je))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(je))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(je))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(je))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(je))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 LP(e){return!e||typeof e!="object"?"The cell has no curve.":e.kind==="table"?PP(e):e.kind==="analytic"?!je(e.vCut)||!je(e.vNom)||!je(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?!je(e.r0)||e.r0<0?"The cell resistance must be a number and cannot be negative.":e.socAtNom!==void 0&&(!je(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 kl(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(!je(t.capacityAh)||t.capacityAh<=0)return"The cell capacity must be a positive number of amp-hours.";if(!je(t.vMin)||t.vMin<0)return"The cut-off voltage must be a number and cannot be negative.";if(!je(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(!je(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&&(!je(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&&(!je(t.massKg)||t.massKg<0))return"The cell mass must be a number and cannot be negative.";let r=LP(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(!je(o.heatCapacityJPerK)||o.heatCapacityJPerK<=0)return"The cell heat capacity must be a positive number of joules per kelvin.";if(!je(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&&!je(o.startC))return"The starting temperature must be a number.";if(o.entropicVPerK!==void 0&&!je(o.entropicVPerK))return"The entropic coefficient must be a number.";if(o.derateFromC!==void 0){if(!je(o.derateFromC))return"The temperature the derate starts at must be a number.";if(o.derateToC!==void 0){if(!je(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(!je(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 ao(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 Ue(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 Ml(e,t,r,n,o){let a=e.length,s=t.length;if(a===0||s===0)return 0;let i=ao(e,n),c=ao(t,o),l=Math.min(i.i+1,a-1),u=Math.min(c.i+1,s-1),m=r[c.i][i.i],d=r[c.i][l],p=r[u][i.i],h=r[u][l],f=m+i.t*(d-m),b=p+i.t*(h-p);return f+c.t*(b-f)}var fa=[0,.05,.1,.2,.3,.4,.5,.6,.7,.8,.9,1],Td={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]},Vx=[0,.05,.1,.2,.5,.8,1],Bx=[2.2,1.55,1.3,1.12,1,.97,.98];function $x(e){return Ue(Vx,Bx,e)}var Gx=[-20,-10,0,10,25,40,60],Kx=[4,2.8,2,1.4,1,.82,.75];function Pd(e){return Ue(Gx,Kx,e)}var Hx=.5;function Ld(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=Td[t]??Td.other,l=e.socAtNom??Hx,u=fa.includes(l)?[...fa]:[...fa,l].sort((f,b)=>f-b),m=Ue(fa,c,l),d=m>0&&m<1?Math.log(i)/Math.log(m):1,p=[],h=[];for(let f of u){let b=Ue(fa,c,f);p.push(o+s*Math.pow(b,d)),h.push(e.constantResistance?a:a*$x(f))}return{kind:"table",soc:u,ocv:p,r0:h}}function Dd(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+=(Ue(t,r,s)+Ue(t,r,i))/2*(i-s)}return o}var ha=25,zx=new WeakMap;function jr(e){let t=zx.get(e);if(t)return t;let r=kl(e);if(r)throw new Error(r);let{cell:n,pack:o}=e,a=n.curve.kind==="table"?n.curve:Ld(n.curve,n.chemistry),s=o.series,i=o.parallel,c=s/i,l=a.rTempC,u=a.rGrid,m=i*n.capacityAh,d=s*n.vMin,p=n.iMaxA>0?i*n.iMaxA:1/0,h=n.iMaxChargeA!==void 0&&n.iMaxChargeA>0?n.iMaxChargeA:n.iMaxA/4,f=h>0?i*h:1/0,b=A=>s*Ue(a.soc,a.ocv,A),g=(A,F=ha)=>{let T=l&&u?Ml(a.soc,l,u,A,F):Ue(a.soc,a.r0,A)*Pd(F);return c*T+o.busResistance},y=(A,F,T)=>b(A)-F*g(A,T),x=(A,F,T)=>{if(!(A>0))return 0;let P=b(F),S=g(F,T);if(!(S>0))return A/P;let w=P*P-4*S*A;return w<0?NaN:2*A/(P+Math.sqrt(w))},k=(A,F,T)=>{if(!(A>0))return 0;let P=b(F),S=g(F,T);return S>0?2*A/(P+Math.sqrt(P*P+4*S*A)):A/P},v=A=>{let F=e.thermal;if(!F||F.derateFromC===void 0)return 1;let T=F.derateToC??F.derateFromC;return A<=F.derateFromC?1:!(T>F.derateFromC)||A>=T?0:1-(A-F.derateFromC)/(T-F.derateFromC)},R=(A,F,T=0)=>{let P=b(A),S=g(A,F),w=S>0?P/(2*S):1/0,C=K=>{if(!(S>0))return K*P;let D=Math.min(K,w);return D*(P-D*S)},L=S>0?Math.max(0,(P-d)/S):1/0,E=T>0&&Number.isFinite(T)?T:1/0,_=S>0?C(L):1/0,O=Number.isFinite(p)?C(p):1/0,I=S>0?P*P/(4*S):1/0,z=[["rules",E],["voltage-floor",_],["current",O],["matched-load",I]],B=z[0][0],V=z[0][1];for(let[K,D]of z)D<V&&(V=D,B=K);let j=v(F??ha);j<1&&(V=Number.isFinite(V)?V*j:V,B="temperature");let q=Number.isFinite(V)?x(V,A,F):1/0;return{watts:V,binding:B,rules:E,voltageFloor:_,current:O,matchedLoad:I,derate:j,amps:q,volts:Number.isFinite(q)?P-q*S:P}},M={model:e,table:a,capacityAh:m,chargeC:m*3600,energyKwh:m*(s*Dd(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:d,currentCeiling:p,chargeCurrentCeiling:f,massKg:n.massKg!==void 0?s*i*n.massKg:null,thermal:e.thermal?{heatCapacityJPerK:s*i*e.thermal.heatCapacityJPerK,coolingWPerK:s*i*e.thermal.coolingWPerK,...e.thermal.startC!==void 0?{startC:e.thermal.startC}:{},entropicVPerK:s*(e.thermal.entropicVPerK??0)}:null,derateAt:v,ocv:b,resistance:g,terminalVoltage:y,currentFor:x,chargeCurrentFor:k,maxPower:R};return zx.set(e,M),M}function Ed(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 Yx={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},Wx={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},jx={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 Id(){return{name:"Formula Student accumulator",cell:Ed(Yx),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 _d(){return{name:"LFP pack",cell:Ed(Wx),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 Nd(){return{name:"Road car pack",cell:Ed(jx),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 Od(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 Sl(e){if(e.kind==="ice"){let n=e.gearbox.efficiency;return{model:e,maxTorque:o=>o>e.limitRpm?0:Ue(e.rpm,e.torque,o),efficiency:()=>n}}let t=n=>Ue(e.rpm,e.torque,n),r=e.kind==="simple"?()=>e.efficiency:(n,o)=>Ml(e.effRpm,e.effTorque,e.effGrid,n,o);return{model:e,maxTorque:t,efficiency:r}}function Vd(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=h=>Math.max(0,e.terminalResistanceOhm*(1+.00393*(h-t))),l=h=>n>0&&o>0?n*Math.pow(Math.max(0,h)/o,a):0,u=(h,f,b)=>{let g=r>0?Math.abs(f)/r:0;return 1.5*c(b)*g*g+l(h)},m=(h,f)=>{let b=e.coolingWPerK*(f-e.coolantC)-l(h);return!(b>0)||r<=0?0:r*Math.sqrt(b/(1.5*c(f)))},d=e.coolingWPerK>0?e.heatCapacityJPerK/e.coolingWPerK:1/0,p=Number.isFinite(d)?.25*d:1/0;return{spec:e,startC:e.startC??e.coolantC,lossW:u,step(h,f,b){if(!(b>0)||!(e.heatCapacityJPerK>0))return h;let g=Number.isFinite(p)?Math.max(1,Math.ceil(b/p)):1,y=b/g,x=h;for(let k=0;k<g;k++)x+=(f-e.coolingWPerK*(x-e.coolantC))*y/e.heatCapacityJPerK;return x},continuousTorque:m,derate(h,f,b){if(s===void 0||i===void 0||!(i>s)||!(b>0)||f<=s)return 1;let g=Math.min(1,m(h,i)/b);return f>=i?g:1-(1-g)*(f-s)/(i-s)},equilibriumC(h){return e.coolingWPerK>0?e.coolantC+h/e.coolingWPerK:1/0}}}function lt(e,t){return t==="rear"&&e.tireRateRear!==void 0?e.tireRateRear:e.tireRate}function Bd(e,t){let r=e.tyreFreeRadiusRear;return(t==="rear"&&r!==void 0?r:e.tyreFreeRadius)??0}var Al=9.81,Ux=(e,t)=>e*(t*t)/2*(Math.PI/180)/1e3,Ns=(e,t)=>e+t>0?e*t/(e+t):0,Xx=.5;function wl(e,t,r){if(!(r>0))return 1;let n=e*Al*t*(Math.PI/180)/r;return 1/(1-Math.min(Xx,n))}function $d(e,t,r){return r>0?e*Al*t/(r*r):0}function qx(e,t,r,n,o){if(!(n>0)||!(o>0))return 1;let a=$d(e,t,r)*(1/n+1/o);return 1/(1-Math.min(Xx,a))}function Be(e){let t=4*e.unsprungPerCorner,r=Math.max(0,e.massTotal-t),n=r*e.frontMassFrac,o=r*(1-e.frontMassFrac),a=lt(e,"front"),s=lt(e,"rear"),i=e.wheelRateFront+(e.heaveSpringFront??0),c=e.wheelRateRear+(e.heaveSpringRear??0),l=Ns(i,a),u=Ns(c,s),m=(O,I)=>{let z=I/2;return z>0?1/(2*Math.PI)*Math.sqrt(O*1e3/z):0},d=m(l,n),p=m(u,o),h=Ns(e.wheelRateFront+e.arbFront,a),f=Ns(e.wheelRateRear+e.arbRear,s),b=Ux(h,e.trackFront),g=Ux(f,e.trackRear),y=b+g,x=y>0?b/y:.5,k=e.rcHeightFront+(e.rcHeightRear-e.rcHeightFront)*(1-e.frontMassFrac),v=(e.cgHeight-k)/1e3,R=r*Al*v,M=wl(r,v,y),A=y>0?R/y*M:0,F=e.massTotal*Al*e.cgHeight/e.wheelbase,T=2*l,P=2*u,S=qx(r,e.cgHeight,e.wheelbase,T,P),C=(T>0&&P>0?(F/T+F/P)/e.wheelbase*S:0)*(180/Math.PI),L=e.wheelbase*e.wheelbase*Ns(T,P)*(Math.PI/180)/1e3,E=e.damperFront??2.5,_=e.damperRear??2.5;return{sprungMass:r,sprungFront:n,sprungRear:o,rideRateFront:l,rideRateRear:u,rideFreqFront:d,rideFreqRear:p,rollRateFront:b,rollRateRear:g,rollRateTotal:y,rollWheelRateFront:h,rollWheelRateRear:f,frontRollStiffFrac:x,rollGradient:A,pitchGradient:C,pitchRate:L,cgRollGain:M,cgPitchGain:S,rideDampingFront:E+(e.heaveDamperFront??0),rideDampingRear:_+(e.heaveDamperRear??0),rollDampingFront:E+(e.rollDamperFront??0),rollDampingRear:_+(e.rollDamperRear??0)}}var Fn=["clFront","clRear","cd"],Cn=e=>e.frame?.kind==="pitch";function ba(e){return Cn(e)?{x:e.axes.h,y:e.axes.pitch}:{x:e.axes.hFront,y:e.axes.hRear}}var Fl=e=>e.frame?.kind==="pitch",Qx=e=>e.kind==="map";var Cl=45,dt=e=>typeof e=="number"&&Number.isFinite(e);function Tl(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(dt))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 Zx(e,t){if(t===void 0)return null;for(let r of Fn){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(dt)||!n.factor.every(dt))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 Jx(e,t){return t===void 0?null:!dt(t.dCl)||!dt(t.dBalance)||!dt(t.dCd)?`The ${e} slopes must be numbers.`:!dt(t.maxDeg)||!(t.maxDeg>0)?`The ${e} response needs a positive angle to be valid to.`:null}function Os(e){if(!e||typeof e!="object")return"Not an aero model.";if(!dt(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=Tl("front ride-height",e.axes?.hFront);if(i)return i;let c=Tl("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(!dt(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=Tl("ride-height",e.axes?.h);if(i)return i;let c=Tl("pitch",e.axes?.pitch,"\xB0","pitch");if(c)return c;let l=e.axes.pitch.find(u=>Math.abs(u)>=Cl);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 Fn){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(dt))return`${i} contains a value that is not a number.`}}return Zx("yaw",e.attitude?.yaw)??Zx("roll",e.attitude?.roll)}if(e.kind==="sensitivity"){let t;if(e.frame==null)t=["hFront","hRear"];else if(e.frame?.kind==="pitch"){if(!dt(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||!dt(r[t[0]])||!dt(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 Fn){if(!e.at||!dt(e.at[s]))return`${s} at the reference must be a number.`;let i=n?.[s];if(!i||!dt(i[t[0]])||!dt(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||!dt(i[0])||!dt(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])>=Cl||Math.abs(i[1])>=Cl))return`A pitch range reaching ${Math.abs(i[0])>=Cl?i[0]:i[1]}\xB0 is not a car's attitude. Pitch is in degrees.`}return Jx("yaw",e.attitude?.yaw)??Jx("roll",e.attitude?.roll)}return`Unknown aero model kind "${e.kind}".`}var eR=180/Math.PI;function ga(e,t,r,n){let o=(n-r)/t;return{h:r+e.refX*o,pitch:Math.atan(o)*eR}}function ya(e,t,r,n){let o=Math.tan(n/eR);return{hFront:r-e.refX*o,hRear:r+(t-e.refX)*o}}var OK=180/Math.PI,DP=["hFront","hRear"],EP=["h","pitch"],Hd=e=>e?.kind==="pitch"?EP:DP,Yt=(e,t)=>e[t],Pl=(e,t)=>e[t],Gd=(e,t)=>({[e[0]]:t(e[0]),[e[1]]:t(e[1])});function IP(e){if(!(!e.yaw&&!e.roll))return{...e.yaw?{yaw:{...e.yaw}}:{},...e.roll?{roll:{...e.roll}}:{}}}function zd(e){let t=Hd(e.frame),r=e.balanceFront,n=e.cl*r,o=e.cl*(1-r),a=Gd(t,c=>Yt(e.dCl,c)*r+e.cl*Yt(e.dBalance,c)),s=Gd(t,c=>Yt(e.dCl,c)*(1-r)-e.cl*Yt(e.dBalance,c)),i=IP(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:Gd(t,c=>Yt(e.dCd,c))},range:{[t[0]]:[...Pl(e.range,t[0])],[t[1]]:[...Pl(e.range,t[1])]},provenance:{...e.provenance},...i?{attitude:i}:{}}}function Ll(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=>Ll(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 tR(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 rR(e,t,r,n=0,o=0){let[a,s]=Hd(e.frame),i=t-Yt(e.ref,a),c=r-Yt(e.ref,s),l={clFront:e.at.clFront+Yt(e.slope.clFront,a)*i+Yt(e.slope.clFront,s)*c,clRear:e.at.clRear+Yt(e.slope.clRear,a)*i+Yt(e.slope.clRear,s)*c,cd:e.at.cd+Yt(e.slope.cd,a)*i+Yt(e.slope.cd,s)*c},u=e.attitude?.yaw?Ll(e.at,e.attitude.yaw,n):{clFront:1,clRear:1,cd:1},m=e.attitude?.roll?Ll(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 Yd(e){let[t,r]=Hd(e.frame),n=[...Pl(e.range,t)],o=[...Pl(e.range,r)],a=i=>o.map(c=>n.map(l=>i(rR(e,l,c)))),s=tR(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 Wd=180/Math.PI,nR=new WeakMap,oR=new WeakMap,jd=new WeakMap;function Tn(e,t){let r=oR.get(e);if(r)return r;let n=t?.wheelbase,o=n!==void 0?jd.get(e)?.get(n):void 0;if(o)return o;let a=_P(e),s=a.map;if(!Cn(s)){let l=NP(e,a);return oR.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=OP(e,a,s.frame,n),c=jd.get(e);return c||(c=new Map,jd.set(e,c)),c.set(n,i),i}function _P(e){let t=nR.get(e);if(t)return t;let r=Os(e);if(r)throw new Error(r);let n=e.kind==="map"?e:Yd(e),{x:o,y:a}=ba(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},d=(y,x)=>{let k=Math.abs(x),v=y.clFront.deg[y.clFront.deg.length-1];return{clFront:Ue(y.clFront.deg,y.clFront.factor,k),clRear:Ue(y.clRear.deg,y.clRear.factor,k),cd:Ue(y.cd.deg,y.cd.factor,k),clamped:k>v}},p=(y,x)=>{if(!u)return m;let k=c?d(c,y):m,v=l?d(l,x):m;return{clFront:k.clFront*v.clFront,clRear:k.clRear*v.clRear,cd:k.cd*v.cd,clamped:k.clamped||v.clamped}},h=(y,x,k=0,v=0)=>{let R=ao(o,y),M=ao(a,x),A=Math.min(R.i+1,s-1),F=Math.min(M.i+1,i-1),T=S=>{let w=S[M.i][R.i],C=S[M.i][A],L=S[F][R.i],E=S[F][A],_=w+R.t*(C-w),O=L+R.t*(E-L);return _+M.t*(O-_)},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:R.clamped||M.clamped,clampedAttitude:P.clamped}},f={x:[o[0],o[s-1]],y:[a[0],a[i-1]]},b=(y,x,k=!1,v=0,R=0)=>{let M=p(v,R),A=ao(o,k?Math.min(Math.max(y,f.x[0]),f.x[1]):y),F=ao(a,k?Math.min(Math.max(x,f.y[0]),f.y[1]):x),T=Math.min(A.i+1,s-1),P=Math.min(F.i+1,i-1),S=T>A.i?o[T]-o[A.i]:0,w=P>F.i?a[P]-a[F.i]:0,C={};for(let L of Fn){let E=n[L],_=E[F.i][A.i],O=E[F.i][T],I=E[P][A.i],z=E[P][T],B=A.clamped||S===0?0:((O-_)*(1-F.t)+(z-I)*F.t)/S,V=F.clamped||w===0?0:((I-_)*(1-A.t)+(z-O)*A.t)/w;C[L]=u?{x:B*M[L],y:V*M[L]}:{x:B,y:V}}return C},g={map:n,x:f.x,y:f.y,hasAttitude:u,factors:p,at:h,slopes:b};return nR.set(e,g),g}function NP(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 Fn)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 OP(e,t,r,n){let o=r.refX,a=o/n,s=(l,u,m=0,d=0)=>{let p=(u-l)/n;return t.at(l+o*p,Math.atan(p)*Wd,m,d)},i=(l,u,m=!1,d=0,p=0)=>{let h=(u-l)/n,f=t.slopes(l+o*h,Math.atan(h)*Wd,m,d,p),b=Wd/(n*(1+h*h)),g={};for(let y of Fn)g[y]={hFront:f[y].x*(1-a)-f[y].y*b,hRear:f[y].x*a+f[y].y*b};return g},c={frame:r,x:t.x,y:t.y,at:t.at,toAxles:(l,u)=>ya(r,n,l,u),fromAxles:(l,u)=>{let m=ga(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 Ud(e){let t=e.clFront+e.clRear;return{cl:t,balanceFront:t!==0?e.clFront/t:.5}}var Se=(e,t)=>e*t/100,ut=e=>e/100,aR={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:Se(3,-.4),hRear:Se(3,.1)},dBalance:{hFront:ut(-.3),hRear:ut(.15)},dCd:{hFront:Se(1.3,-.1),hRear:Se(1.3,.05)},yaw:{dCl:Se(3,-1),dBalance:ut(-.3),dCd:Se(1.3,.5),maxDeg:10},roll:{dCl:Se(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."},sR={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:Se(3,-.3),hRear:Se(3,-.15)},dBalance:{hFront:ut(-.15),hRear:ut(.15)},dCd:{hFront:Se(.9,-.15),hRear:Se(.9,-.05)},yaw:{dCl:Se(3,-1.5),dBalance:ut(.2),dCd:Se(.9,.8),maxDeg:8},roll:{dCl:Se(3,-1),dBalance:ut(-.3),dCd:0,maxDeg:2},note:"Assumed class-level sensitivities for a ground-effect floor, ride height, yaw and roll; not measured."},iR={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:Se(1.4,-.3),hRear:Se(1.4,.05)},dBalance:{hFront:ut(-.25),hRear:ut(.15)},dCd:{hFront:Se(.42,-.1),hRear:0},yaw:{dCl:Se(1.4,-.8),dBalance:ut(-.2),dCd:Se(.42,.6),maxDeg:10},roll:{dCl:Se(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."},cR={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:Se(.3,.5),maxDeg:10},note:"Assumed class-level sensitivities for a road car with no aero devices; not measured."},lR={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:Se(.45,-.4),hRear:Se(.45,.05)},dBalance:{hFront:ut(-.25),hRear:ut(.15)},dCd:{hFront:Se(.4,-.1),hRear:0},yaw:{dCl:Se(.45,-1.2),dBalance:ut(-.2),dCd:Se(.4,.6),maxDeg:10},roll:{dCl:Se(.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."},uR={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:Se(.6,-.35),hRear:Se(.6,.05)},dBalance:{hFront:ut(-.25),hRear:ut(.15)},dCd:{hFront:Se(.45,-.1),hRear:0},yaw:{dCl:Se(.6,-1),dBalance:ut(-.2),dCd:Se(.45,.6),maxDeg:10},roll:{dCl:Se(.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."},mR={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:Se(2.5,-.35),hRear:Se(2.5,.05)},dBalance:{hFront:ut(-.25),hRear:ut(.15)},dCd:{hFront:Se(.9,-.1),hRear:Se(.9,.05)},yaw:{dCl:Se(2.5,-1),dBalance:ut(-.3),dCd:Se(.9,.5),maxDeg:10},roll:{dCl:Se(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."},pR={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:Se(.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 Ur(e){return zd({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 Xd=()=>Ur(aR),qd=()=>Ur(sR),Qd=()=>Ur(iR),Zd=()=>Ur(cR),Jd=()=>Ur(lR),ef=()=>Ur(uR),tf=()=>Ur(mR),rf=()=>Ur(pR);function so(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,lt(e,"front")))/r,rear:(t.sprungMass*(1-n)+o*a(t.rideRateRear,lt(e,"rear")))/r}}function El(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 nf(e,t){return e.wheelbase>0?e.massTotal*t*9.81/e.wheelbase:0}function xa(e,t,r){let n=2*t.rideRateFront,o=2*t.rideRateRear;return!(n>0)||!(o>0)?0:Math.min($d(t.sprungMass,r,e.wheelbase),.5*n*o/(n+o))}function Vs(e,t,r,n,o){let a=e.cgHeight,s=nf(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,d=0,p=0;for(let f=0;f<6;f++){p=xa(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,d=(g*(c-p)-p*b)/k}else m=c>0?b/c:0,d=l>0?g/l:0;let y=El(a,i,m,d),x=Math.abs(y-u);if(u=y,x<1e-9)break}let h=m-d;return{height:u,forward:e.wheelbase>0?u*h/e.wheelbase:0,noseLoad:p*h,dropFront:m,dropRear:d}}var of={yawDeg:0,rollDeg:0},dR=1e-4,VP=40,fR=50;function Pn(e,t,r=0){let n=e.aero?.model;if(!(!n||!Tn(n,e).hasAttitude))return{yawDeg:r,rollDeg:Be(e).rollGradient*t}}function Ra(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 ya(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=Fl(r)?n(r.frame,r.ref.h,r.ref.pitch):r.ref;else if(r){let{x:a,y:s}=ba(r),i=(a[0]+a[a.length-1])/2,c=(s[0]+s[s.length-1])/2;o=Cn(r)?n(r.frame,i,c):{hFront:i,hRear:c}}return{hFront:e.rideHeightFront??o.hFront,hRear:e.rideHeightRear??o.hRear}}var hR=new WeakMap;function Xr(e,t,r=0,n){let o=e.aero;if(!o?.model)return null;let a=hR.get(e);a||(a=new Map,hR.set(e,a));let s=n&&Tn(o.model,e).hasAttitude?n:of,i=s===of?`${t}|${r}`:`${t}|${r}|${s.yawDeg.toFixed(3)}|${s.rollDeg.toFixed(3)}`,c=a.get(i);if(c)return c;let l=BP(e,o,t,r,s);return a.size>4096&&a.clear(),a.set(i,l),l}function BP(e,t,r,n,o){let a=Tn(t.model,e),s=Be(e),i=2*s.rideRateFront,c=2*s.rideRateRear,l=Ra(t,e.wheelbase),u=.5*t.rho*r*r,m=a.area,d=e.wheelbase>0?t.copHeight/e.wheelbase:0,p=Dl(e,s),h=nf(e,n),f=(T,P)=>El(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),w=u*m*S.clFront,C=u*m*S.clRear,L=u*m*S.cd,E=L*d,_=f(T,P),O=h*_,I=xa(e,s,_)*b(T,P),z=w-O-E+I,B=C+O+E-I,V=T-l.hFront+(i>0?z/i:0),j=P-l.hRear+(c>0?B/c:0);return{c:S,downFront:w,downRear:C,drag:L,rF:V,rR:j,norm:Math.hypot(V,j)}},y=(T,P,S=!1)=>{let w=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*(w.clFront.hFront-d*w.cd.hFront),C*(w.clFront.hRear-d*w.cd.hRear)],[L*(w.clRear.hFront+d*w.cd.hFront),L*(w.clRear.hRear+d*w.cd.hRear)]]},x=l.hFront,k=l.hRear,v=g(x,k),R=0;for(;v.norm>=dR&&R<VP;){R++;let T=y(x,k),P=i>0?h/i:0,S=c>0?h/c:0,w=xa(e,s,f(x,k)),C=i>0?w/i:0,L=c>0?w/c:0,E=1+T[0][0]-P*p.front-C,_=T[0][1]-P*p.rear+C,O=T[1][0]+S*p.front+L,I=1+T[1][1]+S*p.rear-L,z=E*I-_*O,B,V;Math.abs(z)>1e-9?(B=-(I*v.rF-_*v.rR)/z,V=-(-O*v.rF+E*v.rR)/z):(B=-.5*v.rF,V=-.5*v.rR);let j=Math.max(1,Math.abs(B)/fR,Math.abs(V)/fR);B/=j,V/=j;let q=1;for(let K=0;K<6;K++){let D=g(x+q*B,k+q*V);if(D.norm<=v.norm||K===5){x+=q*B,k+=q*V,v=D;break}q*=.5}}let M=y(x,k,!0),A=2+M[0][0]+M[1][1],F=(1+M[0][0])*(1+M[1][1])-M[0][1]*M[1][0];return{v:r,axG:n,hFront:x,hRear:k,cgHeight:f(x,k),cgForward:e.wheelbase>0?f(x,k)*b(x,k)/e.wheelbase:0,cgNoseLoad:xa(e,s,f(x,k))*b(x,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:$P(M),stable:F>0&&A>0,converged:v.norm<dR,iterations:R,clampedRide:v.c.clampedRide,yawDeg:o.yawDeg,rollDeg:o.rollDeg,clampedAttitude:v.c.clampedAttitude}}function $P(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 Bs(e,t,r=0,n){let o=Xr(e,t,r,n);return o?{downforce:o.downforce,drag:o.drag,downFront:o.downFront,downRear:o.downRear}:e.aero?so(e.aero,t):{downforce:0,drag:0,downFront:0,downRear:0}}function GP(e,t,r,n){let o=so(t,r),a=Be(e),s=Ra(t,e.wheelbase),i=e.wheelbase>0?o.drag*t.copHeight/e.wheelbase:0,c=Vs(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 af(e,t,r=0,n){let o=Xr(e,t,r,n);return o||(e.aero?GP(e,e.aero,t,r):null)}function Il(e,t=0,r=0,n,o){if(e.aero&&t>0){if(e.aero.model){let i=Xr(e,t,r,n);return{height:i.cgHeight,forward:i.cgForward,noseLoad:i.cgNoseLoad}}let a=so(e.aero,t),s=e.wheelbase>0?a.drag*e.aero.copHeight/e.wheelbase:0;return Vs(e,o??Be(e),r,a.downFront-s,a.downRear+s)}return r===0?{height:e.cgHeight,forward:0,noseLoad:0}:Vs(e,o??Be(e),r,0,0)}var bR=[0,1,0],sf=[0,0,1],oe=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],G=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Q=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],cf=e=>[-e[0],-e[1],-e[2]],J=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],le=(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]],KP=e=>J(e,e),Ln=e=>Math.sqrt(J(e,e)),$s=(e,t)=>KP(G(e,t)),Ee=(e,t)=>Ln(G(e,t)),te=e=>{let t=Ln(e);return t<1e-12?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]};var Dn=(e,t,r)=>{let n=te(r),o=G(e,t);return oe(t,Q(n,J(o,n)))},gR=(e,t,r)=>Ee(e,Dn(e,t,r));var zP=1e-6;function YP(e){if(e<zP){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 Mt(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]=YP(r),a=le(e,t),s=le(e,a);return oe(t,oe(Q(a,n),Q(s,o)))}function nr(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 Mt(Q(o,r),e)}function Ar(e,t){let r=t.length,n=e.map(a=>a.slice()),o=t.slice();return xR(n,o,r,new Array(r).fill(0))}function yR(e,t,r){return xR(e,t,t.length,r)}function xR(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 d=s;d<r;d++)e[u][d]-=m*e[s][d];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 RR=e=>{let t=0;for(let r of e)t=Math.max(t,Math.abs(r));return t},vR=e=>{let t=0;for(let r of e)t+=r*r;return t},WP=Math.sqrt(Number.EPSILON);function kR(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=RR(c),u=vR(c),m=.001,d=1,p=c.length,h=Array.from({length:p},()=>new Array(a).fill(0)),f=Array.from({length:a},()=>new Array(a).fill(0)),b=Array.from({length:a},()=>new Array(a).fill(0)),g=new Array(a).fill(0),y=new Array(a).fill(0),x=new Array(a).fill(0),k=new Array(a).fill(0),v=new Array(a).fill(0);for(let R=0;R<n;R++){if(l<o)return{x:i,residualNorm:l,iterations:R,converged:!0,condProxy:d};for(let T=0;T<a;T++){let P=WP*Math.max(Math.abs(i[T]),s[T]);for(let w=0;w<a;w++)k[w]=i[w];k[T]+=P;let S=e(k);for(let w=0;w<p;w++)h[w][T]=(S[w]-c[w])/P}let M=0;for(let T=0;T<a;T++){for(let S=0;S<a;S++){let w=0;for(let C=0;C<p;C++)w+=h[C][T]*h[C][S];f[T][S]=w}let P=0;for(let S=0;S<p;S++)P+=h[S][T]*c[S];g[T]=P,M=Math.max(M,f[T][T])}let A=Math.max(M,1e-9),F=!1;for(let T=0;T<18;T++){let P=m*A;for(let w=0;w<a;w++){let C=f[w],L=b[w];for(let E=0;E<a;E++)L[E]=w===E?C[E]+P:C[E];y[w]=-g[w]}let S=yR(b,y,x);if(d=Math.max(d,S.condProxy),!S.singular){for(let L=0;L<a;L++)v[L]=i[L]+x[L];let w=e(v),C=vR(w);if(C<u){for(let L=0;L<a;L++)i[L]=v[L];c=w,u=C,l=RR(c),m=Math.max(m*.3,1e-12),F=!0;break}}m=Math.min(m*4,1e12)}if(!F)break}return{x:i,residualNorm:l,iterations:n,converged:l<o,condProxy:d}}function Gs(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 lf(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 MR=e=>[e[0],-e[1],-e[2],-e[3]];function SR(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 AR(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 wR(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 uf(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],d=n+i+m;if(d>=n&&d>=i&&d>=m){let f=Math.sqrt(1+d),b=.5/f;return[.5*f,(c-u)*b,(l-a)*b,(o-s)*b]}if(n>=i&&n>=m){let f=Math.sqrt(1+n-i-m),b=.5/f;return[(c-u)*b,.5*f,(s+o)*b,(l+a)*b]}if(i>=m){let f=Math.sqrt(1-n+i-m),b=.5/f;return[(l-a)*b,(s+o)*b,.5*f,(u+c)*b]}let p=Math.sqrt(1-n-i+m),h=.5/p;return[(o-s)*h,(l+a)*h,(u+c)*h,.5*p]}function FR(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 CR(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 jP(e){let t=Math.abs(e[0])<.6?[1,0,0]:[0,1,0],r=te(le(e,t));return[r,le(e,r)]}function UP(e){let t=e.hardpoints,r=te(G(t.damperChassis,t.pushrodOuter)),[n,o]=jP(r);return{top:t.damperChassis,lower0:t.pushrodOuter,axis0:r,e1:n,e2:o}}function mf(e){let t=e.hardpoints,r=t.wheelCenter,n=te(G(t.ucaRear,t.ucaFront)),o=G(t.uprightUpper,t.ucaFront),a=J(o,n),s=G(o,Q(n,a)),i=J(s,s),c=te(G(t.lcaRear,t.lcaFront)),l=G(t.uprightLower,t.lcaFront),u=$s(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:te(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:UP(e)}:{}}}function or(e,t,r){let n=[t[3],t[4],t[5]],o=[t[0],t[1],t[2]],a=G(r,e.c0);return oe(oe(Mt(n,a),e.c0),o)}function pf(e,t){return oe(e.lcaFront,nr(e.lbjRel0,e.lcaDir,t))}function io(e,t){return e.steerMovesRack?oe(e.tieInner0,Q(e.rackAxis,t)):e.tieInner0}function df(e,t,r,n){let o=or(e,t,e.lbj0),a=pf(e,r),s=o[0]-a[0],i=o[1]-a[1],c=o[2]-a[2],l,u;if(e.strut){let h=e.strut,f=[t[3],t[4],t[5]],b=G(h.top,or(e,t,h.lower0));l=J(b,Mt(f,h.e1)),u=J(b,Mt(f,h.e2))}else{let h=or(e,t,e.ubj0),f=G(h,e.ucaFront),b=J(f,e.ucaDir),g=G(f,Q(e.ucaDir,b));l=b-e.ubjAxial0,u=(J(g,g)-e.ubjRadius2)/e.ubjRadiusRef}let m=or(e,t,e.tro0),d=io(e,n),p=($s(m,d)-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]),_l=e=>{let t=Ks(e);return[e[0]/t,e[1]/t,e[2]/t]},XP=(e,t)=>G(e,Q(t,J(e,t))),ff=e=>_l(le(e,Math.abs(e[0])<.6?[1,0,0]:[0,1,0]));function qP(e,t){let r=e.ucaDir,n=oe(e.ucaFront,Q(r,e.ubjAxial0)),o=Math.sqrt(e.ubjRadius2),a=XP(G(e.ubj0,e.ucaFront),r),s=Ks(a)>1e-9?_l(a):ff(r),i=le(r,s),c=G(e.ubj0,e.lbj0),l=J(c,c);if(!(l>1e-18))return"free";let u=G(n,t),m=J(u,u),d=Gs(2*o*J(s,u),2*o*J(i,u),l-m-o*o,2*o*Math.sqrt(m));if(d.free)return"free";let p=_l(c),h=(f,b)=>{let g=oe(n,oe(Q(s,o*f),Q(i,o*b))),y=_l(G(g,t));return{q1:AR(p,y),k:y,margin:d.margin,ok:d.ok}};return d.margin>0?[h(d.c1,d.s1),h(d.c2,d.s2)]:[h(d.c1,d.s1)]}function QP(e,t,r){let n=t.axis0,o=oe(t.lower0,Q(n,J(G(e.lbj0,t.lower0),n))),a=G(o,e.lbj0),s=Ks(a),i=s>1e-9?Q(a,1/s):ff(n),c=G(t.top,r),l=Ks(c);if(!(l>1e-9))return"free";let u=Q(c,1/l),m=s/l,d=1-m,p=d>=0?Math.sqrt((1-m)*(1+m)):0,h=ff(u),f=b=>{let g=b*p,y=oe(Q(u,g),Q(h,Math.min(m,1))),x=G(Q(u,Math.min(m,1)),Q(h,g));return{q1:lf(uf(x,y,le(x,y)),MR(uf(i,n,le(i,n)))),k:u,margin:d,ok:d>=0}};return d>0?[f(1),f(-1)]:[f(1)]}function ZP(e,t,r,n){let{k:o}=n,a=SR(n.q1,G(e.tro0,e.lbj0)),s=J(a,o),i=G(a,Q(o,s)),c=Ks(i);if(!(c>1e-9))return"free";let l=Q(i,1/c),u=le(o,l),m=oe(t,Q(o,s)),d=G(m,r),p=J(d,d),h=Gs(2*c*J(d,l),2*c*J(d,u),e.tieLen2-p-c*c,2*c*Math.sqrt(p));if(h.free)return"free";let f=(g,y)=>({q:lf(wR(o,g,y),n.q1)});return{roots:h.margin>0?[f(h.c1,h.s1),f(h.c2,h.s2)]:[f(h.c1,h.s1)],margin:h.margin,ok:h.ok}}function TR(e,t,r,n=[0,0,0,0,0,0]){let o=pf(e,t),a=io(e,r),s=FR([n[3],n[4],n[5]]),i=f=>Math.abs(f[0]*s[0]+f[1]*s[1]+f[2]*s[2]+f[3]*s[3]),c=e.strut?QP(e,e.strut,o):qP(e,o);if(c==="free")return{x:n.slice(),converged:!1,margin:0,free:!0};let l=null,u=null;for(let f of c){let b=ZP(e,o,a,f);if(b==="free")return{x:n.slice(),converged:!1,margin:0,free:!0};let g=Math.min(f.margin,b.margin),y=b.ok&&f.ok;for(let{q:x}of b.roots){let k=i(x);y&&(!l||k>l.near)&&(l={q:x,margin:g,near:k}),!y&&(!u||k>u.near)&&(u={q:x,margin:g,near:k})}}let{q:m,margin:d}=l??u,p=CR(m),h=G(G(o,e.c0),Mt(p,G(e.lbj0,e.c0)));return{x:[h[0],h[1],h[2],p[0],p[1],p[2]],converged:l!==null,margin:d,free:!1}}function LR(e){let t=te(G(e.rockerPivotB,e.rockerPivotA));return{pivotA:e.rockerPivotA,axis:t,rprRel0:G(e.rockerToPushrod,e.rockerPivotA),rdmRel0:G(e.rockerToDamper,e.rockerPivotA),damperChassis:e.damperChassis,rodLen2:$s(e.pushrodOuter,e.rockerToPushrod),damperLen0:Ee(e.rockerToDamper,e.damperChassis)}}var JP=(e,t)=>oe(e.pivotA,nr(e.rprRel0,e.axis,t)),hf=(e,t)=>oe(e.pivotA,nr(e.rdmRel0,e.axis,t));function va(e,t){return{pushrod:JP(e,t),damper:hf(e,t)}}function DR(e,t,r=0){let n=J(e.rprRel0,e.axis),o=G(e.rprRel0,Q(e.axis,n)),a=le(e.axis,o),s=G(oe(e.pivotA,Q(e.axis,n)),t),i=J(o,o),c=J(s,s),l=Gs(2*J(s,o),2*J(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:Ee(hf(e,r),e.damperChassis),converged:p,margin:0}}let u=PR(Math.atan2(l.s1,l.c1),r),m=PR(Math.atan2(l.s2,l.c2),r),d=Math.abs(m-r)<Math.abs(u-r)?m:u;return{phi:d,damperLength:Ee(hf(e,d),e.damperChassis),converged:l.ok,margin:l.margin}}function PR(e,t){let r=2*Math.PI;return e+r*Math.round((t-e)/r)}function ER(e,t,r,n){return oe(t,Mt(Q(te(r),n),G(e,t)))}function IR(e,t,r,n){let o=te(n),a=d=>{let p=G(d,r);return G(p,Q(o,J(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,J(s,i)/(c*l))),m=J(le(s,i),o)/(c*l);return Math.atan2(m,u)}function _R(e,t,r,n){return oe(t,Mt(Q(te(r),n),G(e,t)))}var Nl=180/Math.PI,eL=(e,t,r)=>Math.max(t,Math.min(r,e)),NR=[NaN,NaN,NaN];function Hs(e){let t=te(e.spinAxis),r=te(G(e.uprightUpper,e.uprightLower)),n=-Math.asin(eL(t[2],-1,1))*Nl,o=Math.atan2(t[0],t[1])*Nl,a=Math.atan2(-r[0],r[2])*Nl,s=Math.atan2(-r[1],r[2])*Nl,i=te(oe([0,0,-1],Q(t,t[2]))),c=oe(e.wheelCenter,Q(i,e.loadedRadius)),l=e.patchShift?[c[0]+e.patchShift.x,c[1]+e.patchShift.y,c[2]]:c,u=e.uprightLower,m=Math.abs(r[2])>1e-9,d=F=>oe(u,Q(r,(F-u[2])/r[2])),p=m?d(l[2]):NR,h=m?d(e.wheelCenter[2]):NR,f=l[1]-p[1],b=p[0]-l[0],g=te(le(t,[0,0,1])),y=le([0,0,1],g),x=G(l,p),k=J(x,y),v=-J(x,g),R=e.wheelCenter[1]-h[1],M=h[0]-e.wheelCenter[0],A=gR(e.tieOuter,u,r);return{camber:n,toe:o,caster:a,kpi:s,scrubRadius:f,mechanicalTrail:b,scrubAtWheel:k,trailAtWheel:v,kingpinOffset:R,casterOffset:M,steeringArm:A,contactPatch:l,kingpinGround:p,kingpinAtHub:h}}function gt(e){return{corner:e,inv:mf(e),rocker:LR(e.hardpoints)}}var tL=[20,20,20,.2,.2,.2];function VR(e,t,r,n=[0,0,0,0,0,0]){let o=TR(e,t,r,n);if(!o.free)return o;let a=rL(e,t,r,n);return{x:a.x,converged:a.converged,margin:0}}function rL(e,t,r,n=[0,0,0,0,0,0]){return kR(o=>df(e,o,t,r),n,{scales:tL,tol:1e-10,maxIter:40})}var nL=.01,Ol=1.2,Lt=e=>e.ok?e.state:null,St=e=>e.ok?e.state:e.nearest;function we(e,t,r,n,o){let a=0,s=qe(e,a,r,n,o);if(Math.abs(s.travel-t)<1e-4)return OR(s,t,!1);let c=(qe(e,.02,r,bf(s),o).travel-s.travel)/.02;(!Number.isFinite(c)||Math.abs(c)<1e-6)&&(c=1);let l=d=>Math.max(-Ol,Math.min(Ol,d)),u=l((t-s.travel)/c),m=qe(e,u,r,bf(s),o);for(let d=0;d<12&&!(Math.abs(m.travel-t)<1e-4);d++){let p=m.travel-s.travel,h=Math.abs(p)<1e-9?u:u-(m.travel-t)*((u-a)/p);a=u,s=m,u=l(h),m=qe(e,u,r,bf(s),o)}return OR(m,t,Math.abs(u)===Ol)}function OR(e,t,r){let n=e.travel-t,o=Math.abs(n)<=nL,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 bf(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 oL(e,t,r,n,o){switch(e){case"upright":return or(t,r,o.pushrodOuter);case"upperArm":{let a=or(t,r,t.ubj0),s=IR(t.ubj0,a,t.ucaFront,t.ucaDir);return _R(o.pushrodOuter,t.ucaFront,t.ucaDir,s)}default:return ER(o.pushrodOuter,t.lcaFront,t.lcaDir,n)}}function qe(e,t,r,n,o){let{inv:a,corner:s}=e,i=n?.q??[0,0,0,0,0,0],c=VR(a,t,r,i),l=c.x,u=[l[3],l[4],l[5]],m={t:[l[0],l[1],l[2]],omega:u},d=s.hardpoints,p=s.config,h=a.strut,f=h?h.top:or(a,l,d.uprightUpper),b=or(a,l,d.uprightLower),g=or(a,l,d.tieOuter),y=or(a,l,d.wheelCenter),x=te(Mt(u,p.spinAxis)),k=oL(h?"upright":p.pushrodAttach,a,l,t,d),v=h?h.top:d.damperChassis,R=h||p.actuation==="direct"?{phi:0,damperLength:Ee(k,v),converged:!0,margin:1}:DR(e.rocker,k,n?.phi??0),M=Hs({uprightUpper:f,uprightLower:b,wheelCenter:y,spinAxis:x,tieOuter:g,loadedRadius:o?.loadedRadius??p.loadedRadius,patchShift:o?.patchShift});return{pose:m,beta:t,travel:l[2],steer:r,points:{uprightUpper:f,uprightLower:b,tieOuter:g,wheelCenter:y,pushrodOuter:k,spinAxis:x,contactPatch:M.contactPatch,kingpinGround:M.kingpinGround,kingpinAtHub:M.kingpinAtHub,rockerAngle:R.phi,damperLength:R.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:R.damperLength},converged:c.converged&&R.converged,margin:Math.min(c.margin,R.margin)}}var ka=e=>e==="FL"||e==="FR"?"front":"rear",$R=e=>e==="FL"||e==="RL"?"left":"right";function Qe(e,t){return e.corners?.[t]??aL(e[ka(t)],$R(t))}function GR(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 aL(e,t){let r=GR(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 wr=["FL","FR","RL","RR"],Ot=e=>2*e.hardpoints.wheelCenter[1],ar=(e,t)=>t?Ot(Qe(e,"FL"))/2+Ot(Qe(e,"FR"))/2:Ot(Qe(e,"RL"))/2+Ot(Qe(e,"RR"))/2;function nt(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 Wt(e,t){return[t.axleX+e[0],t.sideSign*e[1],e[2]]}function qr(e,t){return[e[0],t.sideSign*e[1],e[2]]}function En(e){return e.frontAxleX-e.wheelbase/2}function gf(e,t,r){return t[2]+e.heave+(t[0]-r)*Math.sin(e.pitch)-t[1]*Math.sin(e.roll)}function In(e,t,r,n){let o=nt(e,t),a=(n?ar(n,o.isFront):o.isFront?t.trackFront:t.trackRear)/2,s=o.sideSign*a,i=o.axleX-En(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 sL={travelMin:-40,travelMax:40,steps:41,steer:0};function zs(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 ot(e,t={}){let r={...sL,...t},n=gt(e);return Ma(n,r)}function Ma(e,t){let r=t.steer,n=.01,o=qe(e,n,r),a=qe(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=qe(e,0,r);u.push({beta:0,travel:m.travel,warm:zs(m),converged:m.converged});let d=zs(m);for(let x=1;x<=l;x++){let k=c*x/l,v=qe(e,k,r,d);d=zs(v),u.push({beta:k,travel:v.travel,warm:d,converged:v.converged})}d=zs(m);for(let x=1;x<=l;x++){let k=-c*x/l,v=qe(e,k,r,d);d=zs(v),u.push({beta:k,travel:v.travel,warm:d,converged:v.converged})}u.sort((x,k)=>x.beta-k.beta);let p=u[u.length-1].travel>=u[0].travel,h=!1;for(let x=1;x<u.length;x++){let k=u[x].travel-u[x-1].travel;(p&&k<-1e-6||!p&&k>1e-6)&&(h=!0)}let f=u.filter(x=>x.converged).map(x=>x.travel),b=f.length?[Math.min(...f),Math.max(...f)]:[0,0],g=f.length>0&&b[0]<=t.travelMin+1e-6&&b[1]>=t.travelMax-1e-6,y=[];for(let x=0;x<t.steps;x++){let k=t.steps===1?t.travelMin:t.travelMin+(t.travelMax-t.travelMin)*x/(t.steps-1),v=iL(u,k,p),R=cL(u,v);y.push(qe(e,v,r,R))}return lL(y,e.corner.config.actuation==="decoupled"?0:e.corner.config.springRate),{samples:y,covered:g,reach:b,fold:h,unconverged:y.filter(x=>!x.converged).length}}function iL(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 cL(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 yf(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 lL(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=yf(n,r,s),c=yf(o,r,s),l=-yf(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 Vl=e=>e!==void 0&&Number.isFinite(e)&&e>0;function uL(e){return e&&Vl(e.helperRate)&&Vl(e.helperTravel)?{rate:e.helperRate,travel:e.helperTravel}:null}function xf(e,t,r){let n=t/e;return r?n+Math.min(t/r.rate,r.travel):n}function Ys(e,t,r,n){if(!(e>0)||!Number.isFinite(e)||!(t>0)||!Number.isFinite(t))return null;let o=uL(n),a=-xf(e,t,o),s=Sa(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 Sa(e,t){if(!Number.isFinite(e))return{droop:null,bump:null};let r=Vl(t?.extended)&&t.extended>e?t.extended:null,n=r!==null&&Vl(t?.stroke)?r-t.stroke:null;return{droop:r!==null?e-r:null,bump:n!==null&&n<e?e-n:null}}function Rf(e,t){if(!(e>0)||!Number.isFinite(e))return null;let r=Sa(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 mL(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=xf(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 pL(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=xf(r,n,o)+t;return a<=0?0:a>=o.rate*o.travel/r+o.travel?r:r*o.rate/(r+o.rate)}function Aa(e,t){let r=mL(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 vf(e,t){let r=pL(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 kf(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 Bl={min:-60,max:60,steps:61},Mf=e=>({travel:[e.min,e.max],force:[0,0],motionRatio:[0,0],spring:null}),KR=new WeakMap;function dL(e,t){let r=KR.get(e.corner);r||KR.set(e.corner,r=new Map);let n=`${t.min}|${t.max}|${t.steps}`,o=r.get(n);return o||r.set(n,o=Ma(e,{travelMin:t.min,travelMax:t.max,steps:t.steps,steer:0})),o}function js(e,t,r=Bl,n=e.corner.config.coilover){let o=e.corner.config;if(o.actuation==="decoupled")return Mf(r);let a=dL(e,r),s=hL(e,o.springRate,a.samples),i=[];for(let f of a.samples){let b=f.metrics.motionRatio;!f.converged||b===void 0||!Number.isFinite(b)||!Number.isFinite(f.metrics.damperLength)||i.length>0&&f.travel<=i[i.length-1].t+1e-6||i.push({t:f.travel,L:f.metrics.damperLength,mr:b})}if(i.length<2)return Mf(r);let c=gL(i,0);if(!(Math.abs(c.mr)>1e-6))return Mf(r);let l=t/c.mr,u=Ys(s,l,c.L,n),m=u?fL(i,kf(u).map(f=>c.L-f)):i,d=m.map(f=>(u?Aa(u,c.L-f.L):l+s*(c.L-f.L))*f.mr-t),p=f=>f===null?null:m.find(b=>b.L===c.L-f)?.t??null,h=u?kf(u).map(p).filter(f=>f!==null):[];return{travel:m.map(f=>f.t),force:d,motionRatio:m.map(f=>f.mr),spring:{rate:s,preload:l,length0:c.L,law:u},...u?{stops:{droop:p(u.droop),bump:p(u.bump)}}:{},...h.length?{kinks:h}:{},length:m.map(f=>f.L)}}function Sf(e,t){if(!e.spring)return null;let r=e.travel.length,n=e.length;if(n&&n.length===r&&r>=2){let s=Fr(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+=(Ws(e,i)+Ws(e,c))/2*(c-i)}return a}function fL(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 hL(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:bL(e,n,r);return!(o>0)||!Number.isFinite(o)?t:t*o/(t+o)}function bL(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=va(e.rocker,n.points.rockerAngle),s=te(G(o.rockerPivotB,o.rockerPivotA)),i=(m,d)=>Math.abs(J(s,le(G(m,o.rockerPivotA),te(G(d,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 Ws(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.motionRatio[0];let n=Fr(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 Qr(e,t,r){if(!e.spring)return dr(e,t);let{rate:n,preload:o,length0:a,law:s}=e.spring,i=Ws(e,0),c=a-r;return(s?Aa(s,c):o+n*c)*Ws(e,t)-o*i}function gL(e,t){let r=Fr(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 Fr(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 dr(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.force[0];let n=Fr(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 wa(e,t){let r=e.travel.length;if(r<3)return Us(e,t);let n=Fr(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 Us(e,t){if(e.travel.length<2)return 0;let n=Fr(e.travel,t);return(e.force[n+1]-e.force[n])/(e.travel[n+1]-e.travel[n])}function ze(e,t,r){let n=e.hardpoints;switch(t.attach){case"upright":{let o=G(t.outer,n.wheelCenter);return oe(oe(Mt(r.pose.omega,o),n.wheelCenter),r.pose.t)}case"lowerArm":{let o=te(G(n.lcaRear,n.lcaFront));return oe(n.lcaFront,Mt(Q(o,r.beta),G(t.outer,n.lcaFront)))}case"rocker":{let o=te(G(n.rockerPivotB,n.rockerPivotA));return oe(n.rockerPivotA,nr(G(t.outer,n.rockerPivotA),o,r.points.rockerAngle))}}}function _n(e,t,r){return e.config.actuation==="decoupled"&&t.attach==="rocker"&&r==="coil"}function Af(e,t,r){return _n(e,t,r)?[t.inner[0],-t.inner[1],t.inner[2]]:t.inner}function Fa(e,t,r){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return wf(e,t,r.kind,ot(e,{travelMin:n,travelMax:o,steps:a}).samples)}function wf(e,t,r,n){let o=te(G(t.outer,Af(e,t,r))),a=[],s=[],i=t.outer;for(let p of n)a.push(p.travel),s.push(J(G(ze(e,t,p),i),o));let c=a.length,l=new Array(c).fill(0);for(let p=0;p<c;p++){let h=Math.max(0,p-1),f=Math.min(c-1,p+1),b=a[f]-a[h];l[p]=b!==0?(s[f]-s[h])/b:0}let u=l[0];for(let p=1;p<c;p++)if(a[p]>=0){let h=a[p]-a[p-1],f=h!==0?(0-a[p-1])/h:0;u=l[p-1]+f*(l[p]-l[p-1]);break}let m=l.filter(p=>Math.abs(p)>1e-9).map(Math.sign),d=m.length>0&&m.some(p=>p!==m[0]);return{travel:a,ratio:l,linkTravel:s,atDesign:u,reverses:d}}function Ff(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 Xs=e=>e.mount??{kind:"rockerToRocker"},WR=e=>[e[0],0,e[2]],yL=e=>2*Math.abs(e[1]),xL=(e,t)=>Math.hypot(e[0]-t[0],e[2]-t[2]);function Gl(e,t){return t.kind==="chassis"?xL(e,t.anchor):yL(e)}function qs(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 co(e,t,r={}){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return Tf(e,t,ot(e,{travelMin:n,travelMax:o,steps:a}).samples)}function Tf(e,t,r){let n=Xs(t),o=h=>ze(e,{...t,inner:t.outer},r[h]),a=[],s=[],i=[];for(let h=0;h<r.length;h++)a.push(r[h].travel),i.push(Gl(o(h),n));let c=zR(a,i,0);for(let h of i)s.push(c-h);let l=a.length,u=new Array(l).fill(0);for(let h=0;h<l;h++){let f=Math.max(0,h-1),b=Math.min(l-1,h+1),g=a[b]-a[f];u[h]=g!==0?(s[b]-s[f])/g:0}let m=HR(a,20),d=HR(a,-20),p=qs(o(m),o(d),n);return{travel:a,ratio:u,springTravel:s,atDesign:zR(a,u,0),installedLength:c,rollSensitivity:c-p}}function HR(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 zR(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=ot(e,{travelMin:-5,travelMax:5,steps:3}),a=h=>WR(ze(e,{...n,inner:n.outer},o.samples[h])),s=a(1),i=a(2),c=a(0),l=i[0]-c[0],u=i[2]-c[2],m=Math.hypot(l,u),d=m>1e-9?[l/m,u/m]:[0,1],p=r??Math.max(80,2*Math.abs(t.outer[1])*.5);return[s[0]+d[0]*p,0,s[2]+d[1]*p]}function Lf(e,t){let r=e.hardpoints,n=r.rockerPivotA,o=YR($l(r.rockerPivotB,r.rockerPivotA)),a=Math.max(30,.6*jR($l(r.rockerToDamper,n))),s=$l(r.rockerToDamper,n),i=YR($l(s,RL(o,vL(s,o)))),c=kL(o,i),l=null,u=-1/0;for(let m=0;m<360;m+=10){let d=m*Math.PI/180,h={outer:[n[0]+a*(Math.cos(d)*i[0]+Math.sin(d)*c[0]),n[1]+a*(Math.cos(d)*i[1]+Math.sin(d)*c[1]),n[2]+a*(Math.cos(d)*i[2]+Math.sin(d)*c[2])],attach:"rocker"},f=t==="chassis"?{...h,mount:{kind:"chassis",anchor:Pf(e,h)}}:h,b;try{b=co(e,f,{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=f)}return l??{outer:r.rockerToDamper,attach:"rocker"}}var $l=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],RL=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],vL=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],jR=e=>Math.hypot(e[0],e[1],e[2]),YR=e=>{let t=jR(e)||1;return[e[0]/t,e[1]/t,e[2]/t]},kL=(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 Df=.001,ML=e=>({outer:e.outer,inner:e.outer,attach:e.attach}),tv=(e,t,r)=>(Gl(e.at0,t)-Gl(r,t))/2,SL=(e,t)=>J(G(t,e.pickup.at0),e.axis);function Ef(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 UR(e,t){let r=[0,1,2].map(n=>Ef(e,t.map(o=>o[n])));return t.map((n,o)=>[r[0][o],r[1][o],r[2][o]])}function If(e){return{travel:e,heave:e.map(t=>t/2),heaveRatio:e.map(()=>.5),roll:[...e],rollRatio:e.map(()=>1)}}function XR(e,t,r,n){let o=e.corner;if(!t.heave&&!t.roll)return{side:If([n.min,n.max]),pickups:{}};let a=St(we(e,0,0)),s={};if(t.heave&&r){let f=ML(t.heave);s.heave={corner:o,link:f,at0:ze(o,f,a)}}if(t.roll){let f=t.roll;s.roll={pickup:{corner:o,link:f,at0:ze(o,f,a)},axis:te(G(f.outer,Af(o,f,t.rollKind??"coil")))}}let i=t.roll&&_n(o,t.roll,t.rollKind??"coil")?{near:t.roll,far:{...t.roll,outer:t.roll.inner}}:null,c=Ma(e,{travelMin:n.min,travelMax:n.max,steps:n.steps,steer:0}),l=[],u=[],m=[],d=[],p=[];for(let f of c.samples)!f.converged||l.length>0&&f.travel<=l[l.length-1]+1e-6||(l.push(f.travel),u.push(s.heave&&r?tv(s.heave,r,ze(o,s.heave.link,f)):f.travel/2),m.push(s.roll?SL(s.roll,ze(o,s.roll.pickup.link,f)):f.travel),i&&(d.push(ze(o,i.near,f)),p.push(ze(o,i.far,f))));if(l.length<2)return{side:If([n.min,n.max]),pickups:{}};let h={travel:l,heave:u,heaveRatio:Ef(l,u),roll:m,rollRatio:Ef(l,m)};return i&&(h.eyes={near:d,nearRatio:UR(l,d),far:p,farRatio:UR(l,p)}),{side:h,pickups:s}}function Kl(e,t,r){let n=Fr(e,r);return t[n]+(r-e[n])/(e[n+1]-e[n])*(t[n+1]-t[n])}function qR(e,t,r){let n=Fr(e,r);return(t[n+1]-t[n])/(e[n+1]-e[n])}function Ze(e,t){return{h:Kl(e.travel,e.heave,t),dh:Kl(e.travel,e.heaveRatio,t),ddh:qR(e.travel,e.heaveRatio,t),r:Kl(e.travel,e.roll,t),dr:Kl(e.travel,e.rollRatio,t),ddr:qR(e.travel,e.rollRatio,t)}}function QR(e,t,r,n){let o=Fr(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 _f=(e,t)=>Math.hypot(e[0]-t[0],e[1]+t[1],e[2]-t[2]);function Nf(e,t){let r=e.side[0].eyes,n=e.side[1].eyes;if(!r||!n)return null;let o=QR(e.side[0].travel,r.near,r.nearRatio,t[0]),a=QR(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]],d=J(c,l),p=J(c,u),h=(J(l,u)-d*p)/i;return{L:i,dL:[d,p],ddL:[[(J(l,l)-d*d)/i+J(c,o.dd),h],[h,(J(u,u)-p*p)/i+J(c,m)]]}}var rv=(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,AL=(e,t)=>e.bump!==null&&t>e.bump||e.droop!==null&&t<e.droop?e.rate:0;function Qs(e,t,r,n,o=0){let a=e.rollStop;if(!a)return r;let s=Nf(e,t);if(!s)return r;let i=rv(a,a.length0-(n??s.L+o));return i===0?r:[r[0]-i*s.dL[0],r[1]-i*s.dL[1]]}function Hl(e,t){let r=If(e.travel);return t==="heave"?{...e,heave:r.heave,heaveRatio:r.heaveRatio}:{...e,roll:r.roll,rollRatio:r.rollRatio}}var zl=(e,t)=>e?e.law?Aa(e.law,t):e.preload+e.rate*t:0,ZR=(e,t)=>e?e.law?vf(e.law,t):e.rate:0;function Zs(e,t,r,n,o){let a=zl(e.heave,n),s=zl(e.roll,o);return[a*t.dh+s*t.dr,a*r.dh-s*r.dr]}var JR=(e,t)=>Ze(e[0],t).h+Ze(e[1],t).h;function wL(e,t){let r=e.gap>0?JR(t,e.gap):0;return e.bothWays?{free:r,pull:e.gap>0?JR(t,-e.gap):0}:{free:r,pull:null}}function FL(e,t,r){let n={...t,outer:t.inner},o=(u,m)=>{let d=Lt(we(e[0],u,0)),p=Lt(we(e[1],m,0));if(!d||!p)return NaN;let h=ze(e[0].corner,t,d),f=ze(e[1].corner,n,p);return Math.hypot(h[0]-f[0],h[1]+f[1],h[2]-f[2])},a=1,s=o(0,0),i=o(-a,a)-o(a,-a),c=Ze(r[0],a).r-Ze(r[1],-a).r-(Ze(r[0],-a).r-Ze(r[1],a).r),l=i/c;return Number.isFinite(s)&&s>0&&Number.isFinite(l)&&Math.abs(l)>Df?{length0:s,scale:l}:null}function nv(e,t,r,n=Bl){let o=r.heave?Xs(r.heave):void 0,a=XR(e[0],r,o,n),s=e[1].corner===e[0].corner?a:XR(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,d=(t[0].arbRate+t[1].arbRate)/2,p=i.map(w=>Ze(w,0));c&&!(Math.abs(p[0].dh+p[1].dh)>Df)&&(i=[Hl(i[0],"heave"),Hl(i[1],"heave")],c=!1),l&&!(Math.abs(p[0].dr+p[1].dr)>Df)&&(i=[Hl(i[0],"roll"),Hl(i[1],"roll")],l=!1),p=i.map(w=>Ze(w,0));let h=p[0].dh+p[1].dh,f=p[0].dr+p[1].dr,b=m>0?2*m/(h*h):0,g=d>0?2*d/(f*f):0,y=0,x=0;if(r.carriesLoad){let w=[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=(-w[0]*p[1].dr-w[1]*p[0].dr)/C,x=(p[0].dh*w[1]-p[1].dh*w[0])/C)}else b>0?y=(w[0]+w[1])/h:g>0&&(x=(w[0]-w[1])/f)}let k={};if(c&&o){let w=[a.pickups.heave,s.pickups.heave];k.heave={pickups:w,mount:o,span0:qs(w[0].at0,w[1].at0,o)}}let v=k.heave?k.heave.span0:NaN,R=k.heave?r.coilover:void 0,M=r.carriesLoad?Ys(b,y,v,R):u?Rf(b,{...wL(u,i),length0:v,coilover:R}):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&&_n(e[0].corner,r.roll,r.rollKind??"coil"))){let w=FL(e,r.roll,i);w&&(k.roll.unit=w)}let F=g>0?{rate:g,preload:x}:null,T={side:i,heave:A,roll:F,force0:[0,0],carriesLoad:r.carriesLoad,read:k},P=k.roll?.unit,S=P&&g>0&&i[0].eyes&&i[1].eyes?Sa(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=Qs(T,[0,0],Zs(T,p[0],p[1],p[0].h+p[1].h,p[0].r-p[1].r)),T}function Js(e,t,r){let n=Ze(e.side[0],t[0]),o=Ze(e.side[1],t[1]),a=r?Qs(e,t,Zs(e,n,o,n.h+o.h+r.heave,n.r-o.r+r.roll),void 0,r.unit):Qs(e,t,Zs(e,n,o,n.h+o.h,n.r-o.r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function Of(e,t,r){let n=Ze(e.side[0],t[0]),o=Ze(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=ZR(e.heave,a),c=ZR(e.roll,s),l=zl(e.heave,a),u=zl(e.roll,s),m=i*n.dh*o.dh-c*n.dr*o.dr,d=[[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,h=p?Nf(e,t):null;if(!p||!h)return d;let f=p.length0-(r?h.L+r.unit:h.L),b=AL(p,f);if(b===0)return d;let g=rv(p,f),y=(k,v)=>b*h.dL[k]*h.dL[v]-g*h.ddL[k][v],x=m+y(0,1);return[[d[0][0]+y(0,0),x],[x,d[1][1]+y(1,1)]]}function Vf(e,t,r){let n=Of(e,t);return n[r][0]+n[r][1]}function CL(e,t,r){let n=e.read.heave;if(!n)return Ze(e.side[0],t[0]).h+Ze(e.side[1],t[1]).h;let[o,a]=n.pickups;return n.span0-qs(ze(o.corner,o.link,r[0]),ze(a.corner,a.link,r[1]),n.mount)}function TL(e,t,r){let n=e.read.roll;if(!n)return Ze(e.side[0],t[0]).r-Ze(e.side[1],t[1]).r;let o=a=>J(G(ze(n.pickups[a].corner,n.pickups[a].link,r[a]),n.pickups[a].at0),n.axes[a]);return o(0)-o(1)}function PL(e,t){let r=e.read.roll;if(!e.rollStop||!r)return;let[n,o]=r.pickups;return _f(ze(n.corner,n.link,t[0]),ze(o.corner,{...o.link,outer:o.link.inner},t[1]))}function ei(e,t,r){let n=Ze(e.side[0],t[0]),o=Ze(e.side[1],t[1]),a=Qs(e,t,Zs(e,n,o,CL(e,t,r),TL(e,t,r)),PL(e,r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function Bf(e,t,r,n){let o=Ze(e.side[0],r),a=Ze(e.side[1],r),s=e.read.heave,i=s?.pickups[t],c=s&&i&&n?2*tv(i,s.mount,ze(i.corner,i.link,n)):o.h+a.h,l=e.rollStop&&n?e.read.roll?.pickups[t]:void 0,u=l&&n?_f(ze(l.corner,l.link,n),ze(l.corner,{...l.link,outer:l.link.inner},n)):void 0;return Qs(e,[r,r],Zs(e,o,a,c,n?0:o.r-a.r),u)[t]-e.force0[t]}function $f(e,t,r,n){let o=wa(e,r[n]);return t?.carriesLoad?o+Vf(t,r,n):o}function ov(e,t){return Ze(e.side[0],t[0]).h+Ze(e.side[1],t[1]).h}function av(e,t){return Nf(e,t)?.L??null}var Gf=e=>e==="FR"||e==="RR"?1:0,Yl=(e,t)=>e.elements?.[t==="FL"||t==="FR"?"front":"rear"]??null;var sv=e=>Number.isFinite(e)&&e>0?1/e:0;var iv=(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},LL=(e,t)=>[e[0][0]*t[0]+e[0][1]*t[1],e[1][0]*t[0]+e[1][1]*t[1]],cv=1e-8,DL=40;function EL(e,t,r,n){return{force:(s,i)=>{if(r){let u=Js(r,s,n);return[dr(t[0],s[0])+i[0]+u[0],dr(t[1],s[1])+i[1]+u[1]]}let c=(s[0]+s[1])/2,l=(s[0]-s[1])/2;return[dr(t[0],s[0])+i[0]+e[0].heaveRate*c+e[0].arbRate*l,dr(t[1],s[1])+i[1]+e[1].heaveRate*c-e[1].arbRate*l]},stiffness:(s,i=Us)=>{if(r){let c=Of(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 Ca(e,t,r,n,o,a=[0,0],s=[0,0],i=null,c){let l=[sv(r[0].tyreRate),sv(r[1].tyreRate)],u=[r[0].staticLoad,r[1].staticLoad],m=EL(r,n,i,c),d=C=>m.force(C,a),p=m.stiffness([0,0]),h=[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]))],f=(C,L)=>{let E=L===1?d(C):m.force(C,[a[0]*L,a[1]*L]),_=[E[0]+s[0]*L,E[1]+s[1]*L],O=[C[0]+t[0]*L+_[0]*l[0]-e[0]*L,C[1]+t[1]*L+_[1]*l[1]-e[1]*L],I=[h[0]*(u[0]+_[0]),h[1]*(u[1]+_[1])],z=[I[0]<O[0],I[1]<O[1]];return{f:_,on:O,off:I,lifted:z,r:[Math.min(O[0],I[0]),Math.min(O[1],I[1])]}},b=(C,L)=>[L[0]?[h[0]*C[0][0],h[0]*C[0][1]]:[1+C[0][0]*l[0],C[0][1]*l[0]],L[1]?[h[1]*C[1][0],h[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]],_=f(E,L),O=!1,I=0;for(;I<DL;I++){if(g(_.r)<cv){O=!0;break}let z=iv(b(m.stiffness(E),_.lifted),[-_.r[0],-_.r[1]]);if(!z)break;let B=1,V=[E[0]+z[0],E[1]+z[1]],j=f(V,L);for(let q=0;q<8&&g(j.r)>g(_.r);q++)B/=2,V=[E[0]+B*z[0],E[1]+B*z[1]],j=f(V,L);E=V,_=j}return!O&&g(_.r)<cv&&(O=!0),{t:E,b:_,converged:O,it:I}},x=y(o?[o[0],o[1]]:[e[0]-t[0],e[1]-t[1]],1),k=x.it;if(!x.converged){let C=0,L=[0,0],E=.25;for(;C<1&&E>=1/256;){let _=Math.min(1,C+E),O=y(L,_);k+=O.it,O.converged?(C=_,L=O.t,_===1&&(x=O)):E/=2}}let{t:v,b:R,converged:M}=x,A=R.lifted,F=[A[0]?-u[0]:R.f[0],A[1]?-u[1]:R.f[1]],T=[A[0]?Math.max(0,R.on[0]):0,A[1]?Math.max(0,R.on[1]):0],P=m.stiffness(v,wa),S=b(P,A);return{t:v,dF:F,lifted:A,clearance:T,converged:M,iterations:k,respond:(C,L,E=[0,0])=>{let _=[A[0]?-h[0]*E[0]:C[0]-L[0]-E[0]*l[0],A[1]?-h[1]*E[1]:C[1]-L[1]-E[1]*l[1]],O=iv(S,_);if(!O)return[NaN,NaN];let I=LL(P,O);return[A[0]?0:I[0]+E[0],A[1]?0:I[1]+E[1]]}}}var lo=e=>!(Number.isFinite(e.tyreRate)&&e.tyreRate>0);function sr(e,t,r){return t?.input.corners[r].staticLoadedRadius??e}var Kf=["FL","FR","RL","RR"],mv={front:["FL","FR"],rear:["RL","RR"]},IL=512,_L=5e-4,NL=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]=St(we(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=>Qe(e.vehicle,p)===Qe(e.vehicle,s))}|${c.springLoad}|${u?`${u.extended}/${u.stroke}`:""}`,d=o.get(m);d?r[s]=d:(r[s]=u?js(i,c.springLoad,void 0,u):js(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=mv[s];a[s]=nv([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 pv(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 OL=e=>`${e.heave}|${e.pitch}|${e.roll}|${e.steer}`;function Hf(e,t,r){return{travel:r.travel,steer:r.steer,ground:r.travel,tyreDeflection:0,load:NaN,loadedRadius:sr(Qe(e.vehicle,t).config.loadedRadius,e.kc,t),lifted:!1,contactLength:0,converged:!0,rigid:!0,rideRate:NaN,wheelRateAtLoad:NaN}}var VL=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 lv(e,t,r,n){let o=mv[n],a=e.vehicle.config,s=o.map(F=>In(F,a,r,e.vehicle)),i=[t.input.corners[o[0]],t.input.corners[o[1]]],c=t.loadCase;if(!c&&i.every(lo))return{corners:[Hf(e,o[0],s[0]),Hf(e,o[1],s[1])],respond:null};let l=o.map(F=>t.curve[F]),u=t.elements?.[n]??null,m=o.map(F=>sr(Qe(e.vehicle,F).config.loadedRadius,t,F)),d=[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],h=[c?.patchShift[o[0]],c?.patchShift[o[1]]],f=[0,0],b=[0,0],g,y=Ca(d,f,i,l,void 0,void 0,p,u),x=[void 0,void 0],k=[!0,!0],v=[0,0],R=!1;for(let F=0;F<NL;F++){F>0&&(y=Ca(d,f,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 w=0;w<2;w++){let C=we(e.ctx[o[w]],y.t[w],s[w].steer,VL(x[w]),{loadedRadius:m[w]-v[w],patchShift:h[w]}),L=St(C);x[w]=L,k[w]=C.ok,T[w]=L.points.contactPatch[2]-t.ground0[o[w]]-y.t[w]-v[w],P[w]=Qr(l[w],y.t[w],L.points.damperLength)-dr(l[w],y.t[w])}if(u){let w=ei(u,y.t,[x[0],x[1]]),C=Js(u,y.t);P[0]+=w[0]-C[0],P[1]+=w[1]-C[1]}let S=Math.max(Math.abs(T[0]-f[0]),Math.abs(T[1]-f[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(f=T,b=P,g=y.t,S<_L){R=!0;break}}let M=y.respond([1,1],[0,0]);return{corners:[0,1].map(F=>{let T=x[F];return{travel:y.t[F],steer:s[F].steer,ground:d[F],tyreDeflection:v[F],load:i[F].staticLoad+y.dF[F],loadedRadius:m[F]-v[F],lifted:y.lifted[F],clearance:y.clearance[F],contactLength:pv(m[F]-v[F],i[F].staticLoad+y.dF[F],i[F].tyreRate),converged:y.converged&&R&&k[F],rigid:!1,state:T,solved:k[F],rideRate:M[F],wheelRateAtLoad:$f(l[F],u,y.t,F)}}),respond:y.respond}}function dv(e,t){let r=e.kc,n=OL(t),o=r.memo.get(n);if(o)return o;let a=lv(e,r,t,"front"),s=lv(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>=IL&&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]=Hf(e,n,In(n,e.vehicle.config,t,e.vehicle));return r}return dv(e,t).corners}function jl(e,t,r){return e.kc?dv(e,t).respond[r]:null}function ti(e,t,r,n=0){let o=e.kc;if(!o)return r;let a=o.input.corners[t];if(lo(a))return r;let s=In(t,e.vehicle.config,{heave:0,pitch:0,roll:0,steer:n},e.vehicle).steer,i=sr(Qe(e.vehicle,t).config.loadedRadius,o,t),c=o.loadCase,l=c?.linkLoad[t]??0,u=c?.patchShift[t],m=St(we(e.ctx[t],r,s,void 0,{loadedRadius:i,patchShift:u})),d=Yl(o,t),p=Qr(o.curve[t],r,m.points.damperLength)+(d?Bf(d,Gf(t),r,m):a.heaveRate*r),f=Math.max(p+l,-a.staticLoad)/a.tyreRate;return(f===0?m:St(we(e.ctx[t],r,s,void 0,{loadedRadius:i-f,patchShift:u}))).points.contactPatch[2]-o.ground0[t]-(c?.ground[t]??0)}var BL=180/Math.PI,$L=[0,0,1];function GL(e,t){let r=qr(e,t),n=Q(le($L,r),-t.sideSign);return-Math.atan2(n[1],n[0])*BL}var fv=e=>1/Math.tan(e*Math.PI/180),hv=.05,bv=.001;function gv(e,t,r){if(!Number.isFinite(e)||!Number.isFinite(t))return NaN;if(!(Math.abs(e)<bv&&Math.abs(t)<bv))return e>0&&t>0?100*(fv(t)-fv(e))/r:NaN}function KL(e,t){let r=ar(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=[hv,-hv].map(l=>{let{inner:u,outer:m}=a(t("FL",l).deg-n,t("FR",l).deg-o);return gv(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:d,outer:p}=a(l.deg-n,u.deg-o),h=gv(d,p,r);return{steerL:l.deg,steerR:u.deg,inner:d,outer:p,toeDiff:d-p,ackermannPct:h??i(),inside:h===void 0?null:m?"left":"right",converged:l.ok&&u.ok}}}function zf(e,t){let r=e.vehicle.config,n={FL:nt("FL",r),FR:nt("FR",r)},o=t.travel??0,a=KL(e,(i,c)=>{let l=Lt(we(e.ctx[i],o,n[i].sideSign*c));return{deg:l?GL(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 yv=35,xv=55,Bt=e=>e.rackTravel&&e.rackTravel>0?e.rackTravel:yv,Yf=e=>e.rackRatio&&e.rackRatio>0?e.rackRatio:xv;var Wf=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 Rv(e,t,r,n,o){let a=we(e,n,0,void 0,o),s=St(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 h=[l],f=Wf(s);for(let b=1;b<=r;b++){let g=p*(t*b)/r,y=qe(e,s.beta,g,f,o),x=Lt(we(e,n,g,Wf(y),o));if(!x||!y.converged){i++,h.push({...h[h.length-1]});continue}h.push({steer:x.metrics.toe,camber:x.metrics.camber,lift:-(y.points.contactPatch[2]-c),contactPatch:y.points.contactPatch,spinAxis:y.points.spinAxis,yaw:-y.metrics.toe*Math.PI/180}),f=Wf(y)}return h},m=u(1),d=u(-1);return{travelMm:n,unsolved:i,centre:l,positive:m,negative:d}}function HL(e,t){return e.map((r,n)=>{let o=n===0?0:n-1,a=n===e.length-1?e.length-1:n+1,s=t[a]-t[o];if(!(s>0))return{longitudinal:0,lateral:0,vertical:0,yaw:0};let i=Q(G(e[a].contactPatch,e[o].contactPatch),1/s),c=te(le(r.spinAxis,[0,0,1])),l=le([0,0,1],c);return{longitudinal:J(i,c),lateral:J(i,l),vertical:i[2],yaw:(e[a].yaw-e[o].yaw)/s}})}function vv(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:HL(o,t)});return{travelMm:e.travelMm,inner:n(r?e.positive:e.negative),outer:n(r?e.negative:e.positive)}}function zL(e){return e.positive[1].steer-e.centre.steer<0}function YL(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:Yf(e.config),innerJacobian:r.inner.jacobian,outerJacobian:r.outer.jacobian}}function jf(e,t,r=13,n=-40,o=40,a=5,s){let i=gt(e),c=Array.from({length:r+1},(b,g)=>t*g/r),l=Rv(i,t,r,0,s),u=zL(l),m=vv(l,c,u),d=Math.max(2,Math.floor(a)),p=Array.from({length:d},(b,g)=>n+(o-n)*g/(d-1));p.some(b=>Math.abs(b)<1e-9)||p.push(0),p.sort((b,g)=>b-g);let h=l.unsolved,f=p.map(b=>{if(Math.abs(b)<1e-9)return m;let g=Rv(i,t,r,b,s);return h+=g.unsolved,vv(g,c,u)});return{...YL(e,c,m),...kv(l.unsolved),travelSurface:{rackMm:c,rows:f,...kv(h)}}}var kv=e=>e>0?{unsolved:e}:{};function Cr(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 Ul(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 Mv(e,t){let r=e.rows;if(r.length<=1||t<=r[0].travelMm)return{lo:0,hi:0,t:0};let n=r.length-1;if(t>=r[n].travelMm)return{lo:n,hi:n,t:0};let o=0,a=n;for(;a-o>1;){let s=o+a>>1;r[s].travelMm<=t?o=s:a=s}return{lo:o,hi:a,t:(t-r[o].travelMm)/(r[a].travelMm-r[o].travelMm)}}var uo=(e,t,r)=>e+r*(t-e);function Ta(e,t,r,n,o){let a=Cr(e.rackMm,e.rows[n.lo][t][r],o);if(n.lo===n.hi)return a;let s=Cr(e.rackMm,e.rows[n.hi][t][r],o);return uo(a,s,n.t)}function Sv(e,t,r,n){let o=Ul(e.rackMm,e.rows[r.lo][t].jacobian,n);if(r.lo===r.hi)return o;let a=Ul(e.rackMm,e.rows[r.hi][t].jacobian,n);return{longitudinal:uo(o.longitudinal,a.longitudinal,r.t),lateral:uo(o.lateral,a.lateral,r.t),vertical:uo(o.vertical,a.vertical,r.t),yaw:uo(o.yaw,a.yaw,r.t)}}function Pa(e,t,r,n){let o=e.travelSurface;if(!o||o.rackMm.length<2||o.rows.length===0)return La(e,t);let a=Mv(o,r),s=Mv(o,n),i=(p,h,f)=>{let b=o.rows[h.lo][p].steerDeg[f];return h.lo===h.hi?b:uo(b,o.rows[h.hi][p].steerDeg[f],h.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],d=l>c[u];if(l<=c[0])m=o.rackMm[0],d=!1;else if(!d){let p=1;for(;p<c.length-1&&c[p]<l;)p++;let h=p-1,f=c[p]-c[h],b=Math.abs(f)>1e-12?(l-c[h])/f:0;m=uo(o.rackMm[h],o.rackMm[p],b)}return{innerDeg:Ta(o,"inner","steerDeg",a,m),outerDeg:Ta(o,"outer","steerDeg",s,m),innerCamber:Ta(o,"inner","camberDeg",a,m),outerCamber:Ta(o,"outer","camberDeg",s,m),innerLift:Ta(o,"inner","liftMm",a,m),outerLift:Ta(o,"outer","liftMm",s,m),innerJacobian:Sv(o,"inner",a,m),outerJacobian:Sv(o,"outer",s,m),atLock:d}}function La(e,t){let r=e.meanDeg.length-1;return{innerDeg:Cr(e.meanDeg,e.innerDeg,t),outerDeg:Cr(e.meanDeg,e.outerDeg,t),innerCamber:Cr(e.meanDeg,e.innerCamber,t),outerCamber:Cr(e.meanDeg,e.outerCamber,t),innerLift:e.innerLift?Cr(e.meanDeg,e.innerLift,t):0,outerLift:e.outerLift?Cr(e.meanDeg,e.outerLift,t):0,...e.innerJacobian&&e.outerJacobian?{innerJacobian:Ul(e.meanDeg,e.innerJacobian,t),outerJacobian:Ul(e.meanDeg,e.outerJacobian,t)}:{},atLock:r>=0&&t>e.meanDeg[r]}}var WL=()=>({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=Be(e),n){let o=e.steerFront;if(!o?.innerLift||!o.outerLift||o.meanDeg.length<2||Math.abs(t)<1e-12)return WL();let a=Math.abs(t),s=t>0,i=n&&o.travelSurface?Pa(o,a,s?n.FL:n.FR,s?n.FR:n.FL):null,c=i?.innerLift??Cr(o.meanDeg,o.innerLift,a),l=i?.outerLift??Cr(o.meanDeg,o.outerLift,a),u=s?c:l,m=s?l:c,d=.5*(u+m),p=r.rollWheelRateFront,h=r.rollWheelRateRear,f=e.trackFront,b=e.trackRear,g=p*f*f+h*b*b,y=g>0?p*f*(m-u)/g:0,x={FL:u-d+.5*f*y,FR:m-d-.5*f*y,RL:.5*b*y,RR:-.5*b*y};return{lift:{FL:u,FR:m,RL:0,RR:0},travel:x,load:{FL:p*x.FL,FR:p*x.FR,RL:h*x.RL,RR:h*x.RR},rollDeg:y===0?0:-Math.atan(y)*180/Math.PI}}function Uf(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 ri=9.81;function Ea(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?Xr(e,t,r,Pn(e,n,o)):so(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 Xf(e,t,r=0,n=0,o=0){if(!e.aero?.model||t<=0)return!1;let a=Xr(e,t,r,Pn(e,n,o));return a!=null&&(a.clampedRide||a.clampedAttitude)}function mo(e){let t=e.loadFactor===void 0?e.massTotal*ri:e.massTotal*ri*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 Av(e,t=Be(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*wl(t.sprungMass,c,t.rollRateTotal),d=(m*t.frontRollStiffFrac+t.sprungFront*a+l*u)/n,p=(m*(1-t.frontRollStiffFrac)+t.sprungRear*s+l*u)/o;return{cf:d,cr:p}}function qf(e){let{cf:t,cr:r}=Av(e);return t+r>0?t/(t+r):.5}function wv(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 d=u>0?1:-1,p=(d*a-c)*t;d*u>=d*p?(c=d*a,u-=p):(c+=u/t,u=0);let h=(d*s-l)*r;u!==0&&(d*u>=d*h?(l=d*s,u-=h):(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 $e(e,t,r,n=0,o=0,a=0,s,i){return Xl(e,t,r,n,o,a,s,i).loads}function Xl(e,t,r,n=0,o=0,a=0,s,i){let c=mo(e),l=Be(e),u=Il(e,n,r,Pn(e,t,o),l),{cf:m,cr:d}=Av(e,l,u.height),p=m*t*ri,h=d*t*ri,f=e.massTotal*(r*ri)*u.height/e.wheelbase-u.noseLoad,b=Ea(e,n,r,t,o),g=(i??Da(e,a,l,s)).load,y={FL:c.FL-p-f/2+b.FL+g.FL,FR:c.FR+p-f/2+b.FR+g.FR,RL:c.RL-h+f/2+b.RL+g.RL,RR:c.RR+h+f/2+b.RR+g.RR};return wv(y,e.trackFront,e.trackRear)}var Qf=Math.PI/180;function Ql(e,t){let r=8*Qf,n=0,o=0;for(let a=1;a<=90;a++){let s=a*.5,i=Math.abs(e.Fy(s*Qf,t,0));if(i>n&&(n=i,r=s*Qf,o=a),a>o+12&&i<.995*n)break}return{aPeak:r,fyPeak:n}}function Fv(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 oi=.999;function jt(e,t,r,n,o){if(t<=0)return 0;let{aPeak:a,fyPeak:s}=o??Ql(e,t),i=Math.min(Math.abs(r),oi*s),c=n?-1:1,l=(v,R)=>Math.abs(e.forces({Fz:t,kappa:c*v,alpha:R}).Fy),u=.3,m=u,d=l(u,a);if(d<i){let v=0,R=u,M=NaN,A=d;for(let F=0;F<9;F++){let T=.5*(v+R),P=l(T,a);P>=i?(v=T,M=P):(R=T,A=P)}Number.isNaN(M)&&(M=l(0,a)),m=M<i?0:Fv(v,M,R,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 R=0,M=a,A=NaN,F=NaN;for(let T=0;T<5;T++){let P=.5*(R+M),S=l(v,P);S<i?(R=P,A=S):(M=P,F=S)}return Number.isNaN(A)&&(A=l(v,0)),Number.isNaN(F)&&(F=l(v,a)),c*e.forces({Fz:t,kappa:c*v,alpha:Fv(R,A,M,F,i)}).Fx},h=4,f=v=>m*v/h,b=[0],g=1;for(let v=1;v<=h;v++)b.push(p(f(v))),b[v]>b[g]&&(g=v);let[y,x]=g===h?[h-1,h-2]:b[g-1]>=b[g+1]?[g-1,g+1]:[g+1,g-1],k=qL(p,f(g-1),f(Math.min(h,g+1)),f(g),b[g],f(y),b[y],f(x),b[x],jL);return c*Math.max(0,k)}var jL=.01,UL=20,XL=(3-Math.sqrt(5))/2;function qL(e,t,r,n,o,a,s,i,c,l){o=-o,s=-s,c=-c;let u=r-t,m=0;for(let d=0;d<UL;d++){let p=l*Math.abs(n)+1e-10,h=.5*(t+r);if(Math.abs(n-h)<=2*p-.5*(r-t))break;let f=!0;if(Math.abs(u)>p){let y=(n-a)*(o-c),x=(n-i)*(o-s),k=(n-i)*x-(n-a)*y;x=2*(x-y),x>0&&(k=-k),x=Math.abs(x);let v=u;if(u=m,Math.abs(k)<Math.abs(.5*x*v)&&k>x*(t-n)&&k<x*(r-n)){m=k/x;let R=n+m;(R-t<2*p||r-R<2*p)&&(m=h>=n?p:-p),f=!1}}f&&(u=n>=h?t-n:r-n,m=XL*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 eh(e,t,r){if(!(r<1))return 0;let n=Math.max(0,r);return Lv(o=>Math.hypot(o,n)/e.reach(t,o,n)-1)}function Pv(e,t,r){let n=Math.max(0,r);return Lv(o=>Math.hypot(n,o)/e.reach(t,n,o)-1)}function Lv(e){let t=0,r=1,n=e(t),o=e(r);if(!(n<0))return 0;if(!(o>0))return 1;let a=0;for(let s=0;s<60;s++){let i=(t*o-r*n)/(o-n),c=e(i);if(Math.abs(c)<1e-12||r-t<1e-12)return i;c>0?(r=i,o=c,a===-1&&(n/=2),a=-1):(t=i,n=c,a===1&&(o/=2),a=1)}return t-n*(r-t)/(o-n)}function th(e,t){return e.model?.kind==="simple"?null:Dv(e,t)}var Cv=new WeakMap,Zf=100,Tv=1.35,Jf=18,Tr=41,ql=41,ni=65;function Dv(e,t){let r=Cv.get(e);if(r)return r;let n=Math.log(Tv),o=(p,h)=>{let f=M=>Math.abs(jt(e,p,M,h)),b=f(0),g=t.muY(p)*p,y=new Float64Array(Tr),x=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<ql;T++){let P=Math.sin(.5*Math.PI*T/(ql-1));M.push(P),A.push(T===0?1:T===ql-1?0:Math.min(A[T-1],f(P*g)/b))}let F=ql-1;for(let T=0;T<Tr;T++){let P=T/(Tr-1);for(;F>0&&A[F-1]<P;)F--;let S=F>0?A[F-1]-A[F]:0;y[T]=F===0?M[0]:M[F]+(S>0?(P-A[F])/S:0)*(M[F-1]-M[F])}y[0]=1,y[Tr-1]=0}let k=new Float64Array(ni),v=M=>Math.atan2(y[M],M/(Tr-1)/x),R=Tr-2;for(let M=0;M<ni;M++){let A=.5*Math.PI*M/(ni-1),F=Math.cos(A),T=Math.sin(A);for(;R>0&&v(R)<A;)R--;let P=R/(Tr-1)/x,S=y[R],w=(R+1)/(Tr-1)/x,C=y[R+1],L=F*(C-S)-T*(w-P),E=Math.abs(L)>1e-12?(P*(C-S)-S*(w-P))/L:Math.hypot(P,S);k[M]=E>0?E:Math.hypot(P,S)}return{room:y,scale:x,edge:k}},a=Array.from({length:Jf},(p,h)=>Zf*Tv**h),s=a.map(p=>o(p,!1)),i=a.map(p=>o(p,!0)),c=(p,h)=>{let f=Math.min(1,Math.abs(h)*p.scale)*(Tr-1),b=Math.min(Tr-2,Math.floor(f));return p.room[b]+(f-b)*(p.room[b+1]-p.room[b])},l=p=>{let h=p>Zf?Math.log(p/Zf)/n:0;if(h>=Jf-1)return[Jf-2,1];let f=Math.floor(h);return[f,h-f]},u=(p,h,f)=>{if(f===0)return 1;let b=f<0?i:s,g=c(b[p],f);return h>0?g+h*(c(b[p+1],f)-g):g},m=(p,h,f)=>{let b=h<0?i:s,[g,y]=l(p),x=Math.atan2(Math.abs(f),Math.abs(h))/(.5*Math.PI)*(ni-1),k=Math.min(ni-2,Math.floor(x)),v=M=>M.edge[k]+(x-k)*(M.edge[k+1]-M.edge[k]),R=v(b[g]);return y>0?R+y*(v(b[g+1])-R):R},d={keeps(p,h){if(h===0)return 1;let[f,b]=l(p);return u(f,b,h)},atLoad(p){let[h,f]=l(p);return b=>u(h,f,b)},use(p,h,f){let b=Math.hypot(h,f);return b>0?Math.min(1,b/m(p,h,f)):0},reach:m};return Cv.set(e,d),d}var QL=[["front","FL","FR"],["rear","RL","RR"]];function Ia(e,t,r,n){let o={...e},a=0,s=oi;for(let[i,c,l]of QL){let u=(k,v)=>n(i,Math.max(0,v[k])).fyPeak,m=Math.min(s,e[c]),d=Math.min(s,e[l]),p=m*u(c,r)+d*u(l,r);if(!(p>0))continue;let h=u(c,t),f=u(l,t),b=m*h+d*f,g=b>0?p/b:1/0,y=m*g,x=d*g;y<=s?x<=s||(x=s,y=h>0?(p-s*f)/h:1/0):(y=s,x=f>0?(p-s*h)/f:1/0),(!(y<=s)||!(x<=s))&&(a+=Math.max(0,p-s*(h+f)),y=Math.min(s,y),x=Math.min(s,x)),o[c]=y,o[l]=x}return{util:o,short:a}}var Ev=.001,ZL=1e-5,Iv=100;function JL(e,t,r,n){if(!(n>Ev))return r;let o=t,a=Math.abs(r-t)<Iv?t+Math.sign(r-t)*Iv:r;for(let s=0;s<60&&Math.abs(a-o)>ZL;s++){let i=.5*(o+a);e(i)>Ev?a=i:o=i}return o}function Zl(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=JL(e,t,o,e(o));return a!==o&&(n=a),a},edge:()=>n}}function Jl(e,t){let r=n=>{try{return we(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 rh=40;function eu(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 _v=[0,0,0];function eD(e,t){let r=te(G(e.rockerPivotB,e.rockerPivotA)),n=te(G(e.rockerToPushrod,e.pushrodOuter)),o=te(G(e.damperChassis,e.rockerToDamper)),a=Math.abs(J(r,le(G(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(J(r,le(G(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}function tu(e,t,r){if(e.mcpherson)return tD(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 d=te(G(n[m].c,n[m].r)),p=le(G(n[m].r,o),d);a[0][m]=d[0],a[1][m]=d[1],a[2][m]=d[2],a[3][m]=p[0],a[4][m]=p[1],a[5][m]=p[2]}let s=le(G(e.contactPatch,o),t),i=r??_v,c=[-t[0],-t[1],-t[2],-(s[0]+i[0]),-(s[1]+i[1]),-(s[2]+i[2])],l=Ar(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]:eD(e,u[5]),condProxy:l.condProxy,singular:l.singular}}function tD(e,t,r){let n=e.wheelCenter,o=e.damperChassis,a=[{at:e.uprightLower,dir:te(G(e.lcaFront,e.uprightLower))},{at:e.uprightLower,dir:te(G(e.lcaRear,e.uprightLower))},{at:e.tieOuter,dir:te(G(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=le(G(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=le(G(e.contactPatch,n),t),c=r??_v,l=[-t[0],-t[1],-t[2],-(i[0]+c[0]),-(i[1]+c[1]),-(i[2]+c[2])],u=Ar(s,l),m=u.x,d=[m[3],m[4],m[5]],p=te(G(o,e.pushrodOuter)),h=J(d,p),f=Math.hypot(d[0]-h*p[0],d[1]-h*p[1],d[2]-h*p[2]);return{ucaFront:NaN,ucaRear:NaN,lcaFront:m[0],lcaRear:m[1],tieRod:m[2],pushRod:u.singular?NaN:h,damper:u.singular?NaN:h,condProxy:u.condProxy,singular:u.singular,strutSide:u.singular?NaN:f,topMount:d}}function nh(e,t){let r=te(e.spinAxis),n=le(G(e.contactPatch,e.wheelCenter),t),o=J(n,r);return[-o*r[0],-o*r[1],-o*r[2]]}var rD=[0,0,0];function ai(e,t,r,n){let o=e.direct?e.damperChassis:e.rockerToPushrod;if(e.mcpherson)return{...tu(e,r,n),armResidual:0};if(t==="upright")return{...tu(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=te(G(s.front,s.bj)),u=te(G(s.rear,s.bj)),m=te(G(e.tieInner,e.tieOuter)),d=[{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 H=0;H<6;H++){let W=d[H].dir,X=le(G(d[H].at,c),W);p[0][H]=W[0],p[1][H]=W[1],p[2][H]=W[2],p[3][H]=X[0],p[4][H]=X[1],p[5][H]=X[2]}let h=le(G(e.contactPatch,c),r),f=n??rD,b=[-r[0],-r[1],-r[2],-(h[0]+f[0]),-(h[1]+f[1]),-(h[2]+f[2])],g=Ar(p,b),y=g.singular,x=g.x,k=x[0],v=x[1],R=x[2],M=[x[3],x[4],x[5]],A=te(G(i.rear,i.front)),F=te(G(o,e.pushrodOuter)),T=Q(M,-1),P=(H,W)=>J(A,le(G(H,i.front),W)),S=P(e.pushrodOuter,F),w=Math.abs(S)>1e-9?-P(i.bj,T)/S:NaN,C=oe(T,Q(F,w)),L=Q(C,-1),E=te(G(i.front,i.bj)),_=te(G(i.rear,i.bj)),O=J(E,E),I=J(E,_),z=J(_,_),B=J(E,L),V=J(_,L),j=O*z-I*I,q=NaN,K=NaN,D=NaN;if(Math.abs(j)>1e-12){q=(B*z-V*I)/j,K=(O*V-I*B)/j;let H=oe(Q(E,q),Q(_,K)),W=G(L,H);D=Math.hypot(W[0],W[1],W[2])}let N=a?{f:k,r:v}:{f:q,r:K},Y=a?{f:q,r:K}:{f:k,r:v};return{ucaFront:N.f,ucaRear:N.r,lcaFront:Y.f,lcaRear:Y.r,tieRod:R,pushRod:w,damper:y||!Number.isFinite(w)||e.decoupled?NaN:e.direct?w:nD(e,w),condProxy:g.condProxy,singular:y,armResidual:D}}function nD(e,t){let r=te(G(e.rockerPivotB,e.rockerPivotA)),n=te(G(e.rockerToPushrod,e.pushrodOuter)),o=te(G(e.damperChassis,e.rockerToDamper)),a=Math.abs(J(r,le(G(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(J(r,le(G(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}var uz=Math.PI/180;function si(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 Ov=["QSX3","QSX8","QSX13","QSX14"],oD=["QSX1"],ru=["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",...Ov];function aD(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 sD(e){let t=new Set(aD(e)),r=ru.filter(n=>!Ov.includes(n));return[...r.filter(n=>!t.has(n)),...[...t].filter(n=>!r.includes(n)),...oD]}function iD(e,t){let r={...e};for(let n of t)r[n]!==void 0&&r[n]!==0&&(r[n]=-r[n]);return r}var Zr=(e,t,r)=>Number.isFinite(e[t])?e[t]:r;function Vv(e,t){return t!=="5.2"?Zr(e,"PKY6",0)*Zr(e,"LKYC",1):Zr(e,"PKY1",-15)*Math.sin(Zr(e,"PKY4",2)*Math.atan(1/Zr(e,"PKY2",2)))*Zr(e,"LKY",1)*Zr(e,"PHY3",0)+Zr(e,"PVY3",0)*Zr(e,"LMUY",1)}var Nv=.1;function Bv(e){if(e.fitData)return"sae";let t=Vv(e.coeffs,e.version);return t>Nv?"sae":t<-Nv?"iso":null}function ii(e){return e.axisSystem??Bv(e)??"sae"}function nu(e){let t=new Set,r=n=>{for(let o of n)t.has(o)?t.delete(o):t.add(o)};return ii(e)==="iso"&&r(ru),e.axisSystem&&e.side==="left"&&r(sD(e.version)),t.size?iD(e.coeffs,t):e.coeffs}var pz=Math.PI/180;var $=(e,t)=>Number.isFinite(e)?e:t;function Gv(e){let t=nu(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 $v=new WeakMap;function ci(e){let t=$v.get(e);return t===void 0&&(t=Gv(e),$v.set(e,t)),t}var Kv=e=>e>=0?1:-1;function ou(e,t,r=0,n){let o=ci(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,d=o.PCY1*o.LCY,p=m*a,h=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,f=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(h)>1e-6?h:1e-6*(h<0?-1:1),x=f?(o.PHY1+o.PHY2*c)*o.LHY+(b*s-g)/y:(o.PHY1+o.PHY2*c)*o.LHY+o.PHY3*s,k=f?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=d*p!==0?h/(d*p):0;return{Fz:a,g:s,dfz:c,dpi:l,Fz0p:i,R0:u,Cy:d,Dy:p,By:v,SHy:x,SVy:k,Kya:h,muy:m,EyA:o.PEY1+o.PEY2*c,EyG:1+o.PEY5*s*s,EyS:o.PEY3+o.PEY4*s,LEY:o.LEY}}function au(e,t,r=0,n){let o=ou(e,t,r,n),a=ci(e),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:m,muy:d,Kya:p,SVy:h,By:f,Cy:b,Dy:g,SHy:y}=o,x=(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,R=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*R!==0?M/(v*R):0,F=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 w=a.REY1+a.REY2*c;return w>1&&(w=1),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:m,Cy:b,Dy:g,By:f,SHy:y,SVy:h,Kya:p,muy:d,EyA:o.EyA,EyG:o.EyG,EyS:o.EyS,LEY:o.LEY,SHx:x,Cx:v,Dx:R,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:w,DVykA:d*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*f*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?h/p:0,sixOne:T,kk:M/F*(M/F),sS0:m*(a.SSZ1+(a.SSZ3+a.SSZ4*c)*i)*a.LS,sS2:m*a.SSZ2*a.LS/u}}function li(e,t){let r=t+e.SHy,n=e.EyA*(e.EyG-e.EyS*Kv(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 su(e,t){let r=t+e.SHx,n=e.ExA*(1-e.PEX4*Kv(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 Hv(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 cD(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=Hv(e,o,r),i=e.Bt*s;return e.Dt*Math.cos(e.Ct*Math.atan(i-a*(i-Math.atan(i))))*n}function lD(e,t,r,n){return e.Dr*Math.cos(Math.atan(e.Br*Hv(e,t+e.SHy+e.arOff,r)))*n}function zv(e,t,r,n,o,a){let s=Math.cos(t),i=cD(e,t,r,s),c=lD(e,t,r,s);return-i*(o-a)+c+(e.sS0+e.sS2*o)*n}function Yv(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*su(e,t)}function oh(e,t){let r=e.sS0===0&&e.sS2===0?0:Yv(e,0,t);return zv(e,t,0,r,li(e,t),0)}function iu(e,t,r){let n=li(e,r),o=Yv(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:zv(e,r,t,o,m,u)}}var ui=(e,t)=>Math.max(.1,e.muY0+e.loadSensY*(t-e.nominalLoad)),mi=(e,t)=>Math.max(.1,e.muX0+e.loadSensX*(t-e.nominalLoad)),Wv=(e,t,r)=>ui(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cy*Math.atan(e.By*r)),jv=(e,t,r)=>mi(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cx*Math.atan(e.Bx*r));function ah(e,t){let r=Math.max(1,t.Fz),n=ui(e,r)*r,o=mi(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 _a=Math.PI/180;function Nn(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 Uv(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?si(r,t):1,s=n?si(n,t):1,i=o?si(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 Na(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 _e(e){let t=Uv(e),r=t,n=t,o=null,a=NaN,s=NaN,i=NaN,c=(v,R,M)=>(o!==null&&v===a&&R===s&&M===i||(o=au(r,v,R,M),a=v,s=R,i=M),o),l=null,u=NaN,m=NaN,d=NaN,p=(v,R,M)=>(l!==null&&v===u&&R===m&&M===d||(l=ou(r,v,R,M),u=v,m=R,d=M),l),h=v=>e.kind==="magic"?iu(c(v.Fz,v.gamma??0,v.p),v.kappa,v.alpha):ah(n,v),f=(v,R,M=0,A)=>e.kind==="magic"?li(p(R,M,A),v):Wv(n,R,v),b=(v,R,M=0,A)=>e.kind==="magic"?su(c(R,M,A),v):jv(n,R,v),g=(v,R,M=0,A)=>e.kind==="magic"?oh(c(R,M,A),v):h({Fz:R,kappa:0,alpha:v,gamma:M,p:A}).Mz,y=v=>e.kind==="simple"?ui(n,v):Na(R=>f(R*_a,v),45,1)/Math.max(1,v),x=v=>e.kind==="simple"?mi(n,v):Na(R=>b(R,v),.6,.02)/Math.max(1,v),k=v=>{let R=.1*_a;return Math.abs((f(R,v)-f(-R,v))/(2*R))};return{model:e,forces:h,Fx:b,Fy:f,Mz:g,muX:x,muY:y,corneringStiffness:k,verticalStiffness:()=>e.verticalStiffness,rollingRadius:v=>{if(e.kind==="magic"&&e.missing?.includes("UNLOADED_RADIUS"))return 0;let R=e.unloadedR0??0;if(!(R>0))return 0;let M=e.verticalStiffness*1e3;if(!(M>0))return R;let A=e.rollingFraction??.306;return R-A*Math.max(0,v)/M},relaxationLength:v=>{let R=e.relaxation;if(!R)return 0;let M=R.carcassStiffness??0;if(!(M>0))return R.sigma;let A=k(Math.max(0,v));return A>0?A/(M*1e3):R.sigma}}}function Oa(e){let t=Math.max(1,e.model.kind==="magic"?e.model.fnomin:e.model.nominalLoad);return e.Fy(2*_a,t,0)-e.Fy(-2*_a,t,0)>=0?1:-1}function pi(e,t=e.kind==="magic"?e.fnomin:e.nominalLoad){let r=_e(e),n=2*_a,o=3*_a,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 uD=Math.PI/180;function Fe(e,t){return e.axle?e.axle(t):e}function lu(e,t){if(e===t)return e;let r=Oa(e)*Oa(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,d)=>n(e.Fx(l,u,m,d),t.Fx(l,u,m,d)),i=(l,u,m=0,d)=>n(e.Fy(l,u,m,d),r*t.Fy(l,u,m,d)),c=(l,u,m=0,d)=>n(e.Mz(l,u,m,d),r*t.Mz(l,u,m,d));return{model:e.model,forces:a,Fx:s,Fy:i,Mz:c,muX:l=>Na(u=>s(u,l),.6,.02)/Math.max(1,l),muY:l=>Na(u=>i(u*uD,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 Dt(e){if(Xv.has(e))return e;let t=qv.get(e);if(t)return t;let r;if(e.axle){let n=e.axle("front"),o=e.axle("rear"),a=Dt(n),s=Dt(o);r=a===n&&s===o?e:lu(a,s)}else Oa(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 Xv.add(r),r!==e&&qv.set(e,r),r}var Xv=new WeakSet,qv=new WeakMap;var uu=25*(Math.PI/180);function mD(e){let t=.6180339887,r=0,n=uu,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 di(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=uu;if(s(uu)<=a){let u=mD(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(uu,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),d=s(m)-a;if(d<0?i=m:c=m,Math.abs(d)<=l)return m}return c}var sh={shaft:!1,trail:0,hub:[0,0,0]};function Zv(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 ih(e,t,r){let n=r.shaft?nh(e,t):[0,0,0];if(r.trail!==0){let a=Zv(e),s=[t[0],t[1],0],i=G(s,Q(a,J(s,a)));n=oe(n,le(Q(a,-r.trail),i))}let o=r.hub;return(o[0]!==0||o[1]!==0||o[2]!==0)&&(n=G(n,le(G(e.contactPatch,e.wheelCenter),o))),{force:oe(t,o),moment:n}}var pD=(e,t)=>{let r=e!==void 0&&e>0?1/e:0,n=t!==void 0&&t>0?1/t:0;return r+n},mu={ucaFront:0,ucaRear:0,lcaFront:0,lcaRear:0,tieRod:0,pushRod:0,rack:0};function po(e){return!e.measured}function fo(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 fi(e,t){let r=e.corner.hardpoints,n=va(e.rocker,t.points.rockerAngle);return{ucaFront:r.ucaFront,ucaRear:r.ucaRear,lcaFront:r.lcaFront,lcaRear:r.lcaRear,tieInner:io(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 ch(e,t,r=0){let n=t.links??{},o=t.bushings??{},a=(l,u,m)=>{let d=pD(u,m);return d>0&&Number.isFinite(l)?l*d: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 Jv(e,t,r,n){let o=Ee(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 hi(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:oe(n.strut.top,t.topMount)}),t.ucaFront!==0||t.ucaRear!==0){let i=Jv(r.ucaFront,r.ucaRear,Ee(r.uprightUpper,r.ucaFront)+t.ucaFront,Ee(r.uprightUpper,r.ucaRear)+t.ucaRear);o.ubjAxial0=i.axial,o.ubjRadius2=i.radius2}if(t.lcaFront!==0||t.lcaRear!==0){let i=Jv(r.lcaFront,r.lcaRear,Ee(r.uprightLower,r.lcaFront)+t.lcaFront,Ee(r.uprightLower,r.lcaRear)+t.lcaRear),c=J(n.lbjRel0,n.lcaDir),l=G(n.lbjRel0,Q(n.lcaDir,c)),u=Math.hypot(l[0],l[1],l[2]);o.lbjRel0=u>1e-9?oe(Q(n.lcaDir,i.axial),Q(l,Math.sqrt(i.radius2)/u)):oe(Q(n.lcaDir,i.axial),l)}if(t.tieRod!==0){let i=Math.sqrt(n.tieLen2)+t.tieRod;o.tieLen2=i*i}if(t.rack!==0&&(o.tieInner0=oe(n.tieInner0,Q(n.rackAxis,t.rack))),t.pushRod===0)return{corner:e.corner,inv:o,rocker:e.rocker};let a=Math.sqrt(e.rocker.rodLen2)+t.pushRod,s={...e.rocker,rodLen2:a*a};return{corner:e.corner,inv:o,rocker:s}}var dD=8,fD=1e-5,hD=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 lh(e,t,r){let n=ih(e,r.force,r.extras??sh),o=r.alignMoment?oe(n.moment,[0,0,r.alignMoment]):n.moment;return ai(e,t,n.force,o)}function du(e,t,r,n,o,a,s=0){let i=qe(e,t,r,o,a),c=e.corner.compliance;if(!(fo(c)&&po(e.corner)))return{state:i,forces:lh(fi(e,i),e.corner.config.pushrodAttach,n),deflection:mu,rigid:i,iterations:0,converged:!0,bypassed:!0};let u=i,m=e,d=e.corner.config.pushrodAttach,p=lh(fi(e,i),d,n),h=mu,f=!1,b=0;for(;b<dD;b++){let g=fi(m,u);if(p=lh(g,d,n),p.singular)break;h=ch(p,c,s),m=hi(e,h);let y=qe(m,t,r,hD(u),a),x=Ee(y.points.wheelCenter,u.points.wheelCenter);if(u=y,x<fD){f=!0;break}}return{state:u,forces:p,deflection:h,rigid:i,iterations:b+1,converged:f&&u.converged,bypassed:!1}}var pu=1e3,e1=1e5;function t1(e,t,r,n,o){let a=du(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 fu(e,t,r,n,o){let a={force:[0,0,n]},s=(b,g=0)=>t1(e,t,r,{force:b,alignMoment:g},o),i=t1(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,pu,n]),l=s([0,-pu,n]),u=s([pu,0,n]),m=s([-pu,0,n]),d=s([0,0,n],e1),p=s([0,0,n],-e1),h=(b,g)=>(b-g)/2,f=[i,c,l,u,m,d,p].every(b=>b.converged);return{toePerLateral:h(c.toe,l.toe),camberPerLateral:h(c.camber,l.camber),toePerLongitudinal:h(u.toe,m.toe),camberPerLongitudinal:h(u.camber,m.camber),toePerAligning:h(d.toe,p.toe),lateralPatch:h(c.patch[1],l.patch[1]),longitudinalPatch:h(u.patch[0],m.patch[0]),bypassed:!1,converged:f}}var bD=1e3;function uh(e,t=bD){if(!fo(e.compliance)||!po(e))return;let r=gt(e),n=qe(r,0,0),o=fu(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 Va(e,t=-rh,r=rh,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=ot(e,{travelMin:t,travelMax:r,steps:n}),s=uh(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 hu(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 On(e,t){return{motionRatio:hu(e.travel,e.motionRatio,t),camber:hu(e.travel,e.camber,t),toe:hu(e.travel,e.toe,t),damperLen:hu(e.travel,e.damperLen,t)}}var r1=Math.PI/180,gD=9.81;function Vn(e,t,r,n=0){let o=Be(e),a=e.wheelbase*(1-e.frontMassFrac),s=e.wheelbase*e.frontMassFrac,i=Ea(e,n),c=e.aero?.model?(k,v,R)=>Ea(e,n,v,k,R):()=>i,l=On(t,0),u=On(r,0),m=e.loadFactor,d=m!==void 0&&m!==1?(m-1)*e.massTotal*gD:0,p=d*e.frontMassFrac/2,h=d*(1-e.frontMassFrac)/2,f=(k,v)=>v>0&&Number.isFinite(v)&&k+v>0?v/(k+v):1,b=lt(e,"front"),g=lt(e,"rear"),y={F:f(e.wheelRateFront+(e.heaveSpringFront??0),b),R:f(e.wheelRateRear+(e.heaveSpringRear??0),g)},x={F:f(e.wheelRateFront+e.arbFront,b),R:f(e.wheelRateRear+e.arbRear,g)};return(k,v,R=0,M=0)=>{let A=c(k,v,R),F=o.rollGradient*k,T=F*r1,P=o.pitchGradient*v*r1,S=(O,I)=>{let z=I==="F"?e.trackFront:e.trackRear,B=I==="F"?o.rideRateFront:o.rideRateRear,V=(O==="R"?1:-1)*(z/2)*Math.tan(T),j=(I==="R"?s:-a)*Math.tan(P),q=`${I}${O}`,K=d?A[q]+(I==="F"?p:h):A[q],D=B>0?K/B:0;return{anti:V,sym:j+D}},w={FL:S("L","F"),FR:S("R","F"),RL:S("L","R"),RR:S("R","R")},C=O=>{let I=O[0];return w[O].sym*y[I]+w[O].anti*x[I]},L=Da(e,M,o,{FL:C("FL"),FR:C("FR")}),E=F+L.rollDeg,_=(O,I)=>{let z=I==="F"?t:r,B=I==="F"?l:u,V=`${I==="F"?"F":"R"}${O}`,j=w[V].sym+w[V].anti+L.travel[V],q=C(V)+L.travel[V]*x[I],K=j-q,D=On(z,q),N=(O==="R"?1:-1)*D.camber;return{travel:q,tyre:K,ground:j,camber:N,camberRoad:N+E,toe:D.toe,bumpToe:D.toe-B.toe,damperTravel:B.damperLen-D.damperLen}};return{FL:_("L","F"),FR:_("R","F"),RL:_("L","R"),RR:_("R","R"),steeringJacking:L}}}var mh=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function ho(e){return{enabled:e?.enabled===!0,roadFeedbackGain:Math.min(2,Math.max(0,mh(e?.roadFeedbackGain,1))),turnInFrictionNm:Math.max(0,mh(e?.turnInFrictionNm,0)),columnStiffnessNmPerRad:Math.max(0,mh(e?.columnStiffnessNmPerRad,0))}}function ph(e,t,r){let n=ho(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 n1=()=>({totalNm:0,aligningNm:0,lateralNm:0,longitudinalNm:0,jackingNm:0});function bo(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 bi(e,t,r,n="model",o){let a=e.steerFront;if(!bo(e)||!a)return null;let s=t<0?-1:1,c=a.rackRatioMmPerRev/(2*Math.PI)/1e3,l=t>=0,u=o&&a.travelSurface?Pa(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],x=b==="FL"?-1:1,k=-x*y.Fy,R={aligning:1e3*(-x*y.Mz)*g.yaw,lateral:k*g.lateral,longitudinal:y.Fx*g.longitudinal,jacking:y.Fz*g.vertical},M=n1();M.aligningNm=-s*R.aligning*c,M.lateralNm=-s*R.lateral*c,M.longitudinalNm=-s*R.longitudinal*c,M.jackingNm=-s*R.jacking*c,M.totalNm=M.aligningNm+M.lateralNm+M.longitudinalNm+M.jackingNm;let A=-s*(R.aligning+R.lateral+R.longitudinal+R.jacking);return{moment:M,rackN:A}},d=m("FL",l?u.innerJacobian:u.outerJacobian),p=m("FR",l?u.outerJacobian:u.innerJacobian),h=n1();for(let b of[d.moment,p.moment])h.aligningNm+=b.aligningNm,h.lateralNm+=b.lateralNm,h.longitudinalNm+=b.longitudinalNm,h.jackingNm+=b.jackingNm,h.totalNm+=b.totalNm;let f=ph(h.totalNm,t,e.steeringSystem);return h.totalNm=f.driverNm,{...h,roadNm:f.roadNm,assistanceNm:f.assistanceNm,frictionNm:f.frictionNm,columnTwistDeg:f.columnTwistDeg,rackForceN:d.rackN+p.rackN,aligningSource:n,perWheel:{FL:d.moment,FR:p.moment}}}var yD=e=>"front"in e&&"rear"in e;function Ba(e,t){return yD(e)?e[t]:e}function fh(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)),d=(u-a[m])/o;return l[m]+d*(l[m+1]-l[m])};return{muX:l=>c(s,l),muY:l=>c(i,l)}}function dh(e,t){let r=Math.max(0,t.Fz);return a1(e.muX(r)*r,e.muY(r)*r,t)}function a1(e,t,r){if(!(t>0))return{fyUsed:0,fyMax:0,fyRes:0};let n=e>0?Math.min(1,Math.abs(r.Fx)/e):0,o=t*Math.sqrt(Math.max(0,1-n*n)),a=Math.abs(r.Fy);return{fyUsed:a,fyMax:o,fyRes:Math.max(0,o-a)}}function o1(e,t,r){let n=dh(e,t),o=dh(e,r);return{left:n,right:o,fyRes:n.fyRes+o.fyRes}}function Jr(e,t,r){let n=o1(Ba(e,"front"),t.FL,t.FR),o=o1(Ba(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 gi=[{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"}],RD=gi.flatMap(e=>[e.min,e.max]);function vD(e){let t={};for(let r of gi){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 bu(e){if(e.kind==="magic")return e.range??vD(e.coeffs)}function hh(e){return Math.max(1,e.kind==="magic"?e.fnomin:e.nominalLoad)}function s1(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 fr(e){let t=i1.get(e);if(t!==void 0)return t;let r=10*hh(e.model),{turnover:n,collapse:o}=MD(e,r),a=n??o??r;return i1.set(e,a),a}var i1=new WeakMap;function MD(e,t){let r=hh(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 d=o(m*s);if(d<c){i=s1(o,(m-2)*s,m*s,20,(p,h)=>p>h);break}c=d}let l=null,u=n(s);for(let m=2;m<=a;m++){let d=n(m*s);if(d>u){let p=s1(n,(m-2)*s,m*s,40,(h,f)=>h<f);n(p)<.05*n(r)&&(l=p);break}u=d}return{turnover:i,collapse:l}}var c1=.1;function gu(e,t=hh(e)){let r=_e(e).muX(t);return{muX:r,none:Number.isFinite(r)&&r<c1}}var l1=["FL","FR","RL","RR"],SD=e=>e==="FL"||e==="RL",AD=e=>e==="FL"||e==="FR"?"front":"rear";function yu(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 l1)a[l]={...t[l]};let s=l=>{let u=0;for(let d of l1)AD(d)===e.axle&&(a[d].Fx=e.sense*(d===e.strong?l-e.open/2:e.open/2),u-=(SD(d)?o:-o)*a[d].Fx);let m=Jr(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 wD=[["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]],FD=[["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]],CD=[["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]],TD=[["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]],PD=[["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]],m1=[["lateral",wD],["longitudinal",FD],["aligning",CD],["combined",TD],["scaling",PD]].flatMap(([e,t])=>t.map(([r,n,o])=>({key:r,section:e,text:n,fallback:o}))),h6=new Map(m1.map(e=>[e.key,e]));var LD=/^\$\s*EDITED\s+([A-Z][A-Z0-9_]*)\s+was\s+(absent|[-+0-9.eE]+)\s*$/;function p1(e){let t={};for(let r of e.split(/\r?\n/)){let n=r.trim().match(LD);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 ED=/^\s*\$\s*UNLOADED_RADIUS_STAND_IN\s*=\s*([0-9.eE+-]+)/,ID=/^\$-+ written by (?:PaceDynamics|PaceLab)\b/m,_D=/^\$\s*AXIS_SYSTEM\s*=\s*(ISO-W|SAE)\b/m;function ND(e){let t=e.match(_D);return t?{axisSystem:t[1]==="SAE"?"sae":"iso",trustSide:!0}:ID.test(e)?{axisSystem:"sae",trustSide:!1}:{axisSystem:"iso",trustSide:!0}}function OD(e){return e>=62?"6.2":e>=61?"6.1":"5.2"}var d1=new Map([["pa",1],["pascal",1],["kpa",1e3],["kilopascal",1e3],["mpa",1e6],["megapascal",1e6],["bar",1e5],["psi",6894.757293168]]);function VD(e,t,r){let n=r.PRESSURE?.trim().toLowerCase(),o=n===void 0?1:d1.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 BD=new Map([["radians",1],["radian",1],["rad",1],["degrees",Math.PI/180],["degree",Math.PI/180],["deg",Math.PI/180]]);function $D(e,t){let r=(s,i)=>s===void 0?1:i.get(s.trim().toLowerCase()),n=r(t.ANGLE,BD),o={fz:1,kappa:1,alpha:n,gamma:n,p:r(t.PRESSURE,d1)},a={};for(let s of gi){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 yi(e,t="imported",r={}){let n=ND(e),o=r.axisSystem??n.axisSystem,a={},s={},i={},c="",l;for(let g of e.split(/\r?\n/)){let y=g.match(ED);y&&(l=parseFloat(y[1]));let x=g.replace(/[$!].*$/,"").trim();if(!x)continue;if(x.startsWith("[")){c=(x.match(/^\[([^\]]*)/)?.[1]??"").trim().toUpperCase();continue}let k=x.indexOf("=");if(k<0)continue;let v=x.slice(0,k).trim().toUpperCase(),R=x.slice(k+1).trim(),M=R.match(/^'([^']*)'|^"([^"]*)"/);if(M){s[v]=M[1]??M[2]??"",c==="UNITS"&&(i[v]=s[v]);continue}let A=parseFloat(R);Number.isFinite(A)&&(a[v]=A)}let u=OD(a.FITTYP??62),m=p1(e),d=m?Object.fromEntries(Object.entries(m).filter(([g])=>a[g]!==void 0)):void 0,p=a.VERTICAL_STIFFNESS??a.KZ??0,h=VD(a,s,i),f=$D(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"),h===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:h??0,missing:b,...d&&Object.keys(d).length?{edited:d}:{},...f?{range:f}:{}}}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 xu(e){if(!e)return null;let t=e.sectionWidth;return t!==void 0&&t>0?t:null}var M6=Math.PI/180;var C6=Math.PI/180,T6=180/Math.PI;function xi(){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 b1=`$ AXIS_SYSTEM = SAE (authored in the evaluation frame: y right)
|
|
3
3
|
[MODEL]
|
|
4
4
|
FITTYP = 62
|
|
5
5
|
[DIMENSION]
|
|
@@ -108,7 +108,7 @@ QHZ1 = 0
|
|
|
108
108
|
QHZ2 = 0
|
|
109
109
|
QHZ3 = 0
|
|
110
110
|
QHZ4 = 0
|
|
111
|
-
`;function
|
|
111
|
+
`;function bh(){return yi(b1,"Example MF6.2")}var KD=Math.PI/180,g1=2,y1=2;function x1(e){let t=Math.sin(y1*Math.atan(1/g1)),r=-e.corneringStiffness/(e.Fz0*t),n=e.camberStiffness/KD/e.Fz0,o=(a,s=5)=>Number(a.toFixed(s)).toString();return`$ AXIS_SYSTEM = SAE (authored in the evaluation frame: y right, +inclination gives +Fy)
|
|
112
112
|
[MODEL]
|
|
113
113
|
FITTYP = 62
|
|
114
114
|
[DIMENSION]
|
|
@@ -170,9 +170,9 @@ PEY3 = 0.1
|
|
|
170
170
|
PEY4 = -4
|
|
171
171
|
PEY5 = 0
|
|
172
172
|
PKY1 = ${o(r)}
|
|
173
|
-
PKY2 = ${o(
|
|
173
|
+
PKY2 = ${o(g1)}
|
|
174
174
|
PKY3 = 0.8
|
|
175
|
-
PKY4 = ${o(
|
|
175
|
+
PKY4 = ${o(y1)}
|
|
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 en(e){let t=gi(g1(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 y1={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},x1={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},R1={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},v1={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},k1={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},M1={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},S1={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},A1={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},hh=()=>en(y1),bh=()=>en(x1),gh=()=>en(R1),yh=()=>en(v1),xh=()=>en(k1),Rh=()=>en(M1),vh=()=>en(S1),kh=()=>en(A1);var w1=e=>Number.isFinite(e)&&e>0;function Ru(e,t){let r=w1(t.grip)?t.grip:1,n=w1(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 xi={ok:!0,violation:0},go=1e7;function tn(e,t){let r;try{r=e.build(t)}catch(s){return{total:go*2,feasible:!1,terms:[],reason:`build failed: ${String(s)}`}}let n=e.feasible(r);if(!n.ok)return{total:go+Math.max(0,n.violation),feasible:!1,terms:[],reason:n.reason};let o;try{o=e.terms(r)}catch(s){return{total:go*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:go*2,feasible:!1,terms:o,reason:"objective was not finite"}}var Ri=(e,t)=>!t||(e.feasible!==t.feasible?e.feasible:e.total<t.total);function Mh(e,t){return t.map((r,n)=>Math.min(e[n].hi,Math.max(e[n].lo,r)))}var rn=e=>e.map(t=>t.start);function vu(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 GD(e){let t=0;for(;t===0;)t=e();return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e())}function Sh(e,t){let{budget:r}=t,n=Math.max(1,Math.floor(t.progressEvery??1)),o=e.variables,a=p=>Mh(o,p.map((h,f)=>o[f].lo+h*(o[f].hi-o[f].lo))),s=p=>p.map((h,f)=>(h-o[f].lo)/(o[f].hi-o[f].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 h=p.map(g=>Math.min(1,Math.max(0,g))),f=tn(e,a(h));f.feasible||c++;let b=Ri(f,l)?f:l;return b===f&&(l=f,u=h),m.push(b.total),t.onProgress&&(i%n===0||i===r)&&t.onProgress({evaluations:i,budget:r,x:a(u),score:b,infeasible:c}),f.total},left:()=>r-i,result:p=>({method:p,x:u?a(u):rn(o),score:l??tn(e,rn(o)),evaluations:i,history:m,infeasible:c})}}var Ah=(e,t,r,n=0,o)=>{let a=t?r.norm(rn(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 F1(e,t){let r=Sh(e,t),n=vu(t.seed??1),o=e.variables.length;for(r.evaluate(Ah(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=Sh(e,t),n=e.variables.length,o=vu(t.seed??1),a=1,s=2,i=.5,c=.5,l=Ah(e,t.warmStart!==!1,r,t.startJitter,o),u=.25;for(;r.left()>0;){let m=[{u:l,f:r.evaluate(l)}];for(let d=0;d<n&&r.left()>0;d++){let p=l.slice();p[d]+=p[d]+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 d=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 h=g=>p.map((y,x)=>y+g*(y-d.u[x])),f=h(a),b=r.evaluate(f);if(b<m[0].f){let g=h(s),y=r.evaluate(g);m[n]=y<b?{u:g,f:y}:{u:f,f:b}}else if(b<m[n-1].f)m[n]={u:f,f:b};else{let g=h(-i),y=r.evaluate(g);if(y<d.f)m[n]={u:g,f:y};else{let x=m[0],k=0;for(let v=1;v<=n;v++)for(let R=0;R<n;R++)k=Math.max(k,Math.abs(m[v].u[R]-x.u[R]));if(k<1e-4)break;for(let v=1;v<=n&&r.left()>0;v++){let R=m[v].u.map((M,A)=>x.u[A]+c*(M-x.u[A]));m[v]={u:R,f:r.evaluate(R)}}}}}m.sort((d,p)=>d.f-p.f),l=m[0].u.map(d=>Math.min(1,Math.max(0,d+.05*(o()-.5)))),u=Math.max(.02,u*.5)}return r.result("nelder-mead")}function C1(e,t){let r=Sh(e,t),n=e.variables.length,o=vu(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,d=(4+l/n)/(n+4+2*l/n),p=(n+2)/3,h=Math.min(1,p*2/((n+1.3)**2+l)),f=Math.min(1-h,p*2*(l-2+1/l)/((n+2)**2+l)),b=Math.sqrt(n)*(1-1/(4*n)+1/(21*n*n)),g=Ah(e,t.warmStart!==!1,r,t.startJitter,o),y=.25,x=new Array(n).fill(1),k=new Array(n).fill(0),v=new Array(n).fill(0),R=0;for(;r.left()>0;){R++;let M=[];for(let S=0;S<a&&r.left()>0;S++){let w=[];for(let L=0;L<n;L++)w.push(GD(o));let C=g.map((L,E)=>L+y*x[E]*w[E]);M.push({z:w,u:C,f:r.evaluate(C)})}if(M.length<s)break;M.sort((S,w)=>S.f-w.f);let A=g.slice(),F=new Array(n).fill(0);g=new Array(n).fill(0);for(let S=0;S<s;S++)for(let w=0;w<n;w++)g[w]+=i[S]*M[S].u[w],F[w]+=i[S]*M[S].z[w];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)*F[S];let T=Math.sqrt(k.reduce((S,w)=>S+w*w,0)),P=T/Math.sqrt(1-(1-u)**(2*R))/b<1.4+2/(n+1)?1:0;for(let S=0;S<n;S++){let w=(g[S]-A[S])/(y*x[S]);v[S]=(1-d)*v[S]+P*Math.sqrt(d*(2-d)*l)*w}for(let S=0;S<n;S++){let w=0;for(let E=0;E<s;E++)w+=i[E]*M[E].z[S]*M[E].z[S];let C=x[S]*x[S],L=(1-h-f)*C+h*(v[S]*v[S]+(1-P)*d*(2-d)*C)+f*w*C;x[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 Ba=[{name:"random",run:F1},{name:"nelder-mead",run:Va},{name:"sep-cma-es",run:C1}];var Y6=Math.PI/180;var ku=Math.PI/180;var X6={Fz:100,alpha:.25*ku,kappa:.005,gamma:.5*ku,p:6900},T1={Fz:100,alpha:1*ku,kappa:.02,gamma:.5*ku,p:6900};var P1=Math.PI/180,tY={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:P1},gamma:{rad:1,deg:P1},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 sY=Math.PI/180;var JD=Math.PI/180;var dY=3*JD;var yY=Math.PI/180;var PY=Math.PI/180;var iE={RCX1:1,RCY1:1,REX1:0,REY1:0,RBY3:0,RHX1:0,RHY1:0},E1={RBX1:15,RBX2:15,RBY1:18,RBY2:19,...iE};var GY=Math.PI/180;var pE=Math.PI/180,Mu=[{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"}],r8=new Map(Mu.map(e=>[e.id,e]));var n8=.01*pE;var st=Math.PI/180;var N1=new Set(Mu.filter(e=>e.group!=="inputs"&&(e.unit==="N"||e.unit==="N\xB7m"||e.unit==="N/rad")).map(e=>e.id)),O1={alpha:{from:-15*st,to:15*st,n:61},kappa:{from:-.25,to:.25,n:61},gamma:{from:-6*st,to:6*st,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}},Ph={alpha:{from:0,to:12*st,n:7},kappa:{from:-.2,to:.2,n:9},gamma:{from:-4*st,to:4*st,n:5},Fz:{from:400,to:1600,n:5},p:{from:6e4,to:12e4,n:4},V:{from:5,to:35,n:4}};var Lh={alpha:{from:0,to:12*st,n:25},kappa:{from:-.2,to:.2,n:25},gamma:{from:-4*st,to:4*st,n:17},Fz:{from:300,to:1800,n:16},p:{from:6e4,to:12e4,n:13},V:{from:5,to:35,n:13}};var Ie=(e,t,r,n={},o={})=>({id:e,form:"curves",sweep:[{input:t,...O1[t],...o}],x:t,y:r,...n}),Su=(e,[t,r],n,o,a={})=>({id:e,form:"carpet",sweep:[{input:t,...Ph[t]},{input:r,...Ph[r]}],x:n,y:[o],...a}),nn=(e,t)=>({id:e,fixed:t}),ir={input:"Fz",values:"car"},Th={alpha:0,kappa:0},$t={kappa:0},I1={alpha:0},fE={input:"Fz",values:[500,1e3,1500]},hE=[{id:"overview",name:"Overview",cards:[nn("tyre","tyre"),Ie("fy","alpha",["Fy"],{title:"Lateral force",hold:$t}),Ie("mz","alpha",["Mz"],{title:"Aligning moment",hold:$t}),Ie("fx","kappa",["Fx"],{title:"Longitudinal force",hold:I1}),Su("combined-carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),nn("ellipse","ellipse")]},{id:"lateral",name:"Lateral",cards:[Ie("fy-load","alpha",["Fy"],{title:"Lateral force per wheel load",series:ir,hold:$t}),Ie("muy-load","alpha",["muY"],{title:"Lateral force per unit load",series:ir,hold:$t}),Ie("fy-peak","alpha",["Fy"],{title:"Lateral force over its peak",series:ir,hold:$t,scale:{per:"peak"}},{from:0,to:15*st,n:61}),Ie("muy-peak","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load"}),Ie("calpha","Fz",["Calpha"],{title:"Cornering stiffness over load"}),Ie("alpha-peak","Fz",["alphaPeak"],{title:"Slip angle at the peak over load"})]},{id:"aligning",name:"Aligning",cards:[Ie("mz-load","alpha",["Mz"],{title:"Aligning moment per wheel load",series:ir,hold:$t}),Ie("trail","alpha",["t"],{title:"Pneumatic trail",series:ir,hold:$t},{from:0,to:12*st,n:49}),Ie("mzr","alpha",["Mzr"],{title:"Residual aligning moment",series:ir,hold:$t},{from:0,to:12*st,n:49}),Su("gough",["alpha","Fz"],"Fy","Mz",{title:"Gough plot",hold:$t}),Ie("steering-feel","alpha",["t"],{title:"Steering feel",x:"FyRel",series:ir,hold:$t},{from:0,to:12*st,n:49})]},{id:"longitudinal",name:"Longitudinal",cards:[Ie("fx-load","kappa",["Fx"],{title:"Longitudinal force per wheel load",series:ir,hold:I1}),Ie("mux-peak","Fz",["muXPeak"],{title:"Peak longitudinal \u03BC over load"}),Ie("kx","Fz",["dFxdk"],{title:"Slip stiffness at zero slip over load",hold:Th}),Ie("kappa-peak","Fz",["kappaPeak"],{title:"Slip ratio at the peak over load"})]},{id:"combined",name:"Combined",cards:[Su("carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),Su("envelope-load",["kappa","alpha"],"Fy","Fx",{title:"Friction envelope per load",scale:{per:"Fz"},facet:fE}),Ie("fy-kappa","kappa",["Fy"],{title:"Side force while driving or braking",series:{input:"alpha",values:[2*st,4*st,8*st]}}),Ie("fx-kappa","kappa",["Fx"],{title:"Driving force while cornering",series:{input:"alpha",values:[0,4*st,8*st]}}),nn("ellipse","ellipse")]},{id:"camber",name:"Camber",cards:[Ie("fy-gamma","alpha",["Fy"],{title:"Lateral force per inclination",series:{input:"gamma",values:[-4,-2,0,2,4].map(e=>e*st)},hold:$t}),Ie("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",...Lh.gamma},{input:"Fz",...Lh.Fz,follow:!0}],x:"gamma",y:["Fz"],z:"muYPeak"},Ie("camber-stiffness","alpha",["dFydg"],{title:"Camber stiffness at the point",series:ir,hold:$t}),Ie("mx","alpha",["Mx"],{title:"Overturning moment",series:ir,hold:$t})]},{id:"rolling",name:"Rolling and radius",cards:[Ie("my","V",["My"],{title:"Rolling-resistance moment",series:ir,hold:Th}),Ie("radius","Fz",["R0","Rl","Re"],{title:"Radius over load"},{from:0}),Ie("p-roll","V",["Proll"],{title:"Rolling power",series:ir,hold:Th})]},{id:"transient",name:"Transient",cards:[Ie("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},Ie("delta-fy","alpha",["Fy"],{title:"Lateral force, minus the reference",hold:$t,scale:{delta:!0}}),Ie("delta-mu","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load, minus the reference",scale:{delta:!0}}),Ie("delta-calpha","Fz",["Calpha"],{title:"Cornering stiffness over load, minus the reference",scale:{delta:!0}})]},{id:"car",name:"Car",cards:[nn("operating","operating"),nn("wheels","wheels")]},{id:"fit",name:"Fit check",cards:[nn("fitLateral","fitLateral"),nn("fitLongitudinal","fitLongitudinal"),nn("fitCoupling","fitCoupling"),nn("fitEnvelope","fitEnvelope")]}];var kE=5670374e-14,Dh=273.15,$1=.95,G1=60,Au=10,ME=.55,Ut=25,Eh=-20,Ih=50,ki={tempC:[20,100,200,550,650,750],factor:[.8,.92,1,1,.85,.65]},Mi={discMassKg:.5,discOuterMm:220,specificHeatJPerKgK:460,emissivity:.6,coolingWPerM2K:200,padCurve:{tempC:[...ki.tempC],factor:[...ki.factor]}},wu={...Mi,discMassKg:.4,discOuterMm:200,padCurve:{tempC:[...ki.tempC],factor:[...ki.factor]}};function _h(e,t){let r=t==="front"?Mi:wu,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 SE=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},vi=(e,t,r,n)=>Math.min(r,Math.max(t,SE(e,n)));function AE(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 Nh(e,t){return{discMassKg:vi(e?.discMassKg,.05,20,t.discMassKg),discOuterMm:vi(e?.discOuterMm,50,600,t.discOuterMm),specificHeatJPerKgK:vi(e?.specificHeatJPerKgK,100,3e3,t.specificHeatJPerKgK),emissivity:vi(e?.emissivity,.02,1,t.emissivity),coolingWPerM2K:vi(e?.coolingWPerM2K,Au,5e3,t.coolingWPerM2K),padCurve:AE(e?.padCurve,t.padCurve)}}function Fu(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 Oh(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*kE*o,i=m=>Au+(e.coolingWPerM2K-Au)*Math.pow(Math.max(0,m)*t/a,ME),c=(m,d,p)=>{let h=m+Dh,f=p+Dh;return i(d)*o*(m-p)+s*(h**4-f**4)},l=(m,d)=>i(d)*o+4*s*Math.max(0,m+Dh)**3,u=(m,d)=>r/l(d,m);return{heatCapacityJPerK:r,areaM2:o,convectionAt:i,coolingW:c,timeConstantS:u,step(m,d,p,h,f){if(!(h>0))return m+d/r;let b=u(p,m+Math.max(0,d)/r),g=Math.max(1,Math.ceil(h/(.25*b))),y=h/g,x=d/g;for(let k=0;k<g;k++)m+=(x-c(m,p,f)*y)/r;return m},padFactor:m=>Fu(e.padCurve,m),window:K1(e.padCurve)}}function Cu(e,t,r,n,o,a,s=Ut){let i=n.length,c=new Array(i),l=new Array(i),u=new Array(i),m=$1/Math.max(1,t),d=a,p=d,h=0,f=0,b=0;for(let g=0;g<i;g++){let y=Math.max(0,r[g]??0);c[g]=d,l[g]=y*n[g],u[g]=e.padFactor(d);let x=y*(o[g]??0);h+=x,d<e.window.fromC?f+=x:d>e.window.toC&&(b+=x);let k=g+1<i?n[g+1]:n[g],v=.5*(n[g]+k),R=v>0?(o[g]??0)/v:0;d=e.step(d,m*x,v,R,s),d>p&&(p=d)}return{tempC:c,heatW:l,padFactor:u,startC:a,endC:d,maxC:p,workJ:h,coldWorkJ:f,hotWorkJ:b}}function K1(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])&&Fu(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,W1=.001,yo={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},$h={fullAtBar:10,maxPowerKw:0,fadeBelowKmh:0,distribution:"equal"};var Gh=U1(Pu(yo,"Formula Student brakes")),Kh=40,j1={ideal:!1,barFront:yo.barFront,pedalForceMaxN:0,testSpeedKmh:Kh,regen:$h};function H1(e){let{heat:t,...r}=e;return t?{...r,heat:{...t,padCurve:{tempC:[...t.padCurve.tempC],factor:[...t.padCurve.factor]}}}:r}function U1(e){let t=(r,n)=>r.heat?r:{...r,heat:_h(r,n)};return{...e,front:t(e.front,"front"),rear:t(e.rear,"rear")}}function Pu(e,t){return{name:t,pedalRatio:e.pedalRatio,masterFrontMm:e.masterFrontMm,masterRearMm:e.masterRearMm,valve:e.valve,valveKneeBar:e.valveKneeBar,valveSlope:e.valveSlope,front:H1(e.front),rear:H1(e.rear),adjusterPitchMm:e.adjusterPitchMm,barLengthMm:e.barLengthMm}}function Hh(e,t){return X1({...e,barFront:t.barFront,pedalForceMaxN:t.pedalForceMaxN})}function zh(e,t){let r=an(t),n=e?Lr(e):void 0;return{mode:r.ideal?"tyre":n?"hydraulic":"balance",hydraulic:n?Hh(n,r):yo,regen:r.regen}}var wE=["none","proportioning","limiter"],Tu=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},ft=(e,t,r,n)=>Math.min(r,Math.max(t,Tu(e,n))),FE=(e,t)=>{let r=Tu(e,t);return r>0?r:t};function z1(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(Tu(e?.discs,n==="inboard"?1:t.discs)))),pistonsPerSide:Math.max(1,Math.min(6,Math.round(Tu(e?.pistonsPerSide,t.pistonsPerSide)))),pistonDiaMm:ft(e?.pistonDiaMm,5,80,t.pistonDiaMm),padMu:ft(e?.padMu,.05,1.5,t.padMu),effRadiusMm:ft(e?.effRadiusMm,20,300,t.effRadiusMm),ratio:n==="inboard"?ft(e?.ratio,1,20,t.ratio):1,...e?.heat&&typeof e.heat=="object"?{heat:Nh(e.heat,t.heat??r)}:{}}}function X1(e){let t=yo;return{pedalRatio:ft(e?.pedalRatio,.5,15,t.pedalRatio),pedalForceMaxN:ft(e?.pedalForceMaxN,0,5e3,t.pedalForceMaxN),barFront:ft(e?.barFront,.05,.95,t.barFront),masterFrontMm:ft(e?.masterFrontMm,8,40,t.masterFrontMm),masterRearMm:ft(e?.masterRearMm,8,40,t.masterRearMm),valve:wE.includes(e?.valve)?e?.valve:t.valve,valveKneeBar:ft(e?.valveKneeBar,0,200,t.valveKneeBar),valveSlope:ft(e?.valveSlope,0,1,t.valveSlope),front:z1(e?.front,t.front,Mi),rear:z1(e?.rear,t.rear,wu),adjusterPitchMm:FE(e?.adjusterPitchMm,t.adjusterPitchMm),barLengthMm:ft(e?.barLengthMm,0,500,t.barLengthMm)}}function CE(e){let t=$h;return{fullAtBar:ft(e?.fullAtBar,0,200,t.fullAtBar),maxPowerKw:ft(e?.maxPowerKw,0,1e3,t.maxPowerKw),fadeBelowKmh:ft(e?.fadeBelowKmh,0,100,t.fadeBelowKmh),distribution:e?.distribution==="wheel"?"wheel":"equal"}}function Lr(e){let t=X1(e??void 0),r=typeof e?.name=="string"&&e.name.trim()?e.name:TE;return Pu(t,r)}function an(e){return{ideal:e?.ideal===!0,barFront:ft(e?.barFront,.05,.95,yo.barFront),pedalForceMaxN:ft(e?.pedalForceMaxN,0,5e3,0),testSpeedKmh:ft(e?.testSpeedKmh,5,150,Kh),regen:CE(e?.regen)}}var TE="Formula Student brakes";var Bh=e=>Math.PI/4*(e*W1)**2;function Bn(e,t){let r=e.pistonsPerSide*Bh(e.pistonDiaMm)*Vh;return e.discs*2*e.padMu*r*e.effRadiusMm*W1*e.ratio/Math.max(.05,t)}function q1(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 Si(e,t){let r=Math.max(0,t)*e.pedalRatio,n=e.barFront*r/Bh(e.masterFrontMm)/Vh,o=(1-e.barFront)*r/Bh(e.masterRearMm)/Vh;return{front:n,rearIn:o,rear:q1(e,o)}}function PE(e,t){let r=Si(e,1);return{front:Bn(e.front,t)*r.front,rear:Bn(e.rear,t)*r.rearIn}}function Ai(e,t){let r=PE(e,t);return r.front/Math.max(1e-12,r.front+r.rear)}function wi(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=Q1(t,l),m=t.maxPowerKw>0&&l>0?t.maxPowerKw*1e3/l:1/0,d=Math.max(0,e.fFront[c]),p=Math.max(0,e.fRear[c]),h=d+p>0?Math.min(1,m/(d+p)):1;r.push(l),n.push(d*h*u),o.push(p*h*u)}}function Q1(e,t){let r=e.fadeBelowKmh/3.6;return r>0?Math.max(0,Math.min(1,t/r)):1}function on(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 Y1=new WeakMap;function xo(e){let t=Y1.get(e);return t||(t=e.mode==="hydraulic"&&e.hydraulic?DE(e,e.hydraulic):LE(e),Y1.set(e,t)),t}function LE(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 DE(e,t){let r=Bn(t.front,e.tyreRadiusM),n=Bn(t.rear,e.tyreRadiusM),o=e.regen,a=(c,l)=>{let u=Si(t,c),m=0,d=0;if(o&&u.front>0){let p=o.fullAtBar>0?Math.min(1,u.front/o.fullAtBar):1;m=p*on(o.v,o.front,l),d=p*on(o.v,o.rear,l)}return{front:r*u.front+m,rear:n*u.rear+d,regenFront:m,regenRear:d,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 d=0;d<60;d++){let p=.5*(m+u);i(p,l)<c?m=p:u=p}return u}}}function Yh(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 Lu=ni,EE=.1,Ro=(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 d=0;d<48;d++)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 d of[t,r]){let p=e(d);p>m&&(u=d,m=p)}return u}function Uh(e,t,r){let n=Math.max(0,r-Lu*t.b),o=Math.min(r,Lu*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 Xh(e,t,r,n,o=0){let a=Math.max(0,r),s=Uh(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],d=u.Fz/Math.max(1e-9,u.Fz+m.Fz),p=Math.max(0,Math.min(1,1-d/EE)),h=p>0&&a<Lu*m.b?m.cap(a):0,f=h>l?l+p*(h-l):0,b=Math.max(0,Math.min(u.slide,u.a)),g={xNoLock:l,xLock:f,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:x,hi:k}=s,v=Du(P=>{let S=Ro(e,P),w=Ro(t,a-P);return Math.min(S+w,2*Math.min(S,w)+y)},x,k),R=e.cap(v),M=t.cap(a-v),A=Math.max(2*l,Math.min(R+M,2*Math.min(R,M)+y)),F=(P,S,w)=>Math.min(y,Math.max(0,P-w))+Math.min(y,Math.max(0,S-w));return{...g,regenWheel:y,mixedMax:A,regenRoom:P=>{let S=F(i,c,P);if(!(a>0))return S;let w=_=>Lu*_.b*Math.sqrt(Math.max(0,1-(P/Math.max(1e-9,_.a))**2)),C=Math.max(x,a-w(t)),L=Math.min(k,w(e));if(!(C<=L))return S;let E=Du(_=>Math.min(y,Ro(e,_)-P)+Math.min(y,Ro(t,a-_)-P),C,L);return Math.max(S,F(e.cap(E),t.cap(a-E),P))}}}var Wh=e=>Math.max(e.xNoLock,e.xLock),jh=e=>Math.max(e.mixedMax,2*e.xLock);function $a(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 Ga(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 Fi(e,t,r,n){return e.shares?IE(e,e.shares,t,r,n):_E(e,t,r,n)}function Z1(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 IE(e,t,r,n,o){let a=jh(r),s=jh(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=Ga(r,t.front*b),y=Ga(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,d=[{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&&d.push({u:b,by:"front"})}if(n.xLock>n.xNoLock){let b=t.rear>0?n.mixedMax/t.rear:1/0;b<i&&d.push({u:b,by:"rear"})}let{cand:p,force:h}=Z1(d,l),f=e.demand(p.u,o);return{force:Math.max(0,Number.isFinite(h)?h:0),control:p.u,demand:f,limitedBy:p.by,lockFront:f.front/2>r.mixedMax/2*(1+1e-9),lockRear:f.rear/2>n.mixedMax/2*(1+1e-9)}}function _E(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 R=e.demand(v,n);return s(R)<=o*(1+1e-12)&&i(R)<=a*(1+1e-12)},l=(v,R)=>{if(v(e.demand(R,n)))return R;let M=0,A=R;for(let F=0;F<60;F++){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),d=Number.isFinite(e.uMax)&&m>=e.uMax,p=v=>{let R=e.demand(v,n),M=$a(t,s(R),R.regenFront),A=$a(r,i(R),R.regenRear);return Number.isFinite(M)&&Number.isFinite(A)?M+A:-1/0},h=e.demand(m,n),f=o>0?s(h)/o:1/0,b=a>0?i(h)/a:1/0,g=[{u:m,by:d?"pedal":f>=b?"front":"rear"}];if(t.xLock>t.xNoLock){let v=l(R=>s(R)<=t.xNoLock,m);v<m&&g.push({u:v,by:"front"})}if(r.xLock>r.xNoLock){let v=l(R=>i(R)<=r.xNoLock,m);v<m&&g.push({u:v,by:"rear"})}let{cand:y,force:x}=Z1(g,p),k=e.demand(y.u,n);return{force:Math.max(0,Number.isFinite(x)?x: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 sn={regen:!0,regenEfficiency:.6};function cn(e,t){let r=e.energy??t??sn;return{regen:r.regen===!0,regenEfficiency:Math.min(1,Math.max(0,Number.isFinite(r.regenEfficiency)?r.regenEfficiency:0))}}function ln(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 J1(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 ht(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 Eu(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 h=o+a>>1;e[h]<=r?o=h:a=h}if(o===n-1)return t[n-1];let s=h=>e[h+1]-e[h],i=h=>(t[h+1]-t[h])/s(h),c=h=>{if(h===0||h===n-1){let[y,x]=h===0?[0,1]:[n-2,n-3],k=i(y)*(1+s(y)/(s(y)+s(x)))-i(x)*(s(y)/(s(y)+s(x)));return k*i(y)<=0?0:Math.abs(k)>2*Math.abs(i(y))?2*i(y):k}let f=i(h-1),b=i(h),g=(f*s(h)+b*s(h-1))/(s(h-1)+s(h));return(Math.sign(f)+Math.sign(b))*Math.min(Math.abs(f),Math.abs(b),.5*Math.abs(g))},l=s(o),u=i(o),m=c(o),d=c(o+1),p=r-e[o];return t[o]+p*(m+p*((3*u-2*m-d)/l+p*(m+d-2*u)/(l*l)))}function Ci(e,t,r){return r.map(n=>ht(e,t,n))}var Ti=e=>e.reduce((t,r)=>r>t?r:t,-1/0),Ka=e=>e.reduce((t,r)=>r<t?r:t,1/0);var NE=[-.906179845938664,-.538469310105683,0,.538469310105683,.906179845938664],OE=[.236926885056189,.478628670499366,.568888888888889,.478628670499366,.236926885056189];function qh(e,t,r){let n=.5*(r-t),o=.5*(t+r),a=0;for(let s=0;s<5;s++)a+=OE[s]*e(n*NE[s]+o);return n*a}var VE=Math.PI*2,BE=.5/3.6;function Pi(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 Qh(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*VE;c[g]=y*o/n,l[g]=s[g]*n/o}let u=Ti(c),m=ln(Ka(c),u,u/BE),d=Ci(c,l,m),{front:p,rear:h}=Pi(t,r),f=d.map(g=>g*p),b=d.map(g=>g*h);return{vVehicle:m,fFront:f,fRear:b,vMax:u}}var ek=60/(2*Math.PI),tk=.1,rk=.08,nk=0;function Zh(e){let t=(r,n)=>r===void 0||!Number.isFinite(r)?n:Math.max(0,r);return{up:t(e.upshiftTime,tk),down:t(e.downshiftTime,rk)}}function Jh(e){let t=e.driveKept;return t===void 0||!Number.isFinite(t)?nk:Math.max(0,Math.min(1,t))}function eb(e,t,r){let{primary:n,ratios:o,efficiency:a}=e.gearbox,s=t>0&&r>0&&n>0,i=(b,g)=>b/ek*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,Ue(e.rpm,e.torque,b)),d=(b,g)=>{let y=c[g];return y?b*y.ratio/r*ek:0},p=(b,g)=>g===0&&c.length>0&&b<c[0].vIdle,h=(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(d(b,g))*y.ratio*l/r:0},f=(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:d,torque:m,force:h,inertiaMass:f,slipping:p}}function Ha(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 tb(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 ok=9.81,ak=Math.PI*2;function Xt(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]*(ak/60),a[v]=t[v]/60*ak,s[v]=a[v]*u/l,i[v]=r[v]*l,c[v]=i[v]/u;let m=Ti(s),d=m,p=.5/3.6,h=ln(Ka(s),m,m/p),f=Ci(s,c,h),b=ln(Ka(t),Ti(t),250),g=Ci(t,o,b).map(v=>v*e.power_scale.value),y,x=d,k;if(e.motorModel?.kind==="ice"){k=eb(e.motorModel,l,u);let v=ln(0,k.vMax,Math.max(2,Math.ceil(k.vMax/p)+1)),R=v.map(F=>tb(k,F)),M=v.map(()=>0),A=e.motorPlacement==="front";y={vVehicle:v,fFront:A?R:M,fRear:A?M:R,vMax:k.vMax},x=k.vMax}else e.motorModel&&(y=Qh(e.motorModel,Math.max(1,Math.round(e.motorCount??e.driven_wheels.value)),e.motorPlacement??"rear",l,u),x=y.vMax);return{params:e,g:ok,FG:e.m.value*ok,vMax:x,vVehicle:h,fRad:f,uMotor:b,pMotor:g,vRad:s,fAxle:y,...k?{engine:k}:{}}}var hr=e=>e.motorModel?.kind==="ice"?Pi(1,e.motorPlacement==="front"?"front":"rear"):Pi(Math.max(1,Math.round(e.motorCount??e.driven_wheels?.value??2)),e.motorPlacement??"rear");function sk(e){let t=hr(e);return t.front>=2||t.rear>=2}function ik(e){return sk(e)?e.motorMount??"hub":"chassis"}function rb(e){if(!e.motorModel)return{front:!1,rear:!0};let t=hr(e);return{front:t.front>0,rear:t.rear>0}}function nb(e){let t=hr(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=ik(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 Et(e){return zh(e.brakeModel,e.brakeSetup)}function Li(e){return an(e.brakeSetup).ideal?"tyre":e.brakeModel||e.brakeModelId?"hydraulic":"balance"}function Iu(e){let t=Li(e);return t==="hydraulic"?{brake_balance:"set by the balance bar and the brake hardware"}:t==="tyre"?{brake_balance:"tyre-limited brakes split as the grip does"}:{}}function ck(e,t){if(!(pt(e.motorModel)||!cn(e).regen))return wi(_u(Xt(e)),t??Et(e).regen)}function _u(e){return e.fAxle??{vVehicle:e.vVehicle,fFront:e.vVehicle.map(()=>0),fRear:e.fRad.map(t=>t*e.params.driven_wheels.value)}}function ob(e,t=Et(e)){if(t.mode==="hydraulic")return Ai(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+re(e,"cg_height")/Math.max(1,re(e,"wheelbase"))))}return re(e,"brake_balance")}function ab(e,t=Et(e)){return{front:t.hydraulic.front.location==="inboard",rear:t.hydraulic.rear.location==="inboard"}}function sb(e){let t=Et(e);return{brakeBalanceFront:ob(e,t),brakeInboard:ab(e,t)}}function lk(e,t=Et(e)){if(t.mode==="tyre"||t.regen.distribution!=="wheel"||pt(e.motorModel))return;let r=hr(e),n={front:r.front>=2,rear:r.rear>=2};return n.front||n.rear?n:void 0}function Di(e){let t=Et(e),r=e.r_dyn.value,n=ab(e,t),o=ob(e,t),a=lk(e,t),s=t.mode==="hydraulic"||a?ck(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 GE=9.81;function cb(e,t){let r=uk(e,t);return(n,o,a)=>r(n,o,a).total}var ib={front:0,rear:0,total:0};function uk(e,t){if(pt(e.motorModel))return()=>ib;let r=Et(e),n=wi(t,r.regen);if(r.mode==="hydraulic"){let a=xo({mode:"hydraulic",balanceFront:Ai(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 ib;let c=a.demand(a.controlFor(s,i),i),l=c.regenFront+c.regenRear,u=Math.min(s,l),m=l>0?u/l:0;return{front:c.regenFront*m,rear:c.regenRear*m,total:u}}}let o=r.mode==="tyre"?KE(e):()=>Math.min(.99,Math.max(.01,re(e,"brake_balance")));return(a,s,i)=>{if(!(a>0))return ib;let c=o(s,i),l=Math.min(c*a,on(n.v,n.front,s)),u=Math.min((1-c)*a,on(n.v,n.rear,s));return{front:l,rear:u,total:l+u}}}function KE(e){let t=e.m.value*GE,r=e.front_mass_diss.value>1?e.front_mass_diss.value/100:e.front_mass_diss.value,n=re(e,"cg_height")/Math.max(1,re(e,"wheelbase")),o=1-Math.max(0,Math.min(1,re(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 mk(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 lb={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"},...mk("front"),...mk("rear")},ub={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 mb(e){let t=lb[e];return`${t.label}, ${t.section}`.toLowerCase()}function pb(e){let t=ub[e];return t.section?`${t.section} ${t.label.charAt(0).toLowerCase()}${t.label.slice(1)}`:t.label}var pk=new WeakMap;function Dr(e){if(e.brakes)return e.brakes;let t=pk.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},pk.set(e,t)}return t}var un=e=>xo(Dr(e));var WE=Math.PI/180,za=Object.freeze({tbr:1,preloadN:0}),Nu=Object.freeze({tbr:1/0,preloadN:0}),fb=e=>e.faces*e.muClutch*e.rFrictionMm/e.rRampMm;function hb(e,t){if(!(e>0)||Number.isNaN(t))return 0;let r=Math.tan(Math.min(90,t)*WE);return r>0?Math.min(1,e/r):1}function fk(e){if(e>=1)return 1/0;let t=e>0?e:0;return(1+t)/(1-t)}function Ou(e){return e===1/0?1:e>1?(e-1)/(e+1):0}function vo(e,t){return e.tbr===1/0?1/0:(e.preloadN>0?e.preloadN:0)+Ou(e.tbr)*Math.abs(t)}function Ii(e,t,r){let n=o=>o!==void 0&&o>0&&r>0?o/r:0;switch(e.kind){case"open":return za;case"spool":return Nu;case"independent":return t==="hubs"?za:Nu;case"clutch":{let o=n(e.preloadNm);return t==="hubs"?{tbr:1,preloadN:o}:{tbr:fk(hb(fb(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 Ei(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 dk=4;function db(e,t){let r=0;for(let a of e)r=Math.max(r,Ei(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=d=>{d>0&&d<1&&(r=Math.max(r,Ei(s.m1+d*i,s.m2+d*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 _i(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=Uh(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=>Ro(e,b)+Ro(t,c-b),l.lo,l.hi),d=[{m1:l.c1,m2:l.c2}];for(let b=1;b<=dk&&m!==l.y1;b++){let g=l.y1+(m-l.y1)*b/dk;d.push({m1:e.cap(g),m2:t.cap(c-g)})}let p=db(d,za),h=db(d,Nu);if(!(h>p))return u;let f=(db(d,{tbr:s,preloadN:i})-p)/(h-p);return Math.min(a,u+(a-u)*Math.min(1,Math.max(0,f)))}function hk(e,t,r,n,o,a){return bb(e,o,_i(t,r,n,o,a))}function bb(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 gb(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,d=l-s,p=d!==0?i-l*(i-o)/d: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 h=e(p),f=h-p;if(u++,m&&f<0==l<0?s*=.5:(o=i,s=l),i=p,c=h,l=f,s<0!=l<0&&Math.abs(i-o)<=r)break}return{x:i,fx:c,evals:u}}function bk(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),d=0;for(let p=o;l<a;p*=2){if(d=Math.min(d+p,m),d>m-n)return null;let h=t+u*d,f=e(h),b=f-h;if(l++,!(Math.abs(b)>n))return{x:h,fx:f,evals:l};if(c<0!=b<0)return yk(e,s,c,h,f,b,n,l,a);s=h,c=b}return null}function gk(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 yk(e,o,s,c,u,m,r,l,n);if(l>=n)return{x:c,fx:u,evals:l};let d=Math.abs(c-o),p=s!==m?m*(c-o)/(s-m):NaN,h=p*i>0?Math.min(Math.abs(p),10*Math.abs(m),2*d):2*d;o=c,s=m,c+=i*h}}function yk(e,t,r,n,o,a,s,i,c){let l=t,u=r,m=n,d=a,p=n,h=o,f=0;for(;i<c&&Math.abs(m-l)>s;){p=(l*d-m*u)/(d-u),h=e(p);let b=h-p;if(i++,!(Math.abs(b)>s))break;b<0==u<0?(l=p,u=b,f===-1&&(d*=.5),f=-1):(m=p,d=b,f===1&&(u*=.5),f=1)}return{x:p,fx:h,evals:i}}function Vu(e,t){return Math.abs(e.fx-e.x)>t?e.x:e.fx}var jE=(e,t)=>{let r=e.brakes?.hydraulic?.[t];return!!r&&r.location==="inboard"&&r.discs===1};function qt(e,t,r){let n=e.driveline?.[t];if(n)return r>=0?n.drive:jE(e,t)?n.coast:n.hubs}var xk=e=>e.tbr>1||e.preloadN>0;var UE=9.81,Rk=["FL","FR","RL","RR"],yb=e=>e==="FL"||e==="FR",Bu=e=>yb(e)?"front":"rear",vk={front:["FL","FR"],rear:["RL","RR"]},Vi=()=>({peak:new Map,freeBrake:new Map}),Oi=25;function Ni(e,t){let r=Math.max(0,e)/Oi,n=Math.floor(r),o=r-n,a=t(n);return o>0?a+o*(t(n+1)-a):a}var $n=1e-4,XE=.05;function mn(e,t,r,n=Vi(),o=!1){let a=r,s=e.massTotal,i=n.peak,c=(S,w)=>{let C=`${S}:${w}`,L=i.get(C);return L||(L=Ql(Fe(t,S),Math.max(1,w*Oi)),i.set(C,L)),L},l=(S,w)=>({aPeak:Ni(w,C=>c(S,C).aPeak),fyPeak:Ni(w,C=>c(S,C).fyPeak)}),u=n.freeBrake,m=(S,w)=>{let C=`${S}:${w}`,L=u.get(C);if(L===void 0){let E=Math.max(1,w*Oi);L=jt(Fe(t,S),E,0,!0,c(S,w)),u.set(C,L)}return L},d=(S,w)=>w>0?Ni(w,C=>m(S,C)):0,p=un(e),h=Dr(e),f=S=>h.regen&&h.regenPerWheel?.[S]?on(h.regen.v,h.regen[S],a)/2:0,b=f("front"),g=f("rear"),y=(S,w,C)=>{let L=Math.max(0,w[S]),E=l(Bu(S),L);return jt(Fe(t,Bu(S)),L,C[S]*E.fyPeak,!0,E)},x=(S,w,C,L,E=!0,_=1)=>{let O=ne=>{let Z=Math.max(0,w[ne]),xe=Fe(t,S),de=l(S,Z),be={Fz:Z,a:Math.abs(d(S,Z)),b:de.fyPeak,slide:Z>0?Math.abs(xe.forces({Fz:Z,kappa:-1,alpha:0}).Fx):0,cap:U=>Math.abs(jt(xe,Z,U,!0,de))};return _===1?be:{Fz:Z,a:_*be.a,b:_*be.b,slide:_*be.slide,cap:U=>_*be.cap(U/_)}},I=ne=>_*Math.abs(C[ne])*l(Bu(ne),Math.max(0,w[ne])).fyPeak,[z,B]=vk[S],V=O(z),j=O(B),q=I(z)+I(B),K=Xh(V,j,q,L,S==="front"?b:g),D=E?K:{...K,xLock:0},N=qt(e,S,-1),Y=N&&xk(N)?N:void 0;if(!Y)return{axle:S,eq:D,cap:D};let H=Number.isFinite(L)?L:V.cap(I(z))+j.cap(I(B)),W=hk(D,V,j,q,Y,H);return{axle:S,eq:D,cap:W,law:Y,strong:()=>V.cap(I(z))>=j.cap(I(B))?z:B}},k=(S,w,C,L,E=1)=>x(S,w,C,L,!0,E).cap,v=(S,w,C)=>{let L=S.demand,E=p.shares?Ga(w,L.front):$a(w,(L.front-L.regenFront)/2,L.regenFront),_=p.shares?Ga(C,L.rear):$a(C,(L.rear-L.regenRear)/2,L.regenRear);return{front:Number.isFinite(E)?E:0,rear:Number.isFinite(_)?_:0}},R=S=>({muX:w=>w>0?Math.abs(d(S,w))/w:0,muY:w=>w>0?l(S,w).fyPeak/w:0}),M={front:R("front"),rear:R("rear")},A={lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},F={front:e.trackFront/2e3,rear:e.trackRear/2e3},T=(S,w,C,L,E)=>{let _=L.cap,O=E.cap,I=Fi(p,_,O,a),z={arms:A,halfTrack:F,ayDir:Math.sign(S)};for(let B=0;B<2;B++){let V=v(I,_,O),j={};for(let K of Rk){let D=Math.max(0,w[K]);j[K]={Fz:D,Fy:Math.abs(C[K])*l(Bu(K),D).fyPeak,Fx:-(yb(K)?V.front:V.rear)/2}}let q=K=>{if(!K.law||!K.strong)return K.cap;let D={axle:K.axle,strong:K.strong(),full:2*K.cap.xNoLock,open:2*K.eq.xNoLock,sense:-1};return bb(K.eq,K.law,yu(D,j,M,z))};_=q(L),O=q(E),I=Fi(p,_,O,a)}return{limit:I,front:_,rear:O}};return{peakAt:l,axle:k,ceiling:(S,w,C)=>{let[L,E]=vk[S];return Math.abs(y(L,w,C)+y(E,w,C))},limitAt:(S,w,C,L=0)=>{let E={FL:0,FR:0,RL:0,RR:0},_=$e(e,S,0,a,0,w),O,I=ne=>(O?.ax!==ne&&(O={ax:ne,loads:$e(e,S,(ne+L)/UE,a,0,w)}),O.loads),z=Zl(ne=>Da(C,I(ne),_,l).short,-L,-1),B=C,V={front:0,rear:0},j,q,K=(ne,Z=!0)=>{let xe=z.at(ne);E=I(xe),B=Da(C,E,_,l).util;let de=0,be=0,U=0;for(let ee of Rk){let se=y(ee,E,B);de+=se,yb(ee)?be+=se:U+=se}if(V={front:Math.abs(be),rear:Math.abs(U)},p.mode!=="tyre"){let ee=x("front",E,B,Math.abs(be),Z),se=x("rear",E,B,Math.abs(U),Z);if(o&&(ee.law||se.law)){let ie=T(S,E,B,ee,se);j=ie.limit,q={front:ie.front,rear:ie.rear}}else j=Fi(p,ee.cap,se.cap,a),q={front:ee.cap,rear:se.cap};de=-j.force}return de/s},D=gb(K,0,$n),N=Vu(D,$n),Y=N;if(j?.lockFront||j?.lockRear){let ne=gb(xe=>K(xe,!1),0,$n);Y=Vu(ne,$n);let Z=bk(K,ne.x,D.x,$n,XE);Z||K(D.x),N=Vu(Z??D,$n)}let H=z.edge(),W=H!==void 0&&N<H;W&&(N=Math.min(0,H),K(N),Y=Math.max(Y,N));let X={loads:E,ceiling:V,limit:j,axles:q};return{ax:N,axUnlocked:Y,...W?{edge:H}:{},...X,split:()=>X.limit&&X.axles?v(X.limit,X.axles.front,X.axles.rear):{...X.ceiling}}}}}var Gu=9.81;function qE(e,t,r){let n=$e(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 Sk=(e,t)=>t.mode==="hydraulic"&&!!Dr(e).regen;function Ya(e,t,r=0,n,o=0,a=1){if(!e.brakes&&e.brakeBalanceFront==null)return e.frontMassFrac;let s=un(e);if(s.shares&&s.mode!=="tyre")return s.shares.front;let i=n&&Sk(e,s)?Fk(e,n):void 0,c=i?Ak(a):ko,l=i?wk(i,c).shares:kk.get(e);l||kk.set(e,l=new Map);let u=Math.round(Math.abs(t)/.005),m=Math.round(Math.max(0,r)/.25),d=i?Math.round(o/.01):0,p=Ck(u,m,d),h=l.get(p);if(h===void 0){let f=-u*.005,b=m*.25,g=e.massTotal*Math.abs(f)*Gu;if(i){let y=Pk(s,Tk(e,i,u,m,d,c),g,b);h=y.front+y.rear>0?y.front/(y.front+y.rear):.5}else h=s.mode==="tyre"?qE(e,f,b):Yh(s,g,b);l.size>5e4&&l.clear(),l.set(p,h)}return h}var kk=new WeakMap;function Ku(e,t,r,n,o=0,a=1){let s=un(e);if(!Sk(e,s))return;let i=Math.round(Math.max(0,r)/(e.massTotal*Gu)/.005),c=Math.round(Math.max(0,n)/.25);return Pk(s,Tk(e,Fk(e,t),i,c,Math.round(o/.01),Ak(a)),Math.max(0,r),n)}var ko=100,Ak=e=>e>0&&Number.isFinite(e)?Math.max(1,Math.round(e*ko)):ko;function wk(e,t){if(t===ko)return e;let r=e.roads.get(t);return r||e.roads.set(t,r={shares:new Map,rooms:new Map}),r}var Mk=new WeakMap;function Fk(e,t){let r=Mk.get(e);r||Mk.set(e,r=new WeakMap);let n=r.get(t);return n||r.set(t,n={ev:t,tyres:Vi(),shares:new Map,rooms:new Map,speeds:new Map,roads:new Map}),n}var Ck=(e,t,r)=>(r*1001+e)*100003+t;function Tk(e,t,r,n,o,a=ko){let s=Ck(r,n,o),i=wk(t,a),c=a===ko?1:a/ko,l=i.rooms.get(s);if(!l){let u=n*.25,m=o*.01,d=t.speeds.get(n);d||(d={cap:mn(e,t.ev,u,t.tyres),dragG:-Math.max(0,Vs(e,u).drag)/(e.massTotal*Gu)},t.speeds.set(n,d));let{cap:p}=d,h=$e(e,m,-r*.005+d.dragG,u),f=Math.abs(m)*e.massTotal*Gu,b=x=>{let[k,v]=x==="front"?["FL","FR"]:["RL","RR"],R=f*(x==="front"?e.frontMassFrac:1-e.frontMassFrac),M=c*(p.peakAt(x,Math.max(0,h[k])).fyPeak+p.peakAt(x,Math.max(0,h[v])).fyPeak),A=R>0&&M>0?Math.min(1,R/M):0;return p.axle(x,h,{FL:A,FR:A,RL:A,RR:A},1/0,c)},g,y;l=(x,k)=>(x==="front"?g??=b("front"):y??=b("rear")).regenRoom(k),i.rooms.size>5e4&&i.rooms.clear(),i.rooms.set(s,l)}return l}function $u(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 Pk(e,t,r,n){if(!(r>0))return $u(e,t,1,n);let o=c=>c.front+c.rear,a=e.controlFor(r,n),s=$u(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=$u(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=$u(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},Gn={rel:1e-6,abs:.001,kappa:1e-12,iters:40};function Kn(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)),d=e(o*m),p=Math.abs(d.Fx)-a,h=null;for(;p<0&&m<.3;){let g=Math.min(.3,m*1.9),y=e(o*g),x=Math.abs(y.Fx);if(x<Math.abs(d.Fx)){h={kappa:g,forces:y};break}c=m,l=d,u=p,m=g,d=y,p=x-a}if(p<0){let g=JE(e,o,c,l,m,d,h),y=Math.abs(g.forces.Fx);if(y<a)return{kappa:o*g.kappa,forces:g.forces};m=g.kappa,d=g.forces,p=y-a}let f=d,b=o*m;for(let g=0;g<n.iters&&m-c>n.kappa;g++){let y=p-u,x=Math.abs(y)>1e-12?(c*p-m*u)/y:.5*(c+m);x>c&&x<m||(x=.5*(c+m));let k=e(o*x),v=Math.abs(k.Fx)-a;if(f=k,b=o*x,Math.abs(v)<s)break;v<0?(c=x,u=v,p*=.5):(m=x,p=v,u*=.5)}return{kappa:b,forces:f}}var Lk=1e-6,QE=40,ZE=(3-Math.sqrt(5))/2;function JE(e,t,r,n,o,a,s){let i=a,c,l,u,m=-Math.abs(a.Fx),d,p,h=-Math.abs(n.Fx);if(s){c=s.kappa;let g=-Math.abs(s.forces.Fx);[l,d,u,p]=g<=h?[c,g,r,h]:[r,h,c,g]}else{c=.3;let g=.3*(1-Lk),y=e(t*g),x=-Math.abs(y.Fx);if(x>=m)return{kappa:o,forces:a};[l,d,u,p]=[o,m,r,h],o=g,m=x,i=y}h<m&&([l,d]=[o,m],o=r,m=h,i=n);let f=c-r,b=0;for(let g=0;g<QE;g++){let y=Lk*Math.abs(o)+1e-10,x=.5*(r+c);if(Math.abs(o-x)<=2*y-.5*(c-r))break;let k=!0;if(Math.abs(f)>y){let A=(o-l)*(m-p),F=(o-u)*(m-d),T=(o-u)*F-(o-l)*A;F=2*(F-A),F>0&&(T=-T),F=Math.abs(F);let P=f;if(f=b,Math.abs(T)<Math.abs(.5*F*P)&&T>F*(r-o)&&T<F*(c-o)){b=T/F;let S=o+b;(S-r<2*y||c-S<2*y)&&(b=x>=o?y:-y),k=!1}}k&&(f=o>=x?r-o:c-o,b=ZE*f);let v=Math.abs(b)>=y?o+b:o+(b>=0?y:-y),R=e(t*v),M=-Math.abs(R.Fx);M<=m?(v>=o?r=o:c=o,u=l,p=d,l=o,d=m,o=v,m=M,i=R):(v<o?r=v:c=v,M<=d||l===o?(u=l,p=d,l=v,d=M):(M<=p||u===o||u===l)&&(u=v,p=M))}return{kappa:o,forces:i}}var Hu=e=>Math.max(2,.003*Math.abs(e)),eI=(e,t)=>Math.max(t.abs,t.rel*Math.abs(e)),xb=.5,tI=.03;function rI(e,t,r,n,o,a=!1){let s=.5*(e.vx+t.vx),i=M=>{let A=(1+M)*s/e.vx-1,F=(1+M)*s/t.vx-1,T=e.at(A),P=t.at(F);return{kappaM:M,kl:A,kr:F,fl:T,fr:P,g:T.Fx+P.Fx-r}},c=eI(r,o),l=Math.max(-xb,Math.min(xb,n)),u=i(l);if(Math.abs(l)>tI){let M=i(.8*l);(u.g-M.g)/(l-M.kappaM)>0||(u=i(0))}if(Math.abs(u.g)<c)return u;let m=u.g<0?1:-1,d=u,p=u,h=.004,f=u,b=u;for(let M=0;M<12;M++){let A=d.kappaM+m*h;if(Math.abs(A)>xb)break;let F=i(A);if(Math.abs(F.g)<c)return F;if(Math.abs(F.g)<Math.abs(f.g)&&(f=F),Math.sign(F.g)!==Math.sign(d.g)){p=F;break}if(m*(F.g-d.g)<=0){if(!a)return f;let T=(Math.sqrt(5)-1)/2,P=b.kappaM,S=F.kappaM,w=i(S-T*(S-P)),C=i(P+T*(S-P));for(let E=0;E<40&&Math.abs(S-P)>1e-7;E++)m*(w.g-C.g)<0?(P=w.kappaM,w=C,C=i(P+T*(S-P))):(S=C.kappaM,C=w,w=i(S-T*(S-P)));let L=m*(w.g-C.g)>0?w:C;if(Math.abs(L.g)<c||Math.sign(L.g)===Math.sign(u.g))return Math.abs(L.g)<Math.abs(f.g)?L:f;d=m*(L.kappaM-d.kappaM)>0?d:b,p=L;break}b=d,d=F,h*=1.9}if(p===u)return f;let g=d,y=p,x=g.g,k=y.g,v=Math.abs(x)<Math.abs(k)?g:y,R=Math.min(1e-7,o.kappa);for(let M=0;M<30&&Math.abs(y.kappaM-g.kappaM)>R;M++){let A=k-x,F=Math.abs(A)>1e-12?(g.kappaM*k-y.kappaM*x)/A:.5*(g.kappaM+y.kappaM),T=Math.min(g.kappaM,y.kappaM),P=Math.max(g.kappaM,y.kappaM);F>T&&F<P||(F=.5*(T+P));let S=i(F);if(v=S,Math.abs(S.g)<c)break;Math.sign(S.g)===Math.sign(x)?(g=S,x=S.g,k*=.5):(y=S,k=S.g,x*=.5)}return v}function Dk(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 Bi(e,t,r,n,o,a=Wa,s=!1){let i=rI(e,t,r,o,a,s),c=i.fr.Fx-i.fl.Fx,l=vo(n,r);if(Math.abs(c)<=l){let k=r-(i.fl.Fx+i.fr.Fx),v=Math.max(0,Math.abs(k)-Hu(r))/2;return{left:{kappa:i.kl,forces:i.fl,want:i.fl.Fx+k/2,short:v},right:{kappa:i.kr,forces:i.fr,want:i.fr.Fx+k/2,short:v},locked:!0,spoolKappa:i.kappaM}}let u=Math.sign(c),m=r/2-u*l/2,d=r/2+u*l/2,p=Kn(e.at,m,e.seed||i.kl,a),h=Kn(t.at,d,t.seed||i.kr,a),f=Math.abs(m-p.forces.Fx)>Hu(m),b=Math.abs(d-h.forces.Fx)>Hu(d),g=Math.max(0,n.preloadN),y=Ou(n.tbr);f&&!b?h=Kn(t.at,Dk(p.forces.Fx,u,g,y),h.kappa,a):b&&!f&&(p=Kn(e.at,Dk(h.forces.Fx,-u,g,y),p.kappa,a));let x=(k,v)=>({kappa:k.kappa,forces:k.forces,want:v,short:Math.max(0,Math.abs(v-k.forces.Fx)-Hu(v))});return{left:x(p,m),right:x(h,d),locked:!1,spoolKappa:i.kappaM}}var nI={front:["FL","FR"],rear:["RL","RR"]},oI=Object.freeze({Fx:0,Fy:0,Mz:0});function zu(e,t,r,n){let o=r;for(let a of["front","rear"]){let[s,i]=nI[a],c=r[s]+r[i],l=qt(e,a,c);if(!l||!(vo(l,c)>0))continue;let u=Fe(t,a),m=n.alpha[a],d=(a==="front"?e.trackFront:e.trackRear)/2e3,p=n.grip??1,h=y=>x=>u.forces({Fz:y,kappa:x,alpha:m,gamma:0}),f=y=>x=>{let k=u.forces({Fz:y,kappa:x,alpha:m,gamma:0});return{Fx:p*k.Fx,Fy:p*k.Fy,Mz:p*k.Mz}},b=(y,x)=>{let k=Math.max(0,n.Fz[y]);return{at:k>0?p===1?h(k):f(k):()=>oI,vx:Math.max(.05,1-x*n.curvature),seed:0}},g=Bi(b(s,d),b(i,-d),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 ja=["FL","FR","RL","RR"];function Rb(e,t,r,n={}){let o={FL:0,FR:0,RL:0,RR:0},a={FL:!1,FR:!1,RL:!1,RR:!1};if(t===0&&!e.tvRearDiffN)return{want:o,held:a,left:0};let s=t>=0?1:-1,i=Math.abs(t),c={FL:0,FR:0,RL:0,RR:0},l={FL:1/0,FR:1/0,RL:1/0,RR:1/0};if(s>0){let p=["front","rear"].filter(h=>e.drive[h]);for(let h of p){let[f,b]=h==="front"?["FL","FR"]:["RL","RR"],g=e.drive[h],y=r[f]+r[b];g==="ideal"?(c[f]=r[f],c[b]=r[b],a[f]=a[b]=!0):c[f]=c[b]=y/2}for(let h of ja){let f=e.motorCap?.[h];f!==void 0&&(l[h]=Math.max(0,f))}}else if(e.brake.kind==="ideal")for(let p of ja)c[p]=r[p],a[p]=!0;else{let p=Math.min(1,Math.max(0,e.brake.front));c.FL=c.FR=p/2,c.RL=c.RR=(1-p)/2;for(let h of ja)a[h]=e.brake.abs}let u=Math.max(-1,Math.min(1,e.idealShift??0));if(u!==0){let p={front:s>0?e.drive.front==="ideal":e.brake.kind==="ideal",rear:s>0?e.drive.rear==="ideal":e.brake.kind==="ideal"};for(let h of["front","rear"]){if(!p[h])continue;let[f,b]=h==="front"?["FL","FR"]:["RL","RR"],[g,y]=(e.turn??1)>0?[f,b]:[b,f],[x,k]=u>0?[g,y]:[y,g],v=Math.abs(u)*c[x];c[x]-=v,c[k]+=v}}for(let p of ja){let h=n[p];a[p]&&h!==void 0&&(l[p]=Math.min(l[p],Math.max(0,h)))}let m=aI(i,c,l);for(let p of ja)o[p]=s*m.each[p];let d=e.tvRearDiffN??0;return d&&(o.RL-=d/2,o.RR+=d/2),{want:o,held:a,left:m.left}}function aI(e,t,r){let n={FL:0,FR:0,RL:0,RR:0},o=ja.filter(i=>t[i]>0),a=e,s=o;for(let i=0;i<4&&s.length>0&&a>0;i++){let c=s.reduce((m,d)=>m+t[d],0),l=a/c,u=s.filter(m=>l*t[m]>=r[m]);if(u.length===0){for(let m of s)n[m]=l*t[m];a=0,s=[];break}for(let m of u)n[m]=r[m],a-=r[m];s=s.filter(m=>!u.includes(m))}return{each:n,left:Math.max(0,a)}}var De=9.81,ue=Math.PI/180,sI=8,iI=.02,cI=12,Ek=e=>10*Math.max(Gn.abs,Gn.rel*Math.abs(e)),Ik=1e-6,br=["FL","FR","RL","RR"],Qt=e=>e==="FL"||e==="FR",dn=e=>Qt(e)?"front":"rear";function Xa(e,t){let r=Fe(e,"front"),n=Fe(e,"rear");return r===n?So(r,t):{front:So(r,t),rear:So(n,t)}}function So(e,t){return ph(e,Math.min(t,fr(e)))}var $i=e=>e==="FL"||e==="RL",_k=new WeakMap;function lI(e,t){let r=_k.get(e);r||_k.set(e,r=new Map);let n=100*Math.ceil(2*t*De/100),o=r.get(n);if(!o){let a=Xa(e,n);o="front"in a?a:{front:a,rear:a},r.set(n,o)}return o}function qa(e,t,r=0,n,o=0,a=1){let s=t?.axG??0;if(t?.balance)return{axG:Number.isFinite(s)?s:0,fx:{FL:0,FR:0,RL:0,RR:0},balance:t.balance};let i=Number.isFinite(t?.tvRearDiffN)?t?.tvRearDiffN:0;if(!(!!s&&Number.isFinite(s))&&!i)return null;let l=e.massTotal*s*De,u=s>=0?Math.min(1,Math.max(0,t?.driveFrontFrac??0)):Math.min(.99,Math.max(.01,Ya(e,s,r,n,o,a))),m=l*u/2,d=l*(1-u)/2;return{axG:s,fx:{FL:m,FR:m,RL:d-i/2,RR:d+i/2}}}function Fb(e,t,r,n){return Math.abs(Ao(e,t,r,n!==void 0?{steerMaxDeg:n}:{}).peak.steerDeg)}function Cb(e,t,r,n){let o=e.tv;if(!o?.enabled)return 0;let a=rM(o)(t,Math.abs(r),n);return r<0?-a:a}function Tb(e,t,r=0,n,o=0,a=0,s,i=1){let c=qa(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?zu(e,n,l,s):l}var Ki=e=>$i(e)?-1:1,Wu=(e,t,r,n,o)=>t*e.Fy(t*r,n,t*o);function Ab(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 uI(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/ue,u?r.FL:r.FR,u?r.FR:r.FL):Ta(o,n/ue);return{innerMag:m.innerDeg*ue,outerMag:m.outerDeg*ue,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)),d=Math.atan(s/(u+a/2));c=n+i*(m-n),l=n+i*(d-n)}return{innerMag:c,outerMag:l,innerCamber:0,outerCamber:0,atLock:!1}}function wo(e,t,r){let n=(e.toeFrontDeg??0)*ue,o=(e.toeRearDeg??0)*ue,a=uI(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 ju(e,t,r){if(r.Fz<=0)return 0;let n=Dt(Fe(e,dn(t))),o=Ki(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 Nk(e,t,r,n){if(!bo(e))return null;let o=Dt(Fe(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:ju(o,s,i)}}return hi(e,r/ue,a,Nn(o.model),{FL:n.FL.travelMm,FR:n.FR.travelMm})}var Ok=()=>({totalNm:[],aligningNm:[],lateralNm:[],longitudinalNm:[],jackingNm:[]});function Vk(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 mI=Object.freeze({Fx:0,Fy:0,Mz:0});function Bk(e,t,r){let n=t==="front"?(r?.FL??0)+(r?.FR??0):(r?.RL??0)+(r?.RR??0),o=qt(e,t,n);return o&&vo(o,n)>0?{F:n,law:o}:null}function Zt(e,t,r,n,o,a,s,i,c){let l=s?.fx,u=s?.axG??0,{wb:m,lf:d,lr:p,m:h}=Ab(e),f=Bk(e,"front",l),b=Bk(e,"rear",l),g={front:0,rear:0},y=i!==void 0&&i>0&&Number.isFinite(i)?i:null,x=U=>y===null?r:Math.sqrt(Math.max(0,U)*y),k=Dt(Fe(t,"front")),v=Dt(Fe(t,"rear")),R=e.trackFront/2e3,M=e.trackRear/2e3,A=!!(e.kinFront&&e.kinRear),F=A&&y===null?Vn(e,e.kinFront,e.kinRear,r):null,T=NaN,P=null,S=U=>{if(!A)return null;if(y===null)return F;let ee=x(U);return ee!==T&&(T=ee,P=Vn(e,e.kinFront,e.kinRear,ee)),P},w={},C={FL:0,FR:0,RL:0,RR:0},L=e.kinFront?.compliance,E=e.kinRear?.compliance,_=!!(L||E),O=!!(L?.toePerMz||E?.toePerMz),I=U=>Qt(U)?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}},B=!1,V=s?.balance,j=0,q=V?lI(t,h):null,K=(U,ee)=>ee>0&&q?q[dn(U)].muX(ee)*ee:0,D=U=>{let ee=U/r,se=y===null?n+d*ee/r:n+d/y,ie=y===null?n-p*ee/r:n-p/y,Re=S(U),pe=x(U),ce=Re?Re(U/De,u,n/ue,o/ue):null,Pe=ce?{FL:ce.FL.travel,FR:ce.FR.travel}:void 0,ke=Xl(e,U/De,u,pe,n/ue,o/ue,Pe,ce?.steeringJacking),ae=ke.loads;B=ke.overturned;let ge=wo(e,o,Pe),fe=ge.steer,Ce=0,Ae=Ne=>{let Te=Math.max(0,ae[Ne]),ye=Ki(Ne),me=Qt(Ne)?k:v,Me=I(Ne),Xe=0,Ye=0;if(Me){let Nt=z[Ne];Xe=Me.toePerFy*Nt.fy+Me.toePerFx*Nt.fx+Me.toePerMz*Nt.mz,Ye=Me.camberPerFy*Nt.fy+Me.camberPerFx*Nt.fx}let Le=fe[Ne]+(ce?ye*ce[Ne].bumpToe*ue:0)+ye*Xe*ue,Ke=Le-(Qt(Ne)?se:ie),vt=(ce?ce[Ne].camberRoad:0)*ue+ye*(ge.camber[Ne]+Ye)*ue;return{Fz:Te,mir:ye,t:me,gains:Me,complianceToe:Xe,steerK:Le,slip:Ke,camberRad:vt}},Ge=(Ne,Te)=>{let ye=y===null?ee/r:1/y,me=Qt(Ne)?d:-p,Me=($i(Ne)?1:-1)*(Qt(Ne)?R:M),Xe=(Math.cos(n)-Me*ye)*Math.cos(Te.steerK)+(Math.sin(n)+me*ye)*Math.sin(Te.steerK);return{at:Te.Fz>0?Ye=>Te.t.forces({Fz:Te.Fz,kappa:Ye,alpha:Te.mir*Te.slip,gamma:Te.mir*Te.camberRad}):()=>mI,vx:Math.max(.05,Xe),seed:C[Ne]}};if(V){let Ne=h*(u*De-(V.axDrag??0)),Te=0;for(let ye=0;ye<cI;ye++){let me={FL:Ae("FL"),FR:Ae("FR"),RL:Ae("RL"),RR:Ae("RR")},Me={FL:K("FL",me.FL.Fz),FR:K("FR",me.FR.Fz),RL:K("RL",me.RL.Fz),RR:K("RR",me.RR.Fz)},Xe=Ne-j,Ye={...V.spec,turn:o<0?-1:1,...Xe<0&&V.brakeFront&&V.spec.brake.kind==="shares"?{brake:{...V.spec.brake,front:V.brakeFront(Xe)}}:{}},Le={},Ke=Rb(Ye,Xe,Me,Le),vt={};for(let mt=0;mt<5;mt++){let He=!1;for(let We of["front","rear"]){let[Oe,rt]=We==="front"?["FL","FR"]:["RL","RR"],Pt=Ke.want[Oe]+Ke.want[rt],pr=qt(e,We,Pt);if(pr&&vo(pr,Pt)>0){let Ve=ct=>Math.max(0,Math.abs(Pt-ct.left.forces.Fx-ct.right.forces.Fx)-Ek(Pt)),ve=Bi(Ge(Oe,me[Oe]),Ge(rt,me[rt]),Pt,pr,g[We],Gn,!0);if(Ve(ve)>0&&(g[We]!==0||C[Oe]!==0||C[rt]!==0)){let ct=Bi({...Ge(Oe,me[Oe]),seed:0},{...Ge(rt,me[rt]),seed:0},Pt,pr,0,Gn,!0);Ve(ct)<Ve(ve)&&(ve=ct)}g[We]=ve.spoolKappa,C[Oe]=ve.left.kappa,C[rt]=ve.right.kappa;let kt=Ke.held[Oe]&&Ke.held[rt],oo=Ve(ve);if(kt&&oo>0){let ct=Math.abs(ve.left.forces.Fx),Wr=Math.abs(ve.right.forces.Fx);(Le[Oe]===void 0||Le[rt]===void 0||ct<Le[Oe]-1e-6||Wr<Le[rt]-1e-6)&&(Le[Oe]=Math.min(ct,Le[Oe]??1/0),Le[rt]=Math.min(Wr,Le[rt]??1/0),He=!0)}vt[Oe]={kappa:ve.left.kappa,Fx:ve.left.forces.Fx,Fy:me[Oe].mir*ve.left.forces.Fy,short:kt?0:oo/2},vt[rt]={kappa:ve.right.kappa,Fx:ve.right.forces.Fx,Fy:me[rt].mir*ve.right.forces.Fy,short:kt?0:oo/2};continue}for(let Ve of[Oe,rt]){let ve=me[Ve],kt=Ke.want[Ve];if(kt===0||ve.Fz<=0){let ma=ve.Fz<=0&&!Ke.held[Ve]?Math.abs(kt):0;ve.Fz<=0&&Ke.held[Ve]&&kt!==0&&Le[Ve]===void 0&&(Le[Ve]=0,He=!0),vt[Ve]={kappa:0,Fx:0,Fy:ve.Fz>0?Wu(ve.t,ve.mir,ve.slip,ve.Fz,ve.camberRad):0,short:ma};continue}let ct=Kn(ma=>ve.t.forces({Fz:ve.Fz,kappa:ma,alpha:ve.mir*ve.slip,gamma:ve.mir*ve.camberRad}),kt,C[Ve],Gn);C[Ve]=ct.kappa;let Wr=Ek(kt),Ix=Math.abs(kt-ct.forces.Fx);if(Ix>Wr&&Math.abs(ct.forces.Fx)<Math.abs(kt)&&Ke.held[Ve]){let ma=Math.abs(ct.forces.Fx);(Le[Ve]===void 0||ma<Le[Ve])&&(Le[Ve]=ma,He=!0)}vt[Ve]={kappa:ct.kappa,Fx:ct.forces.Fx,Fy:ve.mir*ct.forces.Fy,short:Ke.held[Ve]?0:Math.max(0,Ix-Wr)}}}if(!He)break;Ke=Rb(Ye,Xe,Me,Le)}let Nt=0,Sr=0;Te=0;for(let mt of br){let He=me[mt],We=vt[mt];if(w[mt]={Fz:He.Fz,travelMm:ce?.[mt].travel??0,steerRad:He.steerK,slipRad:He.slip,camberRad:He.camberRad,Fy:We.Fy,Fx:We.Fx,kappa:We.kappa,fxShort:We.short+Ke.left/4,lifted:ke.lifted[mt]},He.gains){let rt=O&&He.gains.toePerMz?ju(He.t,mt,w[mt]):0;z[mt]={fy:-He.mir*We.Fy,fx:We.Fx,mz:-He.mir*rt*1e3};let Pt=z[mt];Sr=Math.max(Sr,Math.abs(He.gains.toePerFy*Pt.fy+He.gains.toePerFx*Pt.fx+He.gains.toePerMz*Pt.mz-He.complianceToe))}let Oe=He.steerK-n;Nt+=We.Fx*(Math.cos(Oe)-1)-We.Fy*Math.sin(Oe),Te+=We.Fy*Math.cos(Oe)+We.Fx*Math.sin(Oe)}let wn=Math.abs(Nt-j);if(j=Nt,wn<iI&&Sr<Ik)break}return Te/h}for(let Ne=0;Ne<(_?sI:1);Ne++){Ce=0;let Te=0,ye={};for(let me of br){let Me=Qt(me)?f:b;if(Me&&!ye[me]){let[Ve,ve]=Qt(me)?["FL","FR"]:["RL","RR"],kt=Ae(Ve),oo=Ae(ve),ct=dn(me),Wr=Bi(Ge(Ve,kt),Ge(ve,oo),Me.F,Me.law,g[ct],Gn);g[ct]=Wr.spoolKappa,ye[Ve]={w:kt,share:Wr.left},ye[ve]={w:oo,share:Wr.right}}let Xe=ye[me]?.w??Ae(me),{Fz:Ye,mir:Le,t:Ke,gains:vt,complianceToe:Nt,steerK:Sr,slip:wn,camberRad:mt}=Xe,He=l?.[me]??0,We,Oe=0,rt=0,Pt=0,pr=ye[me]?.share;if(pr)C[me]=pr.kappa,rt=pr.kappa,Oe=pr.forces.Fx,Pt=pr.short,We=Le*pr.forces.Fy;else if(He===0||Ye<=0)We=Wu(Ke,Le,wn,Ye,mt),Pt=Ye<=0?Math.abs(He):0;else{let ve=Kn(kt=>Ke.forces({Fz:Ye,kappa:kt,alpha:Le*wn,gamma:Le*mt}),He,C[me],Gn);C[me]=ve.kappa,rt=ve.kappa,Oe=ve.forces.Fx,Pt=Math.max(0,Math.abs(He-Oe)-Math.max(Wa.abs,Wa.rel*Math.abs(He))),We=Le*ve.forces.Fy}if(w[me]={Fz:Ye,travelMm:ce?.[me].travel??0,steerRad:Sr,slipRad:wn,camberRad:mt,Fy:We,Fx:Oe,kappa:rt,fxShort:Pt,lifted:ke.lifted[me]},vt){let Ve=O&&vt.toePerMz?ju(Ke,me,w[me]):0;z[me]={fy:-Le*We,fx:Oe,mz:-Le*Ve*1e3};let ve=z[me];Te=Math.max(Te,Math.abs(vt.toePerFy*ve.fy+vt.toePerFx*ve.fx+vt.toePerMz*ve.mz-Nt))}Ce+=We*Math.cos(Sr)+Oe*Math.sin(Sr)}if(Te<Ik)break}return Ce/h},N=U=>{let ee=$e(e,0,u,U,0,o/ue);return ee.FL+ee.FR+ee.RL+ee.RR},Y=Math.max(20,3.5*N(r)/h);if(y!==null){Y=4*De;for(let U=0;U<8;U++){let ee=Math.min(40*De,3.5*N(x(Y))/h);if(ee<=Y)break;Y=ee}Y=Math.max(20,Y)}let H=U=>D(U)-U,W=Math.max(.001,Y*1e-4),X=(U,ee,se,ie)=>{let Re=U,pe=se,ce=ee,Pe=ie,ke=Re;for(let ae=0;ae<40;ae++){let ge=Pe-ce,fe=Math.abs(ge)>1e-12?(Re*Pe-pe*ce)/ge:.5*(Re+pe),Ce=Math.min(Re,pe),Ae=Math.max(Re,pe);fe>Ce&&fe<Ae||(fe=.5*(Re+pe));let Ge=H(fe);if(ke=fe,Math.abs(Ge)<1e-4||Ae-Ce<1e-6)break;Ge<0==ce<0?(Re=fe,ce=Ge,Pe*=.5):(pe=fe,Pe=Ge,ce*=.5)}return ke},ne=(U,ee,se,ie=!1)=>{let Re=(ae,ge)=>se>0?ae>0&&ge<0:ge>0&&ae<0,pe=U,ce=ee,Pe=U+se*Math.min(Math.abs(ee),Y);if(!ie&&Math.abs(Pe-U)>W){let ae=H(Pe);if(Re(ce,ae))return{root:X(pe,ce,Pe,ae),last:pe};pe=Pe,ce=ae}let ke=ie?Y/24:Math.max(Y/24,Math.abs(Pe-U)/4);for(let ae=1;ae<=24;ae++){let ge=pe+se*ke;if(Math.abs(ge)>Y)break;let fe=H(ge);if(Re(ce,fe))return{root:X(pe,ce,ge,fe),last:pe};if(ie&&fe*se<0&&(fe-ce)*se<0)break;pe=ge,ce=fe}return{root:null,last:pe}},Z=c??null;if(c===void 0&&a!==void 0&&Number.isFinite(a)&&Math.abs(a)<=Y){let U=H(a);if(Math.abs(U)<=1e-4)H(a+W)<0&&H(a-W)>0&&(Z=a);else{let ee=ne(a,U,Math.sign(U)).root;Z=ee!==null&&(ee===0||Math.sign(ee)===Math.sign(a))?ee:null}}let xe=Z===null;if(Z===null){let U=H(0),ee=H(W),se=Math.abs(U)<=1e-4,ie=se?y!==null?1:o!==0?Math.sign(o):ee>0?1:-1:Math.sign(U),Re=se?ie*W:0,pe=se?ie>0?ee:H(-W):U,ce=ne(Re,pe,ie);Z=ce.root??(se?0:ce.last)}let de=D(Z);if(xe&&o!==0&&y===null){let U=Math.sign(o);if(Z*U<=0||(w.RL.Fy+w.RR.Fy)*U<0){let ee={...w},se=B,ie=U*Math.max(Z*U+W,n*U*r*r/p),Re=null;if(ie*U<Y){let pe=H(ie);if(pe*U>0)Re=ne(ie,pe,U).root;else{let ce=ie+U*Y/24,Pe=H(ce);(Pe-pe)*U>0&&(Re=ne(ce,Pe,U,Pe*U<=0).root)}}Re!==null&&Re*U>0?(Z=Re,de=D(Z)):(Object.assign(w,ee),B=se)}}let be=d*(w.FL.Fy*Math.cos(w.FL.steerRad)+w.FR.Fy*Math.cos(w.FR.steerRad))-p*(w.RL.Fy+w.RR.Fy);if(V){be=0;for(let U of br){let ee=w[U],se=Qt(U)?d:-p,ie=($i(U)?1:-1)*(Qt(U)?R:M),Re=Math.cos(ee.steerRad),pe=Math.sin(ee.steerRad);be+=se*(ee.Fy*Re+ee.Fx*pe)-ie*(ee.Fx*Re-ee.Fy*pe)}}else if(s||f||b){let U=ee=>($i(ee)?1:-1)*(Qt(ee)?R:M);for(let ee of br){let se=w[ee],ie=Qt(ee)?d:-p;be+=ie*se.Fx*Math.sin(se.steerRad)-U(ee)*se.Fx*Math.cos(se.steerRad)}}return y!==null&&Z<-1e-6?{ay:NaN,cn:NaN,wheels:w,overturned:B,res:NaN}:{ay:Z/De,cn:be/(h*De*m),wheels:w,overturned:B,res:de-Z}}function pI(e,t,r,n,o,a,s,i=0){let c=20*ue,l=.001,u=(f,b)=>{let g=Zt(e,t,r,f,n,b,s);return{cn:g.cn-i,ay:g.ay*De}},m=f=>n===0||i!==0||Math.abs(f)<.05||Math.sign(f)===Math.sign(n),d=(f,b,g,y)=>{let x=u(f,y);if(Math.abs(x.cn)<1e-5)return{beta:f,trimmed:!0};let k=y===void 0?void 0:x.ay,v={pos:{b:f,cn:x.cn,ay:k},neg:{b:f,cn:x.cn,ay:k}},R=null,M=f,A=Math.abs(x.cn);for(let F=0;F<b.length&&!R;F++)for(let T of[v.pos,v.neg]){let P=T===v.pos?1:-1,S=f+P*b[F];if(Math.abs(S)>c)continue;let w=u(S,T.ay);if(Math.abs(w.cn)<A&&m(w.ay)&&(A=Math.abs(w.cn),M=S),w.cn===0&&m(w.ay))return{beta:S,trimmed:!0};if(w.cn<0!=T.cn<0){let C={lo:T.b,hi:S,ayLo:T.ay},L=$k(u,C),E=u(L,T.ay);if(Math.abs(E.cn)<l&&m(E.ay))return R=C,{beta:L,trimmed:!0}}T.b=S,T.cn=w.cn,y!==void 0&&(T.ay=w.ay)}return R?{beta:$k(u,R),trimmed:!0}:g?{beta:M,trimmed:!1}:null},p=[.25,.75,2,5].map(f=>f*ue);if(o!==void 0&&Number.isFinite(o)&&Math.abs(o)<=c){let f=d(o,p,!1,a);if(f)return f;if(!s&&i===0&&a!==void 0&&Number.isFinite(a)){let b=dI(e,t,r,n,o,a,c);if(b&&m(b.ay))return{beta:b.beta,trimmed:!0,ay:b.ay}}}let h=[1,3,7,15,20].map(f=>f*ue).filter(f=>f<=c);return d(0,h,!0)??{beta:0,trimmed:!1}}function $k(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),d=m.cn;if(o!==void 0&&(o=m.ay),i=u,Math.abs(d)<1e-5||Math.abs(n-r)<1e-5)break;d<0==a<0?(r=u,a=d,s*=.5):(n=u,s=d,a*=.5)}return i}function dI(e,t,r,n,o,a,s){let i=(d,p)=>{let h=Zt(e,t,r,d,n,void 0,null,void 0,p);return{r:h.res,c:h.cn}},c=o,l=a,u=i(c,l),m=0;for(let d=0;d<fI;d++){let p=i(c+vb,l),h=i(c,l+kb),f=(p.r-u.r)/vb,b=(h.r-u.r)/kb,g=(p.c-u.c)/vb,y=(h.c-u.c)/kb,x=f*y-b*g;if(!Number.isFinite(x)||x===0||Math.abs(x)<yI*(Math.abs(f*y)+Math.abs(b*g)))return null;if(d===0)m=Math.sign(x);else if(Math.sign(x)!==m)return null;if(Math.abs(u.r)<=1e-4&&Math.abs(u.c)<=1e-5)return{beta:c,ay:l};let k=(u.c*b-u.r*y)/x,v=(u.r*g-u.c*f)/x,R=Math.min(1,hI/Math.max(Math.abs(k),1e-300),bI/Math.max(Math.abs(v),1e-300));if(c+=R*k,l+=R*v,Math.abs(c-o)>gI||Math.abs(c)>s||l*a<0)return null;u=i(c,l)}return null}var fI=8,vb=1e-5,kb=.001,hI=1*ue,bI=2,gI=5*ue,yI=.5;function jk(e,t,r,n,o,a,s,i){let c=Zt(e,t,r,n,o,a,s,void 0,i),l=c.ay*De/r,u={},m=0;for(let h of br){let f=c.wheels[h],b=Fe(t,dn(h)),g=fr(b),y=b.muY(Math.min(f.Fz,g)),x=b.muX(Math.min(f.Fz,g));m+=f.fxShort,u[h]={Fz:f.Fz,steerDeg:f.steerRad/ue,slipDeg:f.slipRad/ue,camberDeg:f.camberRad/ue,Fy:f.Fy,Fx:f.Fx,Mz:ju(b,h,f),gripUtil:y*f.Fz>0?Math.hypot(f.Fy/(y*f.Fz),x*f.Fz>0?f.Fx/(x*f.Fz):0):0,...f.Fz>g?{pastTurnover:!0}:{},lifted:f.lifted}}let d=hi(e,o/ue,u,Nn(Fe(t,"front").model),{FL:c.wheels.FL.travelMm,FR:c.wheels.FR.travelMm}),p=wo(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/ue,yawRate:l*180/Math.PI,steerDeg:o/ue,...p.atLock?{lockDeg:(p.steer.FL+p.steer.FR)/2/ue}:{},converged:!0,trimmed:!c.overturned,overturned:c.overturned,driving:!1,fxShortfall:m,...d?{steering:d}:{}}}function fn(e,t,r,n,o,a,s=0){let i=Math.max(8,r),c=Mo(e,t,i,n,o,a,s);return n!==0&&o?.driving===void 0&&(c.driving=EI(e,t,i,c,a,s)),c}function Mo(e,t,r,n,o,a,s){let i=n*ue,c=qa(e,a,r,t),l=o&&Number.isFinite(o.ay)?o.ay*De:void 0,u=o&&Number.isFinite(o.beta)?o.beta*ue:void 0,{beta:m,trimmed:d,ay:p}=pI(e,t,r,i,u,l,c,s),h=jk(e,t,r,m,i,l,c,p),f={...h,trimmed:d&&!h.overturned};return f.driving=n===0?f.trimmed:o?.driving!==void 0&&o.driving&&f.trimmed&&Math.abs(f.beta-o.beta)<=xI,f}var xI=3;function Ao(e,t,r,n={}){let o=Math.max(8,r),a=n.direction??1,s=n.yawDemandCn??0,i=n.steerMaxDeg??RI,c=typeof n.op=="function"?n.op:()=>n.op,l=typeof n.op=="function"||n.op?.balance?null:`${o}|${a}|${s}|${i}|${n.op?`${n.op.axG}|${n.op.driveFrontFrac??""}|${n.op.tvRearDiffN??""}`:""}`;if(l!==null){let R=Mb.get(e)?.get(t)?.get(l);if(R)return R}let u=(R,M)=>M.trimmed&&Math.abs(M.beta-R.beta)<=Uu&&Math.abs(M.ay-R.ay)*De<=Xu,m=!1,d=(R,M)=>{let A=Mo(e,t,o,a*R,M,c(a*R),s);return u(M,A)?(A.driving=!0,A):(m=A.overturned,null)},p=[Mo(e,t,o,0,void 0,c(0),s)],h=null,f=!1,b,g=R=>{let M=p.length-1;for(;M>1&&R.sb*(p[M].beta-p[M-1].beta)>=0;)M--;let A=a*(R.state.ay-p[M].ay)>0,F=T=>R.sb*(T.beta-R.state.beta)>0||a*T.steerDeg>=a*R.state.steerDeg||A&&a*T.ay>=a*R.state.ay;for(;p.length>Math.max(2,M)&&F(p[p.length-1]);)p.pop();b={state:R.state,stall:p[p.length-1]},p.push(R.state),h=Math.abs(R.state.steerDeg)},y=(R,M=!1)=>M||PI(p[p.length-1],R)?LI(e,t,o,a,p,R,c,s):null,x=p[0].trimmed?p[0]:null;if(!x){let R=0;for(let M=Gk;M<=i&&!x;M+=Gk){let A=Mo(e,t,o,a*M,void 0,c(a*M),s);if(A.trimmed){let F=M;x=A;for(let T=0;T<6;T++){let P=.5*(R+F),S=Mo(e,t,o,a*P,void 0,c(a*P),s);S.trimmed?(F=P,x=S):R=P}}else R=M}x&&(x.driving=!0,p.push(x))}if(x){let R=Math.abs(x.steerDeg),M=Math.min(Sb,100/(o*o)),A=x;for(;R<i;){let F=Math.min(i,R+M),T=d(F,A);if(T){let L=y(T);if(L){g(L);break}if(p.push(T),F>=i||tM(e,a*F))break;Math.abs(T.beta-A.beta)<.5*Uu&&Math.abs(T.ay-A.ay)*De<.5*Xu&&(M=Math.min(Sb,1.5*M)),R=F,A=T;continue}if(M>vI){M*=.5;continue}let P=m,S=!1,w=null;for(let L of kI){let E=Math.min(i,R+L);if(E<=R)continue;let _=d(E,A);if(_){if(w=y(_,!0),w)break;p.push(_),R=E,A=_,M=Math.min(Sb,100/(o*o)),S=!0;break}}if(S)continue;if(w){g(w);break}h=R,f=P;let C=P?null:TI(e,t,o,a,p,c,s);C&&g(C);break}}else h=0;let k=p[0];for(let R of p)a*R.ay>a*k.ay&&(k=R);let v={states:p,foldDeg:h,rollover:f,peak:k,...b?{fold:b}:{}};if(l!==null){let R=Mb.get(e);R||(R=new WeakMap,Mb.set(e,R));let M=R.get(t);M||(M=new Map,R.set(t,M)),M.size>256&&M.clear(),M.set(l,v)}return v}var Mb=new WeakMap,RI=90,Uu=1.5,Xu=2.5,Sb=5,vI=.002,kI=[.5,1],Gk=2.5,Uk=.01,pn=.001,MI=.05,SI=.25,AI=5,wI=2,Kk=1e-8,FI=1e-7,CI=1e-6;function Xk(e,t,r,n,o,a,s){let i=n*ue,c=o.ay*De,l=b=>{let g=Zt(e,t,r,i,b*ue,c,qa(e,a(b),r,t));return{g:g.cn-s,ay:g.ay}},u=o.steerDeg,m=l(u),d=u+(u<0?-.001:.001),p=l(d),h=()=>p.g===0||Math.abs(d-u)<Kk;for(let b=0;b<40&&Math.sign(m.g)===Math.sign(p.g)&&!h();b++){let g=(p.g-m.g)/(d-u),y=g!==0?d-p.g/g:d+2*(d-u);if(!Number.isFinite(y))return null;let x=2*Math.abs(d-u)+.001;if(y=d+Math.max(-x,Math.min(x,y-d)),u=d,m=p,d=y,p=l(d),Math.abs(d-o.steerDeg)>wI)return null}let f={x:d,ay:p.ay};if(Math.sign(m.g)!==Math.sign(p.g)){let b=u,g=m.g,y=d,x=p.g;for(let k=0;k<60&&x!==0&&Math.abs(y-b)>Kk;k++){let v=(b*x-y*g)/(x-g),R=l(v);if(f={x:v,ay:R.ay},R.g===0)break;Math.sign(R.g)===Math.sign(g)?(b=v,g=R.g,x*=.5):(y=v,x=R.g,g*=.5)}}else if(!h())return null;return Math.abs(f.ay-o.ay)*De>Xu?null:{steerDeg:f.x,ay:f.ay}}function Gi(e,t,r,n,o){let a=jk(e,t,r,n.beta*ue,n.steerDeg*ue,n.ay*De,qa(e,o(n.steerDeg),r,t));return{...a,trimmed:!a.overturned,driving:!a.overturned}}function TI(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 d=qk(e,t,r,a,s),p=d(u.beta,u),h=d(c.beta,c);if(!p||!h)return null;let f=n*h.steerDeg>=n*p.steerDeg,b=f?p:h,g=f?h:p,y=f?m:-m,x=null;for(let R=Uk;Math.abs(g.beta-c.beta)<=Uu;R*=1.5){let M=d(g.beta+y*R);if(!M)return null;if(n*M.steerDeg<=n*g.steerDeg){x=M;break}b=g,g=M}if(!x)return null;let k=Qk(d,n,b,g,x);if(!k)return null;let v=Gi(e,t,r,k,a);return!v.trimmed||Math.abs(v.beta-c.beta)>Uu||Math.abs(v.ay-c.ay)*De>Xu?null:{state:v,sb:m}}function qk(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 PI(e,t){let r=Math.abs(t.beta-e.beta);return r>SI&&r>AI*Math.abs(t.steerDeg-e.steerDeg)}function LI(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],d=Math.sign(a.beta-l.beta);if(d===0||Math.sign(l.beta-m.beta)!==d||!m.driving)return null;let p=qk(e,t,r,s,i),h=p(m.beta,m),f=p(l.beta,l);if(!h||!f||n*f.steerDeg<n*h.steerDeg)return null;let b=h,g=f,y=null;for(let x=Uk;d*(a.beta-g.beta)>0;x=Math.min(MI,1.5*x)){let k=p(d*(a.beta-g.beta)>x?g.beta+d*x: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 R=Qk(p,n,...y);if(!R)return null;let M=Gi(e,t,r,R,s);return M.trimmed?{state:M,sb:d}:null}b=g,g=k}return null}function Qk(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,d=0;for(let p=0;p<100;p++){let h=.5*(s+i);if(Math.abs(c.beta-h)<=2*pn-.5*(i-s))break;let f=!0;if(Math.abs(m)>pn){let g=(c.beta-l.beta)*(a(c)-a(u)),y=(c.beta-u.beta)*(a(c)-a(l)),x=(c.beta-u.beta)*y-(c.beta-l.beta)*g;y=2*(y-g),y>0&&(x=-x),y=Math.abs(y);let k=m;if(m=d,Math.abs(x)<Math.abs(.5*y*k)&&x>y*(s-c.beta)&&x<y*(i-c.beta)){d=x/y;let v=c.beta+d;(v-s<2*pn||i-v<2*pn)&&(d=h>=c.beta?pn:-pn),f=!1}}f&&(m=c.beta>=h?s-c.beta:i-c.beta,d=Jk*m);let b=e(Math.abs(d)>=pn?c.beta+d:c.beta+(d>=0?pn:-pn));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 Pb(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],d=u[u.length-1],p=l(m),h=l(d);if(p>0||h<0)return null;if(h===0)return Gi(e,t,r,d,i);let f=m;for(let b=0;b<60&&Math.abs(d.beta-m.beta)>1e-9;b++){let g=(m.beta*h-d.beta*p)/(h-p),y=u[0];for(let R of u)Math.abs(R.beta-g)<Math.abs(y.beta-g)&&(y=R);let x=Xk(e,t,r,g,y,i,c);if(!x)return null;let k={beta:g,...x};u.push(k),f=k;let v=l(k);if(Math.abs(v)<("steerDeg"in a?FI:CI))break;v<0?(m=k,p=v,h*=.5):(d=k,h=v,p*=.5)}return Gi(e,t,r,f,i)}function DI(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 Pb(e,t,r,n.fold,a,{steerDeg:o});let u=typeof a.op=="function"?a.op(o):a.op,m=Mo(e,t,r,o,l,u,a.yawDemandCn??0);return m.driving?m:null}function EI(e,t,r,n,o,a){if(!n.trimmed)return!1;let s=n.steerDeg<0?-1:1,{states:i}=Ao(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)],d=Math.abs(m.steerDeg)-Math.abs(u.steerDeg),p=d>0?Math.min(1,Math.max(0,(c-Math.abs(u.steerDeg))/d)):0,h=u.beta+p*(m.beta-u.beta),f=u.ay+p*(m.ay-u.ay);return Math.abs(n.beta-h)<=1&&Math.abs(n.ay-f)<=.05}function Hn(e,t,r,n,o){let a=Math.max(8,r),s=n>=0?1:-1,i=Math.abs(n),c=(b,g)=>fn(e,t,a,s*b,g,o),l=Ao(e,t,a,{direction:s,op:o}),{fold:u}=l;if(u&&Math.abs(u.state.steerDeg)<=Ua){if(i>Math.abs(u.state.ay))return zk(e,t,a,s,i,o);if(i>Math.abs(u.stall.ay)){let b=Pb(e,t,a,u,{direction:s,op:o},{ayG:i});if(b)return b}}let m=l.states.filter(b=>Math.abs(b.steerDeg)<=Ua),d=m[m.length-1],p=l.states.length>m.length;p&&Math.abs(d.steerDeg)<Ua&&m.push(c(Ua,d));let h=m.findIndex(b=>Math.abs(b.ay)>=i);if(h===0)return fn(e,t,a,0,void 0,o);if(h>0)return Hk(m[h-1],m[h],i,c);let f=Zk(m,c,void 0,p||l.foldDeg===null);return f.ay>=i?Hk(f.below,f.state,i,c):l.foldDeg!==null&&l.foldDeg<Ua?zk(e,t,a,s,i,o):f.state}var Ua=20;function Hk(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 d=a.f===o.f?.5*(o.steer+a.steer):o.steer-o.f*(a.steer-o.steer)/(a.f-o.f),p=n(d,i),h=Math.abs(p.ay)-r;if(Math.abs(h)<u&&(l=p,u=Math.abs(h)),Math.abs(h)<=II||a.steer-o.steer<=_I)break;h<0?(o={steer:d,f:h},c===-1&&(a.f*=.5),c=-1):(a={steer:d,f:h},c===1&&(o.f*=.5),c=1)}return l}var II=1e-9,_I=1e-7;function Zk(e,t,r,n=!1){let o=r??0;if(r===void 0)for(let R=1;R<e.length;R++)Math.abs(e[R].ay)>Math.abs(e[o].ay)&&(o=R);let a=e[Math.max(0,o-1)],s=Math.abs(e[o].steerDeg),i=NI/4,c,l,u,m,d,p,h,f,b=null,g;if(o>0&&o<e.length-1){let R=e[o+1];g=F=>{if(F<s)return t(F,a);let T=t(F,e[o]);return T.ay===e[o].ay?t(F,a):T},c=Math.abs(a.steerDeg),l=Math.abs(R.steerDeg),u=s,m=-Math.abs(e[o].ay);let[M,A]=Math.abs(a.ay)>=Math.abs(R.ay)?[a,R]:[R,a];d=Math.abs(M.steerDeg),p=-Math.abs(M.ay),h=Math.abs(A.steerDeg),f=-Math.abs(A.ay)}else{let R=Math.abs(e[o].lockDeg??e[o].steerDeg),M=R-OI,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 F=t(s,a);return{state:F,below:a,ay:Math.abs(F.ay)}}g=F=>t(F,a),c=Math.abs(a.steerDeg),l=R,u=M,m=-Math.abs(A.ay),b=A,d=R,p=-Math.abs(e[o].ay),h=c,f=-Math.abs(a.ay)}let y=l-c,x=0;for(let R=0;R<100;R++){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-d)*(m-f),w=(u-h)*(m-p),C=(u-h)*w-(u-d)*S;w=2*(w-S),w>0&&(C=-C),w=Math.abs(w);let L=y;if(y=x,Math.abs(C)<Math.abs(.5*w*L)&&C>w*(c-u)&&C<w*(l-u)){x=C/w;let E=u+x;(E-c<2*i||l-E<2*i)&&(x=M>=u?i:-i),A=!1}}A&&(y=u>=M?c-u:l-u,x=Jk*y);let F=Math.abs(x)>=i?u+x:u+(x>=0?i:-i),T=g(F),P=-Math.abs(T.ay);P<=m?(F>=u?c=u:l=u,h=d,f=p,d=u,p=m,u=F,m=P,b=T):(F<u?c=F:l=F,P<=p||d===u?(h=d,f=p,d=F,p=P):(P<=f||h===u||h===d)&&(h=F,f=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 NI=.001,OI=.01,Jk=(3-Math.sqrt(5))/2;function zk(e,t,r,n,o,a){let s=l=>Math.abs(fn(e,t,r,n*l,void 0,a).ay),i=0,c=Ua;if(s(c)<o)return fn(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 fn(e,t,r,n*.5*(i+c),void 0,a)}function Lb(e,t,r,n,o){let a=Hn(e,t,r,n,o);return a.steering?Math.abs(a.steering.totalNm):NaN}function Db(e,t,r,n,o){if(!bo(e))return NaN;let a=n<0?-1:1,s=Math.abs(n),i=Hn(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,d=fn(e,t,r,a*u,void 0,o),p=fn(e,t,r,a*m,void 0,o),h=d.steering?Math.abs(d.steering.totalNm):NaN,f=p.steering?Math.abs(p.steering.totalNm):NaN,b=Math.abs(p.ay)-Math.abs(d.ay);if(Number.isFinite(h)&&Number.isFinite(f)&&b>=.01||l===.4&&Number.isFinite(h)&&Number.isFinite(f)&&b>.001)return(f-h)/b}return NaN}function wb(e,t,r,n,o,a){let s=Math.max(8,r),i=Zt(e,t,s,n*ue,o*ue,void 0,qa(e,a,s,t)),c=0;for(let l of br)c+=i.wheels[l].fxShort;return{ay:i.ay,cn:i.cn,fxShortfall:c}}function Eb(e,t,r,n,o){let a=Math.max(8,r),s=Hn(e,t,a,n,o),i=.5,c=wb(e,t,a,s.beta+i,s.steerDeg,o).cn,l=wb(e,t,a,s.beta-i,s.steerDeg,o).cn;return(c-l)/(2*i*ue)*e.massTotal*De*(e.wheelbase/1e3)}function Ib(e,t,r,n){let o=Math.max(8,r),{branch:a,opts:s}=VI(e,t,o,n);return eM(e,t,o,a,s)}function VI(e,t,r,n){if(!e.tv?.enabled||n?.balance){let s=n?{op:n}:{};return{branch:Ao(e,t,r,s),opts:s}}let o=Fb(e,t,r),a={op:s=>{let i=Cb(e,r,s,o);return i===0?n:{axG:n?.axG??0,driveFrontFrac:n?.driveFrontFrac,tvRearDiffN:i}}};return{branch:Ao(e,t,r,a),opts:a}}function eM(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 Gi(e,t,r,n.peak,a);let i=(l,u)=>Mo(e,t,r,l,u,a(l),s),c=n.states[0].driving||!n.peak.driving?n.states:n.states.slice(1);return Zk(c,i,c.indexOf(n.peak),n.foldDeg===null).state}function _b(e,t,r,n={}){let o=n.radius!==void 0&&n.radius>0&&Number.isFinite(n.radius)?n.radius:void 0,a=o===void 0?Math.max(8,r):Math.max(8,Math.sqrt(De*o)),s=(n.betaMaxDeg??10)*ue,i=(n.deltaMaxDeg??10)*ue,[c,l]=n.betaRangeDeg?[n.betaRangeDeg[0]*ue,n.betaRangeDeg[1]*ue]:[-s,s],[u,m]=n.deltaRangeDeg?[n.deltaRangeDeg[0]*ue,n.deltaRangeDeg[1]*ue]:[-i,i],{lf:d,lr:p}=Ab(e),h=o===void 0?0:p/o,f=o===void 0?0:(d+p)/o,b=n.nLines??9,g=n.nPts??21,y=n.steering!==!1&&bo(e),x=y?Nn(Fe(t,"front").model):void 0,k=(B,V,j,q)=>j===1?B:B+(V-B)*q/(j-1),v=e.tv?.enabled?Fb(e,t,a):0,R=B=>{let V=Cb(e,a,B/ue,v);return!n.axG&&V===0?null:qa(e,{axG:n.axG??0,driveFrontFrac:n.driveFrontFrac,tvRearDiffN:V},a,t)},{lf:M,lr:A}=Ab(e),F=n.reserves?Xa(t,e.massTotal*De*1.2):null,T=B=>F?Jr(F,{FL:B.FL,FR:B.FR,RL:B.RL,RR:B.RR},{lf:M,lr:A}):null,P=[],S={ay:[],cn:[]},w=0;for(let B=0;B<b;B++){let V=k(u,m,b,B),j=R(V),q=[],K=[],D=[],N=[],Y=F?{stabil:[],agil:[]}:void 0,H=y?Ok():void 0,W;for(let Z=0;Z<g;Z++){let xe=k(c,l,g,Z),de=Zt(e,t,a,xe,V,W,j,o);if(W=Number.isFinite(de.ay)?de.ay*De:void 0,q.push(de.ay),K.push(de.cn),D.push(xe/ue),N.push(V/ue),Y){let be=T(de.wheels);Y.stabil.push(be.stabil),Y.agil.push(be.agil)}H&&Vk(H,Nk(e,t,V,de.wheels)),Math.abs(de.ay)>w&&(w=Math.abs(de.ay))}P.push({label:`\u03B4 ${(V/ue).toFixed(0)}\xB0`,ay:q,cn:K,betaDeg:D,deltaDeg:N,reserve:Y,steering:H});let X=null,ne=1/0;for(let Z=1;Z<K.length;Z++){if(!Number.isFinite(K[Z-1])||!Number.isFinite(K[Z])||K[Z-1]!==0&&K[Z-1]<0==K[Z]<0)continue;let xe=K[Z-1]===K[Z]?0:K[Z-1]/(K[Z-1]-K[Z]),de=q[Z-1]+xe*(q[Z]-q[Z-1]);if(o===void 0&&V!==0&&Math.abs(de)>=.05&&Math.sign(de)!==Math.sign(V))continue;let be=Math.abs(D[Z-1]+xe*(D[Z]-D[Z-1])-h/ue);be<ne&&(ne=be,X=de)}X!==null&&(S.ay.push(X),S.cn.push(0))}let C=[];for(let B=0;B<b;B++){let V=k(c,l,b,B),j=[],q=[],K=[],D=[],N=F?{stabil:[],agil:[]}:void 0,Y=y?Ok():void 0,H;for(let W=0;W<g;W++){let X=k(u,m,g,W),ne=Zt(e,t,a,V,X,H,R(X),o);if(H=Number.isFinite(ne.ay)?ne.ay*De:void 0,j.push(ne.ay),q.push(ne.cn),K.push(V/ue),D.push(X/ue),N){let Z=T(ne.wheels);N.stabil.push(Z.stabil),N.agil.push(Z.agil)}Y&&Vk(Y,Nk(e,t,X,ne.wheels))}C.push({label:`\u03B2 ${(V/ue).toFixed(0)}\xB0`,ay:j,cn:q,betaDeg:K,deltaDeg:D,reserve:N,steering:Y})}let L=.5*ue,E=R(f),_,O;if(o===void 0)_=(Zt(e,t,a,h+L,f,void 0,E,o).cn-Zt(e,t,a,h-L,f,void 0,E,o).cn)/(2*L),O=(Zt(e,t,a,h,f+L,void 0,R(f+L),o).cn-Zt(e,t,a,h,f-L,void 0,R(f-L),o).cn)/(2*L);else{let B=(q,K)=>Zt(e,t,a,q,K,void 0,R(K),o).cn,V=(q,K,D)=>Number.isFinite(q)?(-3*q+4*K-D)/(2*L):(D-K)/L,j=B(h,f);_=-V(j,B(h-L,f),B(h-2*L,f)),O=V(j,B(h,f+L),B(h,f+2*L))}let I=0;if(E&&E.axG){let B=Zt(e,t,a,h,f,void 0,E,o),V=0;for(let j of br)V+=B.wheels[j].fxShort;I=V/Math.abs(e.massTotal*E.axG*De)}let z=S.ay.reduce((B,V)=>Math.max(B,Math.abs(V)),0);return{isoBeta:C,isoDelta:P,trim:S,maxAy:w,stability:_,control:O,speed:o===void 0?a:Math.sqrt(z*De*o),...o!==void 0?{radius:o}:{},axG:E?.axG??0,axShortfall:I,...x?{steeringAligningSource:x}:{}}}function tM(e,t){return wo(e,t*ue).atLock}function BI(e,t,r,n,o=mn(e,t,r)){let a=r,s=e.massTotal,i=br.filter(g=>Qt(g)?n.drivenFront:n.drivenRear),c=o.peakAt,l={front:n.drivenFront?qt(e,"front",1):void 0,rear:n.drivenRear?qt(e,"rear",1):void 0},u=new Map,m=(g,y)=>{let x=`${g}:${y}`,k=u.get(x);if(k===void 0){let v=Math.max(1,y*Oi);k=jt(Fe(t,g),v,0,!1,c(g,v)),u.set(x,k)}return k},d=(g,y)=>y>0?Ni(y,x=>m(g,x)):0,p=(g,y,x,k)=>{let v=Fe(t,g),R=E=>{let _=Math.max(0,x[E]),O=c(g,_);return{Fz:_,a:d(g,_),b:O.fyPeak,slide:0,cap:I=>_>0?jt(v,_,I,!1,O):0}},[M,A]=g==="front"?["FL","FR"]:["RL","RR"],F=R(M),T=R(A),P=k[M]*F.b,S=k[A]*T.b,w=F.cap(P)+T.cap(S),C=_i(F,T,P+S,y,w);return{l:M,r:A,full:C,asHeld:()=>({axle:g,strong:F.cap(P)>=T.cap(S)?M:A,full:C,open:_i(F,T,P+S,za,w),sense:1})}},h=g=>({muX:y=>y>0?d(g,y)/y:0,muY:y=>y>0?c(g,y).fyPeak/y:0}),f={front:h("front"),rear:h("rear")},b=g=>({arms:{lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},halfTrack:{front:e.trackFront/2e3,rear:e.trackRear/2e3},ayDir:Math.sign(g)});return{limitAt:(g,y,x,k=0)=>{let v={FL:0,FR:0,RL:0,RR:0},R=$e(e,g,0,a,0,y),M,A=I=>(M?.ax!==I&&(M={ax:I,loads:$e(e,g,(I+k)/De,a,0,y)}),M.loads),F=Zl(I=>Da(x,A(I),R,c).short,-k,1),T=x,P={FL:0,FR:0,RL:0,RR:0},S,w=I=>{let z=F.at(I);v=A(z),T=Da(x,v,R,c).util;let B={FL:0,FR:0,RL:0,RR:0};P=B;let V=0,j=n.diffYaw?{fx:{FL:0,FR:0,RL:0,RR:0},axles:[]}:null;for(let q of i){let K=l[dn(q)];if(K){if($i(q)){let H=p(dn(q),K,v,T);V+=H.full,B[H.l]=B[H.r]=H.full/2,j&&(j.fx[H.l]=j.fx[H.r]=H.full/2,j.axles.push(H.asHeld()))}continue}let D=Math.max(0,v[q]),N=c(dn(q),D),Y=jt(Fe(t,dn(q)),D,T[q]*N.fyPeak,!1,N);V+=Y,B[q]=Y,j&&(j.fx[q]=Y)}if(j){let q={};for(let K of br){let D=Math.max(0,v[K]);q[K]={Fz:D,Fy:T[K]*c(dn(K),D).fyPeak,Fx:j.fx[K]}}for(let K of j.axles){let D=yu(K,q,f,b(g))-K.full;V+=D;let[N,Y]=K.axle==="front"?["FL","FR"]:["RL","RR"];B[N]+=D/2,B[Y]+=D/2}}if(S)for(let q of S){let K=0;for(let D of q.wheels)K+=B[D];K>q.cap&&(V-=K-q.cap)}return V/s},C=()=>{let I=gk(w,-k,$n).fx,z=F.edge();return z!==void 0&&I>z&&(I=z,w(I)),{ax:I,loads:v,wheels:P}},L=C(),E=n.motorCaps;if(!E)return L;if(!E.some(I=>I.wheels.reduce((z,B)=>z+L.wheels[B],0)>I.cap))return{...L,held:L.ax};S=E;let O=C();return{...L,held:O.ax,heldWheels:O.wheels}}}}var Yu=.05,Yk=.001,Wk=16,qu=8;function Nb(e,t,r,n){let o=Math.max(qu,r),a=n.nSteer??7,s=e.tv?.enabled?Fb(e,t,o,n.steerMaxDeg):0,i=D=>{let N=Cb(e,o,D,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=Ao(e,t,o,l),m=D=>{let N={},Y={};for(let H of br)N[H]=D.wheels[H].slipDeg*ue,Y[H]=Math.min(1,D.wheels[H].gripUtil);return{steerDeg:D.steerDeg,ayMs:Math.max(0,D.ay*De),ayG:D.ay,slip:N,util:Y,scrub:D.ay>0?$I(D,e.massTotal):0}},d=null,p=D=>{if(d&&D===d.steerDeg)return m(d);let N=DI(e,t,o,u,D,l);if(N)return m(N);let Y=u.states[0];for(let H of u.states)H.steerDeg<=D&&(Y=H);return m(Y)},h=u.peak.driving&&u.peak.ay>0?eM(e,t,o,u,l):null,f=h?Math.max(0,h.ay*De):0,b=h?[...u.states.filter(D=>D.steerDeg<h.steerDeg),h]:u.states,g=h?b.findIndex(D=>D.ay*De>=.995*f):0,y=b[g].steerDeg,{fold:x}=u;if(h&&x&&u.peak===x.state){let D=.995*f/De,N=u.states.indexOf(x.stall),Y=N-1;for(;Y>0&&u.states[Y].beta===x.stall.beta;)Y--;let H=Math.sign(x.stall.beta-u.states[Y].beta),W=N;for(;W>0&&u.states[W].ay>=D&&Math.sign(u.states[W].beta-u.states[W-1].beta)!==-H;)W--;u.states[W].ay<D&&(d=Pb(e,t,o,x,l,{ayG:D},u.states.slice(W,N+1)))}if(d)y=d.steerDeg;else if(g>0){let D=b[g-1].steerDeg,N=y;for(let Y=0;Y<8&&N-D>.001;Y++){let H=.5*(D+N);p(H).ayMs>=.995*f?N=H:D=H}y=N}let k=[];for(let D=0;D<(f>0?a:1);D++){let N=D/(a-1);k.push(p(y*(N+Math.sin(Math.PI/2*N))/2))}k[0].ayMs=0;let v=[],R=[],M=[],A=[],F=[],T=mn(e,t,o,void 0,n.diffYaw===!0),P=BI(e,t,o,n,T),S=n.axDrag??0,w=D=>{let N=T.limitAt(D.ayMs/De,D.steerDeg,D.util,S+D.scrub);return{axD:N.edge!==void 0&&N.edge>0?N.edge:N.ax,locked:N.axUnlocked-N.ax>Yu}},C=D=>{let N=P.limitAt(D.ayMs/De,D.steerDeg,D.util,S+D.scrub);return{axA:N.ax,wA:{wheels:N.wheels,held:N.held??N.ax,...N.heldWheels?{heldWheels:N.heldWheels}:{}}}},L=k.map(D=>({p:D,...C(D),...w(D)})),E=[];for(let D=0;D+1<L.length;D++){let N=L[D],Y=L[D+1],H=[];N.locked!==Y.locked?H.push({read:w,past:W=>W.locked===Y.locked,braking:!0}):(Y.axA>N.axA+Yu&&H.push({read:C,past:W=>(W.axA??-1/0)>N.axA}),-Y.axD>-N.axD+Yu&&H.push({read:w,past:W=>-(W.axD??0)>-N.axD}));for(let{read:W,past:X,braking:ne}of H){let Z=N.p.steerDeg,xe=Y.p.steerDeg,de=null,be=N.axD,U=Y.axD;for(let ee=0;ee<Wk&&xe-Z>Yk&&!(ne&&Math.abs(U-be)<=Yu);ee++){let se=.5*(Z+xe),ie=p(se),Re=W(ie);X(Re)?(xe=se,de={p:ie,r:Re},U=Re.axD??U):(Z=se,be=Re.axD??be)}if(de){let{p:ee,r:se}=de,ie=se.axD!==void 0&&se.locked!==void 0?{axD:se.axD,locked:se.locked}:w(ee),Re=se.axA!==void 0&&se.wA!==void 0?{axA:se.axA,wA:se.wA}:C(ee);E.push({p:ee,...Re,...ie})}}}L.push(...E),L.sort((D,N)=>D.p.steerDeg-N.p.steerDeg);let _=D=>D.axA+S+D.p.scrub,O=.001*Math.max(1,k[k.length-1].ayMs),I=[];for(let D=0;D+1<L.length;D++){let N=L[D],Y=L[D+1];if(!(_(N)>=0&&_(Y)<0))continue;let H=N.p.steerDeg,W=Y.p.steerDeg,X=null,ne=null;for(let de=0;de<Wk&&W-H>Yk;de++){let be=.5*(H+W),U=p(be),ee=C(U);_({p:U,axA:ee.axA})>=0?(H=be,X={p:U,wA:ee.wA}):(W=be,ne={p:U,wA:ee.wA})}let Z=X??ne,xe=Z?.p;if(Z&&xe&&xe.ayMs>N.p.ayMs&&xe.ayMs<Y.p.ayMs){let de=-(S+xe.scrub);I.push({p:xe,axA:de,wA:{wheels:Z.wA.wheels,held:Math.min(Z.wA.held,de)},steady:!0,...w(xe)})}}L.push(...I),L.sort((D,N)=>D.p.steerDeg-N.p.steerDeg);let z=!1;for(let{p:D,axA:N,wA:Y,axD:H,steady:W}of L){let X=v.length-1,ne=X>=0&&(W||z?!(D.ayMs>v[X]):D.ayMs-v[X]<O);z=W===!0&&!ne,ne?(N>R[X]&&(M[X]=Y),R[X]=Math.max(R[X],N),A[X]=Math.min(A[X],H)):(v.push(D.ayMs),R.push(N),M.push(Y),A.push(H),F.push(D.scrub))}for(let D=v.length-2;D>=0;D--)R[D+1]>R[D]&&(M[D]=M[D+1]),R[D]=Math.max(R[D],R[D+1]),A[D]=Math.min(A[D],A[D+1]);let B=v[v.length-1],V=e.massTotal,j=M.map(({wheels:D})=>({FL:D.FL/V,FR:D.FR/V,RL:D.RL/V,RR:D.RR/V})),q=D=>D?{FL:D.FL/V,FR:D.FR/V,RL:D.RL/V,RR:D.RR/V}:void 0,K=n.motorCaps?{axAccelHeld:M.map(D=>D.held),axAccelWheelsHeld:M.map(D=>q(D.heldWheels))}:{};return{ayMax:B,ay:v,axAccel:R,axAccelWheels:j,...K,axDecel:A,axScrub:F,rollover:u.rollover,atLock:h!==null&&tM(e,h.steerDeg)}}function $I(e,t){let r=e.beta*ue,n=0;for(let o of br){let a=e.wheels[o],s=a.steerDeg*ue-r;n+=a.Fx*(Math.cos(s)-1)-a.Fy*Math.sin(s)}return n/t}var kX=Math.PI/180,MX={speeds:Array.from({length:23},(e,t)=>8+t),steerMaxDeg:14,steerSteps:29};function nM(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 Qa={enabled:!1,kp:3e3,ffLow:150,ffHigh:300,vLow:18,vHigh:25},rM=e=>nM(e.ffLow,e.ffHigh,e.vLow,e.vHigh);var Er={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"}},GI=["k_yaw","k_roll","k_pitch"];function Hi(e){for(let t of GI)delete e[t];for(let t of Object.keys(Er)){let r=e[t];if(!r){e[t]={...Er[t]};continue}e[t]={...r,label:Er[t].label,unit:Er[t].unit}}return e}function re(e,t){return e[t]?.value??Er[t].value}function Qu(e){let t=(r,n)=>e[r]?.value??n;return{enabled:t("tv_enabled",0)>=.5,kp:t("tv_kp",Qa.kp),ffLow:t("tv_ff_low",Qa.ffLow),ffHigh:t("tv_ff_high",Qa.ffHigh),vLow:t("tv_v_low",Qa.vLow),vHigh:t("tv_v_high",Qa.vHigh)}}var oM=[10,25,50,100,200,300];function Ob(e,t,r,n,o){let s=oM.map(i=>Math.round(i<=25?r*i:r*25+n*(i-25)));return{id:e,label:t,speedMmS:[...oM],reboundN:s,bumpN:s.map(i=>Math.round(i*o))}}var Zu={name:"Generic FS damper",curves:[Ob("c1","Soft",1.6,1,.65),Ob("c2","Medium",3,1.6,.65),Ob("c3","Firm",8,2.4,.65)]};function Ju(e){let t=e.curves.length;return t>0?e.curves[Math.floor((t-1)/2)].id:""}var zn=25;function Za(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 aM(e,t){return t>=0?Za(e.rebound,t):-Za(e.bump,-t)}function sM(e,t,r){return t*aM(e,t*r)}var Vb=(e,t)=>e.curves.find(r=>r.id===t);function zi(e,t){let r=Vb(e,Ju(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 em=5e3;function Yi(e,t){let r=t>0?t:1,n=[],o=[],a=e.bump.speedMmS.map(c=>c/r).filter(c=>c<em),s=e.rebound.speedMmS.map(c=>c/r).filter(c=>c<em),i=c=>{n.push(c),o.push(sM(e,r,c))};i(-em);for(let c=a.length-1;c>=0;c--)i(-a[c]);i(0);for(let c of s)i(c);return i(em),{kind:"map",input:"velocity",x:n,y:o}}var Bb=64;function Wi(e,t,r){let n=t>0?t:1,o=Math.max(r,1e-6),a=0;for(let s=0;s<Bb;s++){let i=Math.sin((s+.5)*Math.PI/Bb),c=n*o*i;a+=n*(Za(e.rebound,c)+Za(e.bump,c))*i}return a*(Math.PI/Bb)/(Math.PI*o)}function Fo(e,t,r,n,o=e){let a=(c,l,u)=>{if(!c||c.curves.length===0)return;let m=zi(c,l);return{law:m,curve:Yi(m,u),rate:Wi(m,u,zn)}},s=a(e,t?.front,r),i=a(o??e,t?.rear,n);return!s&&!i?null:{...s?{front:s}:{},...i?{rear:i}:{}}}var iM=(e,t)=>({...e,y:e.y.map(r=>r*t)}),KI=e=>({...e,x:e.x.map(t=>-t).reverse(),y:e.y.map(t=>-t).reverse()});function $b(e,t,r){let n=Math.abs(r)>0?Math.abs(r):1,o=zi(e,t);return{law:o,curve:iM(Yi(o,n),.5),rate:Wi(o,n,zn)/2,mr:n,ratio:n,share:.5}}function Gb(e,t,r,n,o){let a=n*(Math.abs(r)>0?Math.abs(r):1),s=zi(e,t),i=iM(Yi(s,a),1/n);return{law:s,curve:o?KI(i):i,rate:Wi(s,a,zn)/n,mr:a/n,ratio:a,share:1/n}}function ji(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 tm=["front","rear","heaveFront","heaveRear","rollFront","rollRear"];function Ui(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 hn(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 qi(e){return e.kind==="coil"?2:1}function Xi(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 lM(e){return Xi(e)/2}function uM(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 cM(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 HI(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 Qi(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*Xi(e.section)/e.barLength,a=2*o/(n*n),s=lM(e.armSection??e.section),i=3*e.E*s/n**3,c=e.dropLinkRate??1/0;return{rateAtLink:cM([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*Xi(e.section)/e.barLength,a=2*o/(n*n),s=3*e.E*uM(e.blade)/n**3,i=e.dropLinkRate??1/0;return{rateAtLink:cM([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*Xi(e.section)/e.length,a=2*o/(n*n);return{rateAtLink:a,contributions:{barTwist:a},torsional:o}}case"coil":{let n=hn(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=HI(e.linkTravel,e.force,t);return{rateAtLink:Math.max(0,n),contributions:{},torsional:0}}}}function rm(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?Af(t,r):1,o=t?wf(t,r):0,a=Qi(e,o).rateAtLink;return{wheelRate:Math.max(0,a*n*n),motionRatio:n,rateAtLink:a}}function Zi(e,t){let r=e.damper??0;return!r||e.design.kind==="none"?0:qi(e.design)*r*t*t}var zI=150;function YI(e){return J(e,[0,-.5,1])<-1e-9?Q(e,-1):e}function mM(e){let t=e.hardpoints,r=G(t.rockerPivotB,t.rockerPivotA),n=oe(t.rockerPivotA,Q(G(t.rockerToDamper,t.rockerPivotA),.6)),o=YI(te(le(r,G(t.rockerToDamper,t.rockerPivotA))));return{outer:n,inner:oe(n,Q(o,zI)),attach:"rocker"}}function Jt(e,t){let r={};for(let o of wr)r[o]=gt(Qe(e,o));let n={vehicle:e,ctx:r};return t&&(n.kc=Wl(n,t)),n}function WI(e,t,r,n){let o=e.corner.hardpoints,a=xa(e.rocker,t.points.rockerAngle),s=i=>Wt(i,r);return{ucaFront:s(o.ucaFront),ucaRear:s(o.ucaRear),lcaFront:s(o.lcaFront),lcaRear:s(o.lcaRear),tieInner:s(io(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:qr(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 nm(e,t,r,n){let o=nt(t,e.vehicle.config),a=o.isFront?o.sideSign*n:0,s;try{s=Lt(we(e.ctx[t],r,a))}catch{return null}if(!s)return null;let i=Qe(e.vehicle,t).config.loadedRadius,c=WI(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 om=.5;function jI(e,t){let r=([i,c,l])=>{let u=te(G(c,i)),m=G(l,i),d=te(G(m,Q(u,J(m,u))));return[u,d,le(u,d)]},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=G(i,e[0]);return oe(t[0],[0,1,2].map(l=>a[l][0]*c[0]+a[l][1]*c[1]+a[l][2]*c[2]))}}}var pM=e=>[(e[2][1]-e[1][2])/2,(e[0][2]-e[2][0])/2,(e[1][0]-e[0][1])/2];function am(e,t,r){let n=nt(t,e.vehicle.config),o=e.ctx[t],a=r.rigid?void 0:{loadedRadius:r.loadedRadius},s=r.state?null:we(o,r.travel,r.steer,void 0,a),i=r.state??St(s),c=we(o,r.travel+om,r.steer,void 0,a),l=we(o,r.travel-om,r.steer,void 0,a),u=(s?s.ok:r.converged)&&c.ok&&l.ok,m=St(c),d=St(l),p=(T,P)=>Wt(T.points[P],n),h=o.inv.strut?"pushrodOuter":"uprightUpper",f=p(i,h),b=p(i,"uprightLower"),g=T=>{let P=G(b,f);return Math.hypot(...le(P,G(p(i,T),f)))/Math.hypot(...P)},y=g("tieOuter")>=g("wheelCenter")?"tieOuter":"wheelCenter",x=[f,b,p(i,y)],k=T=>jI(x,[p(T,h),p(T,"uprightLower"),p(T,y)]),v=k(m),R=k(d),M=pM(v.rot),A=pM(R.rot),F=[NaN,NaN,NaN];return{solved:u,state:i,at:T=>p(i,T),velocity:T=>u?Q(G(v.move(T),R.move(T)),1/(2*om)):F,omega:u?Q(G(M,A),1/(2*om)):F}}function Kb(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 dM(e,t,r){let n=am(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 fM(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 hM(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 UI(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 XI=.1*Math.PI/180;function bM(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]))*XI<=o*n}function sm(e,t){return!e.valid||!e.cpLeft||!e.cpRight?!1:bM([e.lateral,e.height],e.cpLeft,e.cpRight,e.sinAngle,t)}function Ji(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 qI=1;function gM(e){let t=Ji(e);if(!t||!e.cpLeft||!e.cpRight||Math.abs(t.left-t.right)>qI)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 Ja(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 Ir(e,t,r){let n=r==="front"?"FL":"RL",o=r==="front"?"FR":"RR",a=dM(e,n,t),s=dM(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=fM(a),c=fM(s),l=hM(a,i),u=hM(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 d=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,h=Math.hypot(d[0],d[1]),f=Math.hypot(p[0],p[1]),b=h>0&&f>0?Math.abs(d[0]*p[1]-d[1]*p[0])/(h*f):0,g=Kb(a.cp,d,s.cp,p)??UI(a.cp,l,s.cp);if(!g)return{...m,sinAngle:b};let y=s.cp[0]-a.cp[0],x=s.cp[1]-a.cp[1],k=Math.hypot(y,x)||1,v=y/k,R=x/k,M=(a.cp[0]+s.cp[0])/2,A=(a.cp[1]+s.cp[1])/2,F=(g[0]-a.cp[0])*-R+(g[1]-a.cp[1])*v,T=(g[0]-M)*v+(g[1]-A)*R;return{lateral:g[0],height:g[1],heightAboveGround:F,lateralAlongGround:T,valid:!0,icLeft:i,icRight:c,lineLeft:l,lineRight:u,sinAngle:b,cpLeft:a.cp,cpRight:s.cp}}function bn(e,t){return{front:Ir(e,t,"front"),rear:Ir(e,t,"rear")}}function im(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 QI(e,t){return{camber:im(e.travel,e.camber,t),toe:im(e.travel,e.toe,t),motionRatio:im(e.travel,e.motionRatio,t),damperLen:e.damperLen?im(e.travel,e.damperLen,t):0}}var yM=e=>QI(e,0).motionRatio;function Hb(e,t){if(e.kind!=="coil")return null;let r=t??e.motionRatio,n=hn(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 cm(e,t){if(e.kind==="none")return 0;if(e.kind==="tabulated"){let n=a=>ZI(e,a);return(n(.5)-n(-.5))/(2*.5)/2}if((e.gap??0)>0)return 0;let r=t??e.motionRatio;return hn(e.rate,0)*r*r/2}function ec(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 ZI(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 zb={kind:"coil",rate:120,motionRatio:.7,gap:5,bothWays:!1};var xM=new WeakMap;function um(e,t){let r=xM.get(e);r||(r=new Map,xM.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=co(e,t);return r.set(n,a),a}var JI=32,tc=new Map,RM=new WeakMap,e2=1;function t2(e){let t=RM.get(e);return t===void 0&&(t=e2++,RM.set(e,t)),t}function Yb(e,t){if(!t.linkage)return null;let r=_n(e,t.linkage,t.design.kind),n=`${t2(e)}|${r?"unit":"bar"}|${JSON.stringify(t.linkage)}`,o=tc.get(n);if(o)return o;let a=Aa(e,t.linkage,{kind:t.design.kind});return tc.size>=JI&&tc.delete(tc.keys().next().value),tc.set(n,a),a}function To(e,t,r=0){let n=(o,a)=>{if(!(!o||o.design.kind==="none"))return rm(o.design,Yb(a,o),r).wheelRate};return{front:n(t.arbFrontDesign,e.front),rear:n(t.arbRearDesign,e.rear)}}function es(e,t){let r=(n,o)=>{if(!n||n.design.kind==="none")return;let a=n.linkage?um(o,n.linkage).atDesign:void 0;return cm(n.design,a)};return{front:r(t.heaveFrontDesign,e.front),rear:r(t.heaveRearDesign,e.rear)}}function AM(e,t){let r=(a,s)=>{if(!a||a.design.kind!=="coil")return;let i=a.linkage?um(s,a.linkage).atDesign:void 0;return Hb(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 mm(e,t){let r=(o,a)=>o?ec(o,Wb(o,a)):0,n=(o,a)=>o?Zi(o,jb(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 Wb=(e,t)=>e.linkage?um(t,e.linkage).atDesign:void 0,jb=(e,t)=>rm(e.design,Yb(t,e),0).motionRatio;function wM(e,t){let r=t.damperSetup,n=t.heaveDamperModel??t.damperModel,o=t.rollDamperModel??t.damperModel,a=(d,p,h)=>{if(!d||!n?.curves.length)return;let f=Wb(d,p);if(ec(d,f)>0)return $b(n,r?.[h],f??(d.design.kind==="coil"?d.design.motionRatio:1))},s=(d,p,h)=>{if(!d||!o?.curves.length)return;let f=jb(d,p);if(!(Zi(d,f)>0))return;let b=Yb(p,d)!==null;return Gb(o,r?.[h],f,qi(d.design),b&&f>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 pm(e,t){let r=t.heaveDamperModel??t.damperModel,n=t.rollDamperModel??t.damperModel,o=(i,c)=>Co(i)?{source:"none"}:Ui(i.config.coilover,c),a=(i,c)=>{if(!i)return{source:"none"};let l=ec(i,Wb(i,c))>0;return Ui(i.coilover,l?r:void 0)},s=(i,c)=>{if(!i||i.design.kind!=="coil")return{source:"none"};let l=Zi(i,jb(i,c))>0;return Ui(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 FM(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 Co=e=>e.config.actuation==="decoupled",Po="a decoupled axle damps in its heave and roll elements, set below";function CM(e,t,r={}){let n={...t},o=(m,d)=>{let p=n[m];p&&typeof p=="object"&&"value"in p&&(n[m]={...p,value:d})},{front:a,rear:s}=To(e,t);a!==void 0&&o("arb_front",a),s!==void 0&&o("arb_rear",s);for(let[m,d,p]of[[t.heaveFrontDesign,e.front,"heave_spring_front"],[t.heaveRearDesign,e.rear,"heave_spring_rear"]]){if(!m||m.design.kind==="none")continue;let h=m.linkage?um(d,m.linkage).atDesign:void 0;o(p,cm(m.design,h))}let i=n2(e,t,r),c=r2(e,i);n.kinFront=c.kinFront,n.kinRear=c.kinRear;let l=s2(e,i);n.steerFront=c.steerFront,Number.isFinite(l.ackermannPct)&&o("ackermann_pct",l.ackermannPct);let u=m=>Co(m)?0:m.measured?.springRate??m.config.springRate;o("spring_front",u(e.front)),o("spring_rear",u(e.rear));for(let[m,d]of[[e.front,"spring_front"],[e.rear,"spring_rear"]])Co(m)&&(n.readouts={...n.readouts,[d]:"a decoupled axle has no corner spring; its heave and roll elements carry the car"});for(let[m,d]of[[e.front,"damper_front"],[e.rear,"damper_rear"]])Co(m)&&(o(d,0),n.readouts={...n.readouts,[d]:Po});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 r2(e,t){return{kinFront:kM(e.front),kinRear:kM(e.rear),steerFront:e.front.measured?void 0:dm(e.front,t)}}var vM=new WeakMap;function kM(e){let t=vM.get(e);return t||vM.set(e,t=Na(e)),t}function n2(e,t,r={}){return o2(e,t,r.front,r.rear)}function o2(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 fm(a,r,n).front??o}var MM=new WeakMap;function dm(e,t=e.config.loadedRadius){let r=MM.get(e);r||(r=new Map,MM.set(e,r));let n=r.get(t);if(n)return n;let o=t===e.config.loadedRadius?void 0:{loadedRadius:t},a=Yf(e,Bt(e.config),void 0,void 0,void 0,void 0,o);return r.size>=4&&r.clear(),r.set(t,a),a}var SM=new WeakMap;function a2(e){return ot(e,{travelMin:-1,travelMax:1,steps:3}).samples[1].metrics.motionRatio??1}var lm=e=>e.measured?yM(e.measured):a2(e);function s2(e,t=e.front.config.loadedRadius){let r=()=>e.front.measured?void 0:dm(e.front,t);return{...i2(e),get steerFront(){return r()},get ackermannPct(){let n=r();return n?Wf(n,Ot(e.front),e.config.wheelbase):Number.NaN}}}function i2(e){let t=SM.get(e);if(t)return t;let r=e.front.measured,n=e.rear.measured,a=!r||!n?bn(Jt(e),{heave:0,pitch:0,roll:0,steer:0}):null,s={wheelbase:e.config.wheelbase,trackFront:r?r.track:Ot(e.front),trackRear:n?n.track:Ot(e.rear),mrFront:lm(e.front),mrRear:lm(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:Ja(a.front),rcGainRear:n||!a?0:Ja(a.rear),rcFrontValid:r?!0:!!a?.front.valid,rcRearValid:n?!0:!!a?.rear.valid};return SM.set(e,s),s}var Gt={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}},LM=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),_r=(e,t,r,n=1/0)=>typeof e=="number"&&Number.isFinite(e)?Math.min(n,Math.max(r,e)):t;function Lo(e){if(LM(e))switch(e.kind){case"open":case"spool":return{kind:e.kind};case"clutch":{let t=Gt.clutch;return{kind:"clutch",preloadNm:_r(e.preloadNm,t.preloadNm,0),rampDriveDeg:_r(e.rampDriveDeg,t.rampDriveDeg,1,90),rampCoastDeg:_r(e.rampCoastDeg,t.rampCoastDeg,1,90),faces:Math.round(_r(e.faces,t.faces,0)),muClutch:_r(e.muClutch,t.muClutch,0,1),rFrictionMm:_r(e.rFrictionMm,t.rFrictionMm,1),rRampMm:_r(e.rRampMm,t.rRampMm,1)}}case"torsen":{let t=Gt.torsen,r=_r(e.preloadNm,0,0);return{kind:"torsen",tbrDrive:_r(e.tbrDrive,t.tbrDrive,1),tbrCoast:_r(e.tbrCoast,t.tbrCoast,1),...r>0?{preloadNm:r}:{}}}default:return}}function hm(e){if(!LM(e))return;let t=Lo(e.front),r=Lo(e.rear);return t||r?{...t?{front:t}:{},...r?{rear:r}:{}}:void 0}function Do(e){let t=hr(e),r=n=>n>=2?"independent":n===1?"diff":"none";return{front:r(t.front),rear:r(t.rear)}}function rc(e){if(!e.driveline)return;let t=Do(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:Ii(i,"drive",r),coast:Ii(i,"coast",r),hubs:Ii(i,"hubs",r)}},o=n("front"),a=n("rear");return o||a?{...o?{front:o}:{},...a?{rear:a}:{}}:void 0}var c2={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"}},TM=e=>{let t=e==="front"?"Front":"Rear";return Object.fromEntries(Object.entries(c2).map(([r,n])=>[`${e}.${r}`,{section:t,...n}]))},bm={...TM("front"),...TM("rear")},PM=e=>e.motorModel?.kind==="ice"?e.motorPlacement==="front"?"front":"rear":null;function DM(e,t){let r=PM(t);if(!(!r||PM(e)===r||t.driveline?.[r]))return{...t.driveline,[r]:{...Gt.clutch}}}function cr(e,t,r,n){return e>0?!(r>0)||!Number.isFinite(r)?e:Math.max(1,e-t/r):n}function gm(e,t,r){let n=Math.max(0,Math.min(1,r)),o=cr(e.freeRadius,e.staticLoad,e.tyreRate,e.surveyed),a=cr(t.freeRadius,t.staticLoad,t.tyreRate,t.surveyed);return n*o+(1-n)*a}function ts(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 gn(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 nc(e,t){if(!e)return u2(t);let r=t-On(e,0).camber;return r?{...e,camber:e.camber.map(n=>n+r)}:e}function l2(e){return{kinFront:nc(e.kinFront,re(e,"camber_front_deg")),kinRear:nc(e.kinRear,re(e,"camber_rear_deg"))}}function u2(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 EM=9.81,IM=e=>e>1?e/100:e;function Eo(e,t,r){let n=t??e.tireModel??yi(),o=r??e.tireModelRear??n,a={grip:re(e,"grip_scale"),stiffness:re(e,"stiffness_scale")},s=Ru(n,a);return{front:s,rear:o===n?s:Ru(o,a)}}function Nr(e,t,r){let n=Eo(e,t,r),o=_e(n.front);return Dt(n.rear===n.front?o:lu(o,_e(n.rear)))}function Ub(e,t,r){let n=IM(e.front_mass_diss.value),o=Eo(e,t,r),a=_e(o.front),s=o.rear===o.front?a:_e(o.rear),i=t??e.tireModel,c=r??e.tireModelRear??i,l=e.m.value*EM*n/2,u=e.m.value*EM*(1-n)/2,m=(i?a.verticalStiffness():0)||re(e,"tire_vertical_rate"),d=(c?s.verticalStiffness():0)||re(e,"tire_vertical_rate"),p=Pr(i)??0,h=Pr(c)??0,f=e.surveyedRadiusFront&&e.surveyedRadiusRear?gm({freeRadius:p,staticLoad:l,tyreRate:m,surveyed:e.surveyedRadiusFront},{freeRadius:h,staticLoad:u,tyreRate:d,surveyed:e.surveyedRadiusRear},n):void 0,b=e.surveyedRadiusFront?cr(p,l,m,e.surveyedRadiusFront):void 0,g=e.surveyedRadiusRear?cr(h,u,d,e.surveyedRadiusRear):void 0;return{ev:a,evR:s,Wf:l,Wr:u,tireRate:m,tireRateRear:d,tyreFreeRadius:p,tyreFreeRadiusRear:h,cgStandingRadius:f,standingFront:b,standingRear:g}}function fm(e,t,r){let n=Ub(e,t,r);return{front:n.standingFront,rear:n.standingRear}}function _M(e,t,r){return Ub(e,t,r).cgStandingRadius}function It(e,t,r){let n=IM(e.front_mass_diss.value),o=re(e,"mr_front")||1,a=re(e,"mr_rear")||1,{ev:s,evR:i,Wf:c,Wr:l,tireRate:u,tireRateRear:m,tyreFreeRadius:d,tyreFreeRadiusRear:p,cgStandingRadius:h,standingFront:f,standingRear:b}=Ub(e,t,r),g=Di(e),y=rc(e),x=Fo(e.damperModel,e.damperSetup,o,a,e.damperModelRear??e.damperModel),k=e.readouts?.damper_front===Po,v=e.readouts?.damper_rear===Po,R={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,re(e,"cop_long"))),copHeight:re(e,"cop_height"),...e.aeroModel?{model:e.aeroModel}:{},rideHeightFront:re(e,"ride_height_front"),rideHeightRear:re(e,"ride_height_rear")};return{massTotal:e.m.value,frontMassFrac:n,steeringSystem:e.steeringSystem,tv:Qu(e),cgHeight:ts(re(e,"cg_height"),e.cgReference?.standingRadius,h),...h!==void 0?{cgStandingRadius:h}:{},wheelbase:re(e,"wheelbase"),trackFront:re(e,"track_front"),trackRear:re(e,"track_rear"),wheelRateFront:re(e,"spring_front")*o*o,wheelRateRear:re(e,"spring_rear")*a*a,tireRate:u,...m!==u?{tireRateRear:m}:{},tireDamping:re(e,"tire_vertical_damping"),arbFront:re(e,"arb_front"),arbRear:re(e,"arb_rear"),brakeBalanceFront:g.balanceFront,brakes:g,...y?{driveline:y}:{},heaveSpringFront:re(e,"heave_spring_front"),heaveSpringRear:re(e,"heave_spring_rear"),unsprungPerCorner:re(e,"unsprung_mass"),unsprungCgHeight:m2(e,{Wf:c,Wr:l,tireRate:u,tireRateRear:m,tyreFreeRadius:d,tyreFreeRadiusRear:p,standingFront:f,standingRear:b}),tyreFreeRadius:d,...p!==d?{tyreFreeRadiusRear:p}:{},rcHeightFront:gn(re(e,"rc_front"),e.rcRoad?.gainFront,e.rcRoad?.radiusFront,f),rcHeightRear:gn(re(e,"rc_rear"),e.rcRoad?.gainRear,e.rcRoad?.radiusRear,b),corneringStiffnessFront:s.corneringStiffness(c),corneringStiffnessRear:i.corneringStiffness(l),damperFront:x?.front&&!k?x.front.rate:re(e,"damper_front")*o*o,damperRear:x?.rear&&!v?x.rear.rate:re(e,"damper_rear")*a*a,...x?.front&&!k?{damperCurveFront:x.front.curve}:{},...x?.rear&&!v?{damperCurveRear:x.rear.curve}:{},aero:R,ackermannPct:re(e,"ackermann_pct"),toeFrontDeg:re(e,"toe_front_deg"),toeRearDeg:re(e,"toe_rear_deg"),yawInertia:re(e,"I_yaw"),steerFront:e.steerFront,...l2(e)}}function m2(e,t){let r=(a,s,i,c)=>a??(s>0?cr(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 ym={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 NM(e,t=e.batteryModel){if(!t)return e;let r=jr(t),n=(o,a)=>({...o,value:a});return{...e,capacity:n(e.capacity,r.capacityAh),ocv:n(e.ocv,r.voltageAtFull)}}var VM={damper_front:`the damper part sets it: its front curve at ${zn} mm/s`,damper_rear:`the damper part sets it (the rear's own, where the car names one): its rear curve at ${zn} mm/s`};function xm(e){let t=!!(e.damperModelId||e.damperModel),r=t||!!(e.damperModelIdRear||e.damperModelRear);return{...t?{damper_front:VM.damper_front}:{},...r?{damper_rear:VM.damper_rear}:{}}}function BM(e,t=e.damperModel,r=e.damperModelRear??t){if(!t&&!r)return e;let n=re(e,"mr_front")||1,o=re(e,"mr_rear")||1,a=Fo(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!==Po&&(i.damper_front=s(e.damper_front,"damper front",a.front.rate/(n*n))),a.rear&&e.readouts?.damper_rear!==Po&&(i.damper_rear=s(e.damper_rear,"damper rear",a.rear.rate/(o*o))),i}var $M={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 yn(e){return!!e&&typeof e=="object"&&"value"in e&&"label"in e}var h2={Batteriekapazit\u00E4t:"pack capacity",Rollwiderstandsbeiwert:"rolling-resistance coefficient"},KM=e=>h2[e]??e;function Rm(e){let t=[];for(let r of Object.keys(e)){if(r==="motor"||r==="name")continue;let n=e[r];yn(n)&&t.push({key:r,label:KM(n.label),value:n.value,unit:n.unit})}return t}var b2=[{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"]}],g2=.5,GM=e=>e==="infinite"?1/0:typeof e=="number"?e:null,y2=e=>/front/.test(e)?e.replace("front","rear"):/rear/.test(e)?e.replace("rear","front"):null,rQ=(()=>{let e=$M.rows,t=o=>{let a=y2(o),s=GM(e[o]?.score),i=a&&e[a]?GM(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>=g2&&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 Xb={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 HM(e){let t=new Map;for(let a of Rm(e))t.set(a.key,a);let r=new Set,n=[];for(let a of b2){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=Rm(e).filter(a=>!r.has(a.key));return o.length&&n.push({title:"Other",rows:o}),n}var qb={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"},Qb={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"},zM=e=>!!(e.aeroModelId||e.aeroModel);function x2(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 R2=e=>!!(e.batteryModelId||e.batteryModel),YM={capacity:"an engine car has no pack",ocv:"an engine car has no pack",soc:"an engine car has no pack",power_limit_kw:"an engine car has no pack, and the power rule is the electric class\u2019s",endurance_reserve:"an engine car has no pack to finish with a reserve of",I_rotor:"the engine model refers its own crank through each gear"},nQ=Object.keys(YM);function Zb(e){if(!(e.motorModelId||e.motorModel))return{};let t=pt(e.motorModel),r={effi_pgb:"the motor model states its own efficiency",...t?YM:{}};return(e.motorCount!=null||t)&&(r.driven_wheels="the motor layout in Powertrain sets which wheels are driven"),r}function v2(e,t){let r={};return t.geometry&&Object.assign(r,Xb,x2(e)),zM(e)&&Object.assign(r,qb),R2(e)&&Object.assign(r,ym),Object.assign(r,Zb(e)),Object.assign(r,xm(e)),Object.assign(r,Iu(e)),e.readouts&&Object.assign(r,e.readouts),r}function WM(e,t){let r=v2(e,t);return zM(e)||Object.assign(r,Qb),r}function Jb(e){let t=e.cop_long;return yn(t)?1-t.value:.5}function k2(e,t){let r=e.front_aero_diss,n=e.cop_long;!yn(r)||!yn(n)||(t===r.label?n.value=1-r.value:t===n.label&&(r.value=1-n.value))}function M2(e,t){k2(e,t);let r=e.c_l,n=e.c_w,o=e.l_to_d_ratio;!yn(r)||!yn(n)||(t===r.label||t===n.label?yn(o)&&n.value!==0&&(o.value=r.value/n.value):yn(o)&&t===o.label&&o.value!==0&&(n.value=r.value/o.value))}function vm(e,t,r){let n=!1;for(let o of Object.keys(e)){if(o==="motor"||o==="name")continue;let a=e[o];if(yn(a)&&KM(a.label)===t){a.value=r,n=!0;break}}return n&&M2(e,t),n}function km(e,t,r=0,n,o){let a=()=>({cl:e.c_l.value,cw:e.c_w.value,frontShare:Jb(e),A:e.A.value,platform:null});if(!e.aeroModel)return a();let s=Xr(n??It(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:Jb(e),A:s.area,platform:s}}var jM=e=>typeof e=="object"&&e!==null&&typeof e.value=="number"&&typeof e.label=="string";function UM(e,t=e.aeroModel){if(!t)return e;let r=Tn(t,{wheelbase:re(e,"wheelbase")}).at(re(e,"ride_height_front"),re(e,"ride_height_rear")),{cl:n,balanceFront:o}=Wd(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(jM(e.cop_long)?e.cop_long:void 0,Er.cop_long,1-o)};return jM(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 oc={dsTarget:.25,accelStep:.25,vTol:.002,scanSteps:24,seamIters:8,fitSpacing:1},S2=32;function XM(e,t,r){let n=Math.round(e/t);return Math.max(1,Math.min(Number.isFinite(n)?n:1,Math.floor(r/S2)||1))}function At(e){let t=oc,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 qM=Math.PI/180,Mm=.02,QM=new WeakMap;function ac(e){let t=QM.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)*qM,l=(e.bank?.[i]??0)*qM,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 QM.set(e,s),s}function Sm(e,t,r){return e.n0[t]+e.k[t]*r*r}function ZM(e,t){return e.k[t]<0?Math.sqrt(Math.max(0,e.n0[t])/-e.k[t]):1/0}function JM(e,t){if(!e)return null;let r=1/0,n=-1/0;for(let o=0;o<e.n0.length;o++){let a=Sm(e,o,t[o]??0);a<r&&(r=a),a>n&&(n=a)}return r>=1-Mm&&n<=1+Mm?null:{lo:r,hi:n}}var rs=[.1,.25,.5,.75,1,1.25,1.5,2,2.5];function eS(e){let t=e.lo>=1-Mm?1:1-1.25*(1-e.lo)-.05,r=e.hi<=1+Mm?1:1+1.25*(e.hi-1)+.05,n=[...rs].reverse().find(a=>a<=t)??rs[0],o=rs.find(a=>a>=r)??rs[rs.length-1];return rs.filter(a=>a>=n&&a<=o)}function eg(e,t,r){return r<1?Math.max(e,t):Math.min(e,t)}function tS(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,d,p=1,h=1)=>s.axAccel(m,d,p,h)+t.axAccel(u(m),m,d,p,h)-r.axAccel(m,d,p,h),axDecel:(m,d,p=1,h=1)=>{let f=b=>s.axDecel(m,d,p,b)+t.axDecel(u(m),m,d,p,b)-r.axDecel(m,d,p,b);return h===1?f(1):eg(f(h),f(1),h)},ay:(m,d,p=1)=>Math.max(0,s.ay(m,d,p)+t.ay(u(m),m,d,p)-r.ay(m,d,p)),scrub:(m,d,p=1)=>(s.scrub?.(m,d,p)??0)+t.scrub(u(m),m,d,p)-(r.scrub?.(m,d,p)??0)}:{vMax:s.vMax,axAccel:(m,d,p=1,h=1)=>t.axAccel(u(m),m,d,p,h),axDecel:(m,d,p=1,h=1)=>t.axDecel(u(m),m,d,p,h),ay:(m,d,p=1)=>t.ay(u(m),m,d,p),scrub:(m,d,p=1)=>t.scrub(u(m),m,d,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}=A2(e,t,r),u=new Array(a),m=new Array(a),d=new Array(a),p=new Array(a).fill(0),h=0,f=0,b=0,g=Math.max(0,Math.min(1,n.kept)),y=g>=1?0:n.up,x=g>=1?0:n.down,k=4*y*(1-g),v=A=>{let{v:F,gear:T,tau:P,target:S}=A;h=0,f=0,b=0;for(let w=0;w<s;w++){let C=i(w),L=e[C];for(let O=0;P<=0&&O<n.count;O++){let I=T;if(F<L-1e-9?n.best(F)>T&&(n.rpm(F,T)>=n.limitRpm||c[w]>=F*k)?I=T+1:T>0&&F<n.vIdle(T)&&(I=T-1):L<F-1e-9&&T>0&&n.best(l[w])<T&&n.rpm(F,T-1)<=n.limitRpm&&(I=T-1),I===T)break;S=I,I>T?h++:f++,P=I>T?y:x,P<=0&&(T=S)}u[w]=F,m[w]=T+1,d[w]=n.rpm(F,T);let E=P>0;p[w]=E?1:0;let _=L;if(!E)F<L&&(_=Math.min(L,Math.sqrt(Math.max(0,F*F+2*o(w,F,n.share(F,T))*t[w]))));else if(F<L){let O=o(w,F,g>0?g*n.share(F,T):0),I=Math.min(L,Math.sqrt(Math.max(0,F*F+2*O*t[w]))),z=F+I>0?2*t[w]/(F+I):1/0;if(z<=P)_=I,b+=z,P-=z;else{let B=Math.min(L,Math.max(0,F+O*P)),V=Math.max(0,t[w]-(F+B)*.5*P);b+=P,P=0,T=S,_=Math.min(L,Math.sqrt(Math.max(0,B*B+2*o(w,B,n.share(B,T))*V)))}}else{let O=F+_>0?2*t[w]/(F+_):0;b+=Math.min(O,P),P-=O,P<=0&&(T=S)}F=_}return{v:F,gear:T,tau:P,target:S}},R=n.best(e[0]),M={v:e[0],gear:R,tau:0,target:R};if(r)for(let A=0;A<6;A++){let F=v(M),T=Math.abs(F.v-M.v)<=1e-9&&F.gear===M.gear&&F.target===M.target&&Math.abs(F.tau-M.tau)<=1e-12;if(M=F,T)break}else{let A=v(M);u[a-1]=A.v,m[a-1]=A.gear+1,d[a-1]=n.rpm(A.v,A.gear),p[a-1]=A.tau>0?1:0}return{v:u,gear:m,rpm:d,shifting:p,upshifts:h,downshifts:f,gapTime:b}}function A2(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,d=e[m]<e[u]-1e-9;s=d?0:s+t[u],i=d?Math.min(i,e[m]):e[u],l<n&&(o[u]=s,a[u]=i)}return{brakeAhead:o,apexAhead:a}}var tg=.001,rg=9.81,sc=(e,t)=>wm(e?.gradient?.[t]??0);function wm(e){return e===0?0:-rg*Math.sin(e*Math.PI/180)}function ns(e,t){let r=new Array(t);for(let n=0;n<t;n++)r[n]=wm(e?.[n]??0);return r}function Fm(e,t){let r=e?.[t];return r!=null&&r>0?r:1}var Yn=(e,t)=>Fm(e?.mu,t),Io=(e,t)=>e?.bank?.[t]??0;function w2(e,t,r,n,o,a){let s=e.ay(t,r,Yn(o,a)),i=Io(o,a);if(!i)return s;let c=i*Math.PI/180,l=n===0?0:-Math.sign(n)*rg*Math.sin(c);return Math.max(0,(s+l)/Math.cos(c))}function at(e,t){if(!t)return e;let r=t*Math.PI/180;return e*Math.cos(r)+rg*Math.sin(r)}function ng(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 _o=(e,t,r)=>t?t(r):e,F2=1e-4;function os(e,t,r,n,o,a,s){let i=At(r),c=[];for(let l=0;l<t.length;l++){let u=t[l],m=Math.abs(u),d=_o(e,o,l),p=a!==void 0&&a>0?Math.min(d.vMax,a):d.vMax,h=s?Math.min(p,s(l)):p,f=m<=0?h:ng(b=>b*b*m-w2(d,b,0,u,n,l),tg,h,i.scanSteps,Math.min(i.vTol,F2));c.push({v:f,ax:0,ay:f*f*u})}return c}function C2(e,t,r,n,o,a,s=1,i=0,c=0,l){if(r.v<=t.v)return 0;let u=p=>{let h=at(p*p*n,c),f=(l?e.axDecel(p,Math.abs(h),s,l(p)):e.axDecel(p,Math.abs(h),s))+i;return Math.sqrt(Math.max(0,p*p+2*f*o))},m=r.v;r.v=ng(p=>u(p)-t.v,tg,r.v,a.scanSteps,a.vTol),r.ay=r.v*r.v*n;let d=Math.abs(at(r.ay,c));return r.ax=(l?e.axDecel(r.v,d,s,l(r.v)):e.axDecel(r.v,d,s))+i,m-r.v}function T2(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(at(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 rS(e,t,r,n,o,a){let s=At(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 d=(m+1)%i;u=Math.max(u,C2(_o(e,o,m),t[d],t[m],r.curvature[m],r.ds[m],s,Yn(r,m),sc(r,m),Io(r,m),a?p=>a(m,p):void 0))}if(u<=s.vTol)break}return c}function nS(e,t,r,n,o,a){let s=At(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 d=(m+1)%i;u=Math.max(u,T2(_o(e,o,m),t[d],t[m],r.curvature[m],r.ds[m],Yn(r,m),sc(r,m),Io(r,m),a?a[m]:1))}if(u<=s.vTol)break}return c}function P2(e,t,r){let n=r.load?ac(t):null;if(!n||!r.load)return{pick:r.envelope};let o=t.npts;return{pick:tS(n,r.load,e,r.envelope),cap:a=>ZM(n,a%o),n:(a,s)=>Sm(n,a,s)}}function oS(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 _o(e,t,i).axAccel(c,Math.abs(at(u,Io(r,i))),Yn(r,i),s?l*s[i]:l)+sc(r,i)})}function aS(e,t){return{gear:e.gear.slice(0,t),engineRpm:e.rpm.slice(0,t),shifting:e.shifting.slice(0,t)}}function sS(e,t,r,n){if(!e.scrub)return{};let o=!1,a=n.map((s,i)=>{let c=_o(e,t,i),l=at(s*s*r.curvature[i],Io(r,i)),u=c.scrub?c.scrub(s,Math.abs(l),Yn(r,i)):0;return u!==0&&(o=!0),u});return o?{axScrub:a}:{}}function Kt(e,t,r,n={}){let o=At(r),a=t.npts,s=t.closed&&!n.standingStart,{pick:i,cap:c,n:l}=P2(e,t,n),u=n.driveDerate,m=n.brakeFade;if(!s)return L2(e,t,o,n.standingStart===!0,i,u,n.vCeiling,m,c,l,n.shifts);let d=os(e,t.curvature,o,t,i,n.vCeiling,c),p=rS(e,d,t,o,i,m),h=nS(e,d,t,o,i,u),f=n.shifts?oS(e,i,t,d.map(k=>k.v),!0,n.shifts,u):void 0;if(f)for(let k=0;k<a;k++)d[k].v=f.v[k];for(let k=0;k<a;k++){let v=d[k];v.ay=v.v*v.v*t.curvature[k];let R=d[(k+1)%a].v;v.ax=(R*R-v.v*v.v)/(2*t.ds[k])}let b=d.map(k=>k.v),g=d.map(k=>k.ax),y=d.map(k=>k.ay),x=0;for(let k=0;k<a;k++){let v=b[k]+b[(k+1)%a];v>0&&(x+=2*t.ds[k]/v)}return{states:d,v:b,ax:g,ay:y,laptime:x,sweeps:{backward:p,forward:h},...l?{loadFactor:b.map((k,v)=>l(v,k))}:{},...sS(e,i,t,b),...f?aS(f,a):{}}}function L2(e,t,r,n,o,a,s,i,c,l,u){let m=t.npts,d=t.closed?m:m-1,p=d+1,h=new Array(p);for(let x=0;x<p;x++)h[x]=t.curvature[x%m];let f=os(e,h,r,t,o,s,c);n&&(f[0].v=0);for(let x=d-1;x>=0;x--){let k=f[x],v=f[x+1];if(k.v<=v.v)continue;let R=_o(e,o,x),M=F=>{let T=at(F*F*t.curvature[x],Io(t,x)),P=(i?R.axDecel(F,Math.abs(T),Yn(t,x),i(x,F)):R.axDecel(F,Math.abs(T),Yn(t,x)))+sc(t,x);return Math.sqrt(Math.max(0,F*F+2*P*t.ds[x]))},A=n&&x===0?k.v:tg;k.v=ng(F=>M(F)-v.v,A,k.v,r.scanSteps,r.vTol)}for(let x=0;x<d;x++){let k=f[x],v=f[x+1];k.ay=k.v*k.v*t.curvature[x];let R=at(k.ay,Io(t,x));k.ax=_o(e,o,x).axAccel(k.v,Math.abs(R),Yn(t,x),a?a[x]:1)+sc(t,x),v.v=Math.min(v.v,Math.sqrt(Math.max(0,k.v*k.v+2*k.ax*t.ds[x])))}let b=u?oS(e,o,t,f.map(x=>x.v),!1,u,a):void 0;if(b)for(let x=0;x<p;x++)f[x].v=b.v[x];let g=0;for(let x=0;x<d;x++){let k=f[x].v+f[x+1].v;k>0&&(g+=2*t.ds[x]/k)}let y=f.slice(0,m);for(let x=0;x<m;x++){let k=y[x];k.ay=k.v*k.v*t.curvature[x];let v=x<d?f[x+1].v:k.v;k.ax=t.ds[x]>0?(v*v-k.v*k.v)/(2*t.ds[x]):0}return{states:y,v:y.map(x=>x.v),ax:y.map(x=>x.ax),ay:y.map(x=>x.ay),laptime:g,sweeps:{backward:1,forward:1},...l?{loadFactor:y.map((x,k)=>l(k,x.v))}:{},...sS(e,o,t,y.map(x=>x.v)),...b?aS(b,m):{}}}var iS=(e,t)=>{let r=e[t]?.value;return Number.isFinite(r)&&r>0?r:0};function No(e,t,r){let n=e.m.value,o=e.r_dyn?.value??0,a=iS(e,"I_wheel"),s=e.motorModel?.kind==="ice"?0:iS(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,d=u*a/c,p=n+m+d;return{mass:n,driven:m,undriven:d,effective:p,powerFactor:n/p,tractionFactor:n/(n+d)}}function Oo(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 ic=36e5,mS=Math.PI*2,og=e=>Math.max(0,Math.min(1,e));function ag(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=Sl(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/mS),l=Math.max(0,i*o/(n*a)),u=r.efficiency(c,l);return u>.01?u:.5}}var cS=new WeakMap;function as(e){if(e.batteryModel)return e.batteryModel;let t=e.capacity.value,r=e.ocv.value,n=cS.get(e);if(n&&n.capacityAh===t&&n.ocv===r)return n.model;let o=_d(t,r);return cS.set(e,{capacityAh:t,ocv:r,model:o}),o}function sg(e){let t=e.params,r=cb(t,_u(e));if(pt(t.motorModel)||Et(t).mode!=="hydraulic")return r;let n;return(o,a,s,i=0)=>{if(!(o>0))return 0;n??=D2(e);let c=Ku(n.inp,n.ev,o,a,i);return c?Math.min(o,c.regenFront+c.regenRear):r(o,a,s)}}var lS=new WeakMap;function D2(e){let t=e.params,r=lS.get(t);if(!r){let n=cn(t);r={inp:It(n.regen?t:{...t,energy:{...n,regen:!0}}),ev:Nr(t)},lS.set(t,r)}return r}var cc=e=>e.airTempC??Ut;function Cm(e,t){return e.thermal?e.thermal.startC??t:da}function uS(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 pS=()=>({windingC:[],derate:[],lossW:[],torqueNm:[],ampsRms:[]});function E2(e){let t=e.motorModel;if(pt(t))return;let r=t?Sl(t).maxTorque:s=>Ue(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/mS),peak:r,torque:(s,i,c)=>{let l=Math.min(Math.abs(s)*o/(n*a),c*r(i));return s<0?-l:l}}}function I2(e,t){let r=e.motorModel?.thermal;if(!r||!t)return;let n=r.torqueConstant;return{...t,th:Nd(r),amps:o=>n>0?Math.abs(o)/n:0}}function _2(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),d=u?c/l:1,p=r*d;return{dq:m*p,lossJ:m*m*e.resistance(n,o)*p,energyJ:l*p,short:c>i,cutoff:u,seconds:p}}function N2(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 O2(e){let{drivenFront:t,drivenRear:r}=Oo(e);return No(e.params,t,r)}function ss(e,t,r,n,o=sn,a,s,i,c,l,u){let m=e.params,d=m.rho.value,p=m.fr_0.value,h=m.m.value,f=e.FG,b=m.aeroModel?It(m):void 0,g=ag(m),y=jr(as(m)),x=y.chargeC,k=m.motorModel?.kind==="ice",v=og(a??(k?1:m.soc.value)),R=cc(m),M=s??Cm(y,R),A=M,F=0,T=0,P=0,S=0,w=-1,C=-1,L=-1,E=i||m.motorModel?.thermal?E2(m):void 0,_=I2(m,E),O=_?_.th.startC:0,I=O,z=0,B=1,V=-1,j=0,q=0,K=sg(e),D=u?.scrub,N=O2(e),Y=D?h/N.tractionFactor:0,H=N.effective-h,W=Math.min(t.length,r.length);for(let X=0;X<W;X++){let ne=r[X],Z=ne*ne,xe=n[X]-(c?.[X]??0),{cl:de,cw:be,A:U}=km(m,ne,xe/9.81,b),ee=.5*d*de*U*Z,se=.5*d*be*U*Z,ie=(f+ee)*-p,Re=D?-Y*(D[X]??0):0,pe=ie+se+Re+h*xe;H>0&&(pe+=H*n[X]);let ce=pe*t[X];l?.driveN?.push(pe>0?pe:0);let Pe=X+1<r.length?r[X+1]:ne,ke=.5*(ne+Pe),ae=ke>0?t[X]/ke:0,ge=0,fe=v,Ce=M,Ae=0,Ge=0,Ne=ae;if(k){pe>0&&(Ge=ce/g(ne,pe),F+=Ge/ic),l?.netKwh.push(F-T),l?.powerKw?.push(ae>0?Ge/ae/1e3:0);continue}if(pe>0){let Te=ce/g(ne,pe),ye=_2(y,Te,ae,v,M);ye.short&&w<0&&(w=X),ye.cutoff&&C<0&&(C=X);let me=v*x,Me=Math.min(ye.dq,me),Xe=ye.dq>0?Me/ye.dq:1;Me>=me&&L<0&&(L=X),F+=ye.energyJ*Xe/ic,Ge=ye.energyJ*Xe,Ne=ye.seconds,P+=ye.lossJ*Xe,S+=Me,ae>0&&(Ae=Me/ye.seconds),v=og(v-Me/x),M=uS(y,M,ye.dq>0&&ae>0?Me/ae:0,ye.lossJ*Xe,ae,R),M>A&&(A=M),ge=pe}else if(o.regen){let Te=u?at(u.ay[X],u.bank?.[X]??0)/9.81:0,ye=K(-pe,ne,xe/9.81,Te),me=o.regenEfficiency*ye*t[X],Me=N2(y,me,ae,v,M),Xe=(1-v)*x,Ye=Math.min(Me.dq,Xe),Le=Me.dq>0?Ye/Me.dq:1;T+=Me.energyJ*Le/ic,Ge=-Me.energyJ*Le,P+=Me.lossJ*Le,S-=Ye,ae>0&&(Ae=-Ye/ae),v=og(v+Ye/x),M=uS(y,M,Ye>0&&ae>0?-Ye/ae:0,Me.lossJ*Le,ae,R),M>A&&(A=M),ge=-ye*Le}if(l?.netKwh.push(F-T),l?.powerKw?.push(ae>0?Ge/Ne/1e3:0),l?.pack){let Te=l.pack;Te.soc.push(fe),Te.amps.push(Ae),Te.volts.push(y.ocv(fe)-Ae*y.resistance(fe,Ce)),Te.cellC.push(Ce)}if(_){let Te=_.rpm(ne),ye=_.th.derate(Te,O,_.peak(Te));ye<B&&(B=ye),ye<1&&V<0&&(V=X),q+=ae,ye<1&&(j+=ae);let me=_.torque(ge,Te,ye),Me=_.th.lossW(Te,me,O);z+=Me*ae,i&&(i.windingC.push(O),i.derate.push(ye),i.lossW.push(Me),i.torqueNm.push(me),i.ampsRms.push(_.amps(me))),O=_.th.step(O,Me,ae),O>I&&(I=O)}else E&&i&&i.torqueNm.push(E.torque(ge,E.rpm(ne),1))}return{drive:F,regen:T,net:F-T,chargeAh:S/3600,loss:P/ic,socEnd:v,shortAt:w,cutoffAt:C,emptyAt:L,tempEndC:M,tempMaxC:A,..._?{motorTempEndC:O,motorTempMaxC:I,motorLossKwh:z/ic,motorDerateMin:B,motorDerateAt:V,motorDerateTimeFrac:q>0?j/q:0}:{}}}var V2=.5,B2=.02,$2=6;function dS(e,t,r,n,o,a,s,i){let c=n(),l=1,u=h=>{let f=pS(),b=ss(e,t,h.v,h.ax,r,o,a,f,s,void 0,{ay:h.ay,bank:i,...h.axScrub?{scrub:h.axScrub}:{}});return{trace:f,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 d=m.trace.derate.slice(),p=!1;for(let h=0;h<$2;h++){let f=n(d);l++;let b=Math.abs(f.laptime-c.laptime);if(c=f,m=u(c),b<B2){p=!0;break}let g=m.trace.derate,y=new Array(d.length);for(let x=0;x<d.length;x++)y[x]=d[x]+V2*((g[x]??1)-d[x]);d=y}return{lap:c,derate:d,solves:l,converged:p,peakWindingC:m.peak,derateTimeFrac:m.frac}}var G2=.1;function fS(e){if(e.motorModel?.kind==="ice")return 0;let t=e.power_limit_kw?.value??0;return t>0?t*1e3:0}function ig(e,t,r){return e.motorModel?.kind==="ice"?1/0:jr(as(e)).maxPower(t??e.soc.value,r,fS(e)).watts}function Tm(e,t,r,n){let o=ig(e,r,n);if(!Number.isFinite(o))return 1/0;if(o<=0)return 0;let a=Math.max(G2,t),s=ag(e),i=o*.9/a;return o*s(t,i)/a}var K2=180/Math.PI;function Pm(e,t,r,n){let o=e*t,a=e*(1-t);return o/r-a/n}var Lm=e=>e*9.81*K2;var HQ=Math.PI/180;function Dm(e,t,r,n=0){let o=$e(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?Pm(e.massTotal,e.frontMassFrac,2*i,2*c):0,u=Lm(l),m=u>.15?"understeer":u<-.15?"oversteer":"neutral";return{gradient:u,balance:m,cAlphaFront:i,cAlphaRear:c}}var QQ=Math.PI/180,ZQ=180/Math.PI;var hS=2220446049250313e-31;function Y2(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 d=0;d<t;d++)e[a][d]*=m;for(let d=0;d<t;d++)e[d][a]*=l}}}}}function W2(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 j2(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])<=hS*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 d=.5*(u-l),p=d*d+m,h=Math.sqrt(Math.abs(p));l+=s,p>=0?(h=d+(d>=0?Math.abs(h):-Math.abs(h)),r[a-1]=r[a]=l+h,h!==0&&(r[a]=l-m/h),n[a-1]=n[a]=0):(r[a-1]=r[a]=l+d,n[a]=h,n[a-1]=-h),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 d=a-2,p=0,h=0,f=0;for(;d>=c;d--){let b=e[d][d],g=l-b,y=u-b;p=(g*y-m)/e[d+1][d]+e[d][d+1],h=e[d+1][d+1]-b-g-y,f=e[d+2][d+1];let x=Math.abs(p)+Math.abs(h)+Math.abs(f);if(p/=x,h/=x,f/=x,d===c)break;let k=Math.abs(e[d][d-1])*(Math.abs(h)+Math.abs(f)),v=Math.abs(p)*(Math.abs(e[d-1][d-1])+Math.abs(b)+Math.abs(e[d+1][d+1]));if(k<=hS*v)break}for(let b=d+2;b<=a;b++)e[b][b-2]=0,b!==d+2&&(e[b][b-3]=0);for(let b=d;b<=a-1;b++){b!==d&&(p=e[b][b-1],h=e[b+1][b-1],f=b!==a-1?e[b+2][b-1]:0,l=Math.abs(p)+Math.abs(h)+Math.abs(f),l!==0&&(p/=l,h/=l,f/=l));let g=Math.sqrt(p*p+h*h+f*f),y=p>=0?g:-g;if(y!==0){b===d?c!==d&&(e[b][b-1]=-e[b][b-1]):e[b][b-1]=-y*l,p+=y,l=p/y,u=h/y;let x=f/y;h/=p,f/=p;for(let v=b;v<=a;v++){let R=e[b][v]+h*e[b+1][v];b!==a-1&&(R+=f*e[b+2][v],e[b+2][v]-=R*x),e[b+1][v]-=R*u,e[b][v]-=R*l}let k=a<b+3?a:b+3;for(let v=c;v<=k;v++){let R=l*e[v][b]+u*e[v][b+1];b!==a-1&&(R+=x*e[v][b+2],e[v][b+2]-=R*f),e[v][b+1]-=R*h,e[v][b]-=R}}}}}}while(c<a-1&&a>=0)}return r.map((i,c)=>({re:i,im:n[c]}))}function bS(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 Y2(r),W2(r),j2(r)}function gS(e){let t=[],r=new Array(e.length).fill(!1),n=bS(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 cg(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 f=c;f<r;f++)for(let b=c;b<r;b++){let g=e[f][b]*e[f][b]+t[f][b]*t[f][b];g>m&&(m=g,l=f,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 f=0;f<r;f++)[e[f][c],e[f][u]]=[e[f][u],e[f][c]],[t[f][c],t[f][u]]=[t[f][u],t[f][c]];[n[c],n[u]]=[n[u],n[c]]}let d=e[c][c],p=t[c][c],h=d*d+p*p;for(let f=c+1;f<r;f++){let b=(e[f][c]*d+t[f][c]*p)/h,g=(t[f][c]*d-e[f][c]*p)/h;if(!(b===0&&g===0))for(let y=c;y<r;y++)e[f][y]-=b*e[c][y]-g*t[c][y],t[f][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 d=0,p=0;for(let h=c+1;h<r;h++)d+=e[c][h]*o[h]-t[c][h]*a[h],p+=e[c][h]*a[h]+t[c][h]*o[h];o[c]=-(d*l+p*u)/m,a[c]=-(p*l-d*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 U2(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 cg(r,n)}function Em(e,t=r=>U2(e,r)){return gS(e).map(r=>({...r,vector:t(r.eigenvalue)}))}function is(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 yS(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 is(Em(i),c,0)}function xS(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=yS({sprungMass:o,unsprungMass:e.unsprungCornerMass??e.unsprungPerCorner,springRate:s,damperRate:n,tireRate:lt(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 Im(e,t,r){let n=Be(e);return{front:xS(e,n,"front",t??n.rideDampingFront),rear:xS(e,n,"rear",r??n.rideDampingRear)}}var mZ=180/Math.PI;var lg=["FL","FR","RL","RR"],he={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},cs=20,RS=[he.zFL,he.zFR,he.zRL,he.zRR],vS=[he.vzFL,he.vzFR,he.vzRL,he.vzRR],xn={fzFL:0,fzFR:1,fzRL:2,fzRR:3,fzBody:4,myBody:5,mxBody:6,fx:7,fy:8,mz:9},ug=10;function _m(e){let t=Array.from({length:cs},()=>new Array(cs).fill(0)),r=Array.from({length:cs},()=>new Array(ug).fill(0));t[he.zFL][he.vzFL]=1,t[he.zFR][he.vzFR]=1,t[he.zRL][he.vzRL]=1,t[he.zRR][he.vzRR]=1,t[he.zBody][he.vzBody]=1,t[he.pitch][he.pitchRate]=1,t[he.roll][he.rollRate]=1,t[he.x][he.vx]=1,t[he.y][he.vy]=1,t[he.yaw][he.yawRate]=1;let{inertia:n}=e,o=[1,0,3,2],a=(s,i,c,l)=>{s[RS[i]]-=c,s[vS[i]]-=l,s[he.zBody]+=c,s[he.vzBody]+=l,s[he.pitch]-=c*e.leverX[i],s[he.pitchRate]-=l*e.leverX[i],s[he.roll]+=c*e.leverY[i],s[he.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),d=e.damperRate[s]+c(e.rollDamper),p=(l+u)/2,h=(l-u)/2,f=(m+d)/2,b=(m-d)/2,g=new Array(cs).fill(0);a(g,s,p,f),(h!==0||b!==0)&&a(g,o[s],h,b);let y=e.wheelMass[s],x=e.leverX[s],k=e.leverY[s],v=RS[s],R=vS[s];for(let M=0;M<cs;M++){let A=g[M];A!==0&&(t[R][M]+=A/y,t[he.vzBody][M]-=A/e.bodyMass,t[he.pitchRate][M]+=x*A/n.yy,t[he.rollRate][M]-=k*A/n.xx)}t[R][v]-=e.tyreRate[s]/y,t[R][R]-=e.tyreDamping[s]/y,r[R][xn.fzFL+s]=1/y}return r[he.vzBody][xn.fzBody]=1/e.bodyMass,r[he.pitchRate][xn.myBody]=1/n.yy,r[he.rollRate][xn.mxBody]=1/n.xx,r[he.vx][xn.fx]=1/e.totalMass,r[he.vy][xn.fy]=1/e.totalMass,r[he.yawRate][xn.mz]=1/n.zz,{A:t,B:r,params:e}}function mg(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,d=lt(e,"front")*1e3,p=lt(e,"rear")*1e3,h=(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:[d,d,p,p],tyreDamping:[h,h,h,h],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 kS=he.rollRate+1;function MS(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,kS).map(i=>i.slice(0,kS));if(!n.every(i=>i.every(Number.isFinite)))return{};let a=Em(n,i=>{let c=i.re*i.re-i.im*i.im,l=2*i.re*i.im,u=r.map((d,p)=>r.map((h,f)=>(p===f?c:0)-i.re*n[2*p+1][2*f+1]-n[2*p+1][2*f])),m=r.map((d,p)=>r.map((h,f)=>(p===f?l:0)-i.im*n[2*p+1][2*f+1]));return cg(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:is(a,s,1),pitch:is(a,s,2),roll:is(a,s,3)}}function SS(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 Nm(e){let t=Be(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=MS(_m(mg(e)));return{roll:SS(m.roll,a,s),pitch:SS(m.pitch,l,u)}}var Om=9.81,Rn=Math.PI/180;function AS(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 ls(e,t,r,n,o){let{wb:a,lf:s,lr:i,m:c}=AS(e),l=0;for(let x=0;x<16;x++){let k=l/r,v=o-n-s*k/r,R=-n+i*k/r,M=$e(e,l/Om,0,r),A=Math.max(0,M.FL+M.FR),F=Math.max(0,M.RL+M.RR),T=t(v,A),P=t(R,F),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,d=-n+i*u/r,p=$e(e,l/Om,0,r),h=Math.max(0,p.FL+p.FR),f=Math.max(0,p.RL+p.RR),b=t(m,h),g=t(d,f),y=s*b*Math.cos(o)-i*g;return{ay:l/Om,cn:y/(c*Om*a)}}function pg(e,t,r,n={}){let o=Math.max(8,r),a=(n.betaMaxDeg??10)*Rn,s=(n.deltaMaxDeg??10)*Rn,i=n.nLines??9,c=n.nPts??21,l=(g,y,x,k)=>x===1?g:g+(y-g)*k/(x-1),u=[],m={ay:[],cn:[]},d=0;for(let g=0;g<i;g++){let y=l(-s,s,i,g),x=[],k=[],v=[],R=[];for(let M=0;M<c;M++){let A=l(-a,a,c,M),F=ls(e,t,o,A,y);x.push(F.ay),k.push(F.cn),v.push(A/Rn),R.push(y/Rn),Math.abs(F.ay)>d&&(d=Math.abs(F.ay))}u.push({label:`\u03B4 ${(y/Rn).toFixed(0)}\xB0`,ay:x,cn:k,betaDeg:v,deltaDeg:R});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(x[M-1]+A*(x[M]-x[M-1])),m.cn.push(0);break}}let p=[];for(let g=0;g<i;g++){let y=l(-a,a,i,g),x=[],k=[],v=[],R=[];for(let M=0;M<c;M++){let A=l(-s,s,c,M),F=ls(e,t,o,y,A);x.push(F.ay),k.push(F.cn),v.push(y/Rn),R.push(A/Rn)}p.push({label:`\u03B2 ${(y/Rn).toFixed(0)}\xB0`,ay:x,cn:k,betaDeg:v,deltaDeg:R})}let h=.5*Rn,f=(ls(e,t,o,h,0).cn-ls(e,t,o,-h,0).cn)/(2*h),b=(ls(e,t,o,0,h).cn-ls(e,t,o,0,-h).cn)/(2*h);return{isoBeta:p,isoDelta:u,trim:m,maxAy:d,stability:f,control:b,speed:o}}function X2(e){return!e.corneringStiffnessFront||!e.corneringStiffnessRear?null:{Cf:2*e.corneringStiffnessFront,Cr:2*e.corneringStiffnessRear}}function lc(e,t){let r=X2(e);if(!r)return null;let{Cf:n,Cr:o}=r,{wb:a,lf:s,lr:i,m:c}=AS(e),l=e.yawInertia??c*1*1,u=Math.max(3,t),m=-(n+o)/(c*u),d=(-s*n+i*o)/(c*u)-u,p=(-s*n+i*o)/(l*u),h=-(s*s*n+i*i*o)/(l*u),f=m+h,b=m*h-d*p,g=f*f-4*b,y,x,k;if(g<0)y=f/2,x=Math.sqrt(Math.max(0,b)),k=x>0?-f/(2*x):1;else{let C=Math.sqrt(g);y=Math.max((f+C)/2,(f-C)/2),x=Math.sqrt(Math.abs(b)),k=x>0?-f/(2*x):1}let v=f<0&&b>0,R=Pm(c,e.frontMassFrac,n,o),M=Lm(R),A=M>.15?"understeer":M<-.15?"oversteer":"neutral",F=s*n-i*o,T=C=>C*3.6,P=null,S=null;F>1e-6?S=T(Math.sqrt(n*o*a*a/(c*F))):F<-1e-6&&(P=T(Math.sqrt(n*o*a*a/(c*-F))));let w=u/(a+R*u*u);return{stable:v,yawFreq:x/(2*Math.PI),dampingRatio:k,eigReal:y,understeerGradient:M,balance:A,characteristicSpeed:P,criticalSpeed:S,yawRateGain:w}}var q2={envelopeTrim:{name:"Grip envelope, trim",code:"`solvePoint` in src/core/dynamics/twoTrack.ts (`twoTrackLimitState`, `twoTrackStateAtAy`)"},envelopeLimits:{name:"Grip envelope, limits",code:"`calcGGV` in src/core/laptime/ggv.ts"},qssLap:{name:"QSS lap",code:"`solveLap` in src/core/laptime/solver.ts, with its energy (`energyOverPath`)"},tyreReadouts:{name:"Tyre readouts",code:"`lapReserves` in src/core/dynamics/lapReserve.ts"},transientPlant:{name:"Transient plant",code:"`dynamicReplay` in src/core/dynamics/dynamicReplay.ts"},plannerRequest:{name:"Optimal, the request",code:"`planCarFrom` in src/core/plan/request.ts"},ymd:{name:"Yaw moment diagram",code:"`twoTrackYMD` in src/core/dynamics/twoTrack.ts"},stepSteer:{name:"Step steer",code:"`steerRun` in src/core/dynamics/steerRun.ts"},drive:{name:"Drive",code:"`liveCar` in src/core/drive/liveCar.ts"}},dg=Object.keys(q2),Vm=["envelopeTrim","envelopeLimits","qssLap","tyreReadouts","ymd"];var Q2="the longitudinal condition is set directly; what a motor could deliver is the lap solver\u2019s question",Z2="no tractive force is applied at a constant speed",fg="runs a torque-vectoring controller only when the caller hands one in (`DynamicReplayOptions.vectoring`, `SteerRunOptions.vectoring`), as the app does (`lapVectoringFor`, `steerVectoringFor` in src/app/dynamics/tvCore.ts)",hg="Drive runs no torque vectoring: its aids are ABS and traction control",wS="the readouts split the drive by room or through the diff, never by a controller",J2=[{key:"damper_front",tools:["ymd"],why:"dampers act on velocity; every point here is at constant attitude"},{key:"damper_rear",tools:["ymd"],why:"dampers act on velocity; every point here is at constant attitude"},{key:"tire_vertical_damping",tools:Vm,why:"tyre damping acts on velocity; every point here is at constant attitude"},{key:"tire_vertical_damping",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic (reduced planner model)"},{key:"I_yaw",tools:["envelopeTrim","envelopeLimits","tyreReadouts","ymd"],why:"inertia resists change; a steady corner has none"},{key:"I_yaw",tools:["qssLap"],why:"inertia resists change; a steady corner has none. The quasi-transient option charges it (`calcGgvFamily`)",onCar:"quasi-transient off, as in the templates"},{key:"I_roll",tools:Vm,why:"inertia resists change; a steady corner has none"},{key:"I_roll",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no roll dynamics (reduced planner model)"},{key:"I_pitch",tools:Vm,why:"inertia resists change; a steady corner has none"},{key:"I_pitch",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no pitch dynamics (reduced planner model)"},...["capacity","ocv","soc"].flatMap(e=>[{key:e,tools:["ymd"],why:"energy does not enter a single steady-state point"},{key:e,tools:dg.filter(t=>t!=="ymd"&&t!=="qssLap"),why:"the charge reaches the forces only through a battery model\u2019s power ceiling (`packPowerW`); without one it is counted by the QSS lap\u2019s energy account, and drawn on nowhere",onCar:"no battery model"}]),{key:"tv_kp",tools:Vm,why:"the feedback gain multiplies a yaw error, and a trimmed point has none \u2014 the feedforward does move this diagram"},{key:"tv_kp",tools:["transientPlant","stepSteer"],why:fg},{key:"tv_kp",tools:["plannerRequest"],why:"the planner reads only whether torque vectoring is on, for its allocation (`longitudinalAllocation`)"},{key:"tv_kp",tools:["drive"],why:hg},{key:"tv_enabled",tools:["transientPlant","stepSteer"],why:fg},{key:"tv_enabled",tools:["drive"],why:hg},{key:"tv_enabled",tools:["tyreReadouts"],why:wS,gap:"the envelope corners with the feedforward, the readouts split the same lap without it (rule 3)"},...["tv_ff_low","tv_ff_high","tv_v_low","tv_v_high"].flatMap(e=>[{key:e,tools:["transientPlant","stepSteer"],why:fg},{key:e,tools:["drive"],why:hg},{key:e,tools:["tyreReadouts"],why:wS,gap:"the envelope corners with the feedforward, the readouts split the same lap without it (rule 3)"},{key:e,tools:["plannerRequest"],why:"the planner allocates by capacity when vectoring is on, with no feedforward schedule (reduced planner model)"}]),{key:"brake_balance",tools:["ymd"],why:"no braking: the diagram is drawn at constant speed",ymd:{driving:"the diagram is drawn under acceleration, not braking",liveBraking:!0}},{key:"brake_balance",tools:["stepSteer"],why:"the speed is held by the drive; the test never brakes"},...["gear_ratio","power_scale","power_limit_kw","driven_wheels","effi_pgb"].map(e=>({key:e,tools:["ymd"],why:Z2,ymd:{moving:Q2}})),...["gear_ratio","power_scale","power_limit_kw"].flatMap(e=>[{key:e,tools:["envelopeTrim"],why:"the trim imposes the tyres\u2019 push (`axG`); what a motor could deliver is the envelope limits\u2019 question"},{key:e,tools:["tyreReadouts"],why:"the lap\u2019s motion carries the drive the powertrain made; the readouts only split it"},{key:e,tools:["stepSteer"],why:"the speed is held by a force (a PI loop on the drive), not through the powertrain"}]),{key:"power_scale",tools:["plannerRequest"],why:"the planner\u2019s drive is the motor model\u2019s axle force (`planDriveOf`), which `power_scale` does not scale",gap:"the envelope scales its drive by `power_scale` (`calcGGV`), the planner does not: two cars (rule 1)"},{key:"power_limit_kw",tools:["plannerRequest"],why:"the planner has no pack limit (reduced planner model)"},...["I_wheel","I_rotor"].flatMap(e=>[{key:e,tools:["ymd"],why:"rotating inertia only acts where the car changes speed",ymd:{moving:"rotating inertia is longitudinal, and `ax` is set here rather than solved \u2014 nothing in this picture spins a wheel up"}},{key:e,tools:["envelopeTrim"],why:"the trim imposes the tyres\u2019 push; rotating inertia acts where the speed changes (`rotatingInertia.ts`)"},{key:e,tools:["tyreReadouts"],why:"the lap\u2019s motion carries what the inertia cost; the readouts only split the force"},{key:e,tools:["stepSteer"],why:"no wheel rotation, and the speed is held"},{key:e,tools:["plannerRequest"],why:"the planner has no rotating inertia (reduced planner model)"}]),{key:"v_limit_endurance",tools:["ymd"],why:"a limiter constrains a lap\u2019s speed profile; this diagram is drawn at one imposed speed"},{key:"v_limit_endurance",tools:dg.filter(e=>e!=="ymd"),why:"a limiter constrains a distance event\u2019s speed profile (`runTrackLap`), and is live there (`wiring.test.ts`, LAP_KEYS)"},{key:"endurance_reserve",tools:["ymd"],why:"an energy budget sets the long event\u2019s speed ceiling; this diagram is drawn at one imposed speed"},{key:"endurance_reserve",tools:dg.filter(e=>e!=="ymd"),why:"an energy budget solves a distance event\u2019s speed ceiling (`runTrackLap`), and is live there (`wiring.test.ts`, LAP_KEYS)"},{key:"fr_0",tools:["ymd"],why:"rolling resistance is longitudinal",ymd:{moving:"rolling resistance is a drag term; `ax` is what the car does, not what the tyres are handed"}},{key:"fr_0",tools:["envelopeTrim"],why:"the trim takes the tyres\u2019 push as given; rolling resistance is a drag, not a tyre force"},{key:"fr_0",tools:["tyreReadouts"],why:"the lap\u2019s motion carries the drag (`LapMotion.axDrag`), rolling resistance in it"},{key:"fr_0",tools:["stepSteer"],why:"step steer\u2019s plant has no rolling resistance (`twoTrackSimFrom` without `rollingCoeff`), and its speed is held"},{key:"r_dyn",tools:["ymd"],why:"the rolling radius only matters where a wheel is driven or braked",ymd:{moving:"the force each tyre carries is set here in newtons; a radius would only convert it to a torque"}}];function FS(e=0){let t=[],r=new Set;for(let n of J2){if(!n.tools.includes("ymd")||n.onCar||r.has(n.key)||e<0&&n.ymd?.liveBraking)continue;r.add(n.key);let o=e>0?n.ymd?.driving??n.ymd?.moving??n.why:e<0?n.ymd?.moving??n.why:n.why;t.push({key:n.key,why:o})}return t}var CS=Math.PI/180;function LS(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 TS(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 DS(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,d]of[[s,1-c],[Math.min(o-1,s+1),c]])if(!(d<=0))for(let[p,h]of[[i,1-l],[Math.min(a-1,i+1),l]])h<=0||(u+=d*h*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])*CS||1,a=e.isoDelta.length>1?(e.isoDelta[1].deltaDeg[0]-e.isoDelta[0].deltaDeg[0])*CS:1,s=R=>DS(e,t,r,R),i=s((R,M)=>R.ay[M]),c=s((R,M)=>R.cn[M]),l=s((R,M)=>R.betaDeg[M]),u=s((R,M)=>R.deltaDeg[M]),m=s((R,M)=>TS(R.cn,M,o)),d=s((R,M,A)=>TS(e.isoDelta.map(F=>F.cn[M]),A,a||1)),p=Math.max(1e-6,e.maxAy),h=Math.abs(i)/p,f=Math.max(1e-6,...e.isoDelta.flatMap(R=>R.cn.filter(Number.isFinite).map(Math.abs))),b=Math.abs(c)/f,g=i===0?c:c*Math.sign(i),y=[];y.push(`${LS(l,i)}.`),b<.03?y.push("On the trim line: yaw moments balance, so this is a steady corner the car can actually hold. Only points on this line are real cornering states \u2014 everywhere else the car is still rotating."):g>0?y.push(`Not a steady state: there is a surplus yaw moment turning the car further into the corner, so it would keep rotating from here. To hold ${Math.abs(i).toFixed(2)} g the driver would have to wind ${u>=0?"off":"on"} steer until the point reaches the trim line.`):y.push("Not a steady state: the yaw moment is straightening the car out, so it would run wide from here. The car needs more steer, or more front grip, to reach the trim line at this slip angle.");let x=Math.abs(e.stability)>1e-9?m/e.stability:1;x<.15?y.push("Yaw stiffness has collapsed here: the moment resisting a change in body slip is essentially gone, so the car will not gather itself up if it steps out. Both axles are close to saturation."):x<.85?y.push(`Yaw stiffness is down to about ${(100*x).toFixed(0)} % of its straight-ahead value \u2014 the car resists a change in body slip less firmly here than it does in the linear range.`):y.push(`Yaw stiffness is near its straight-ahead value (${(100*x).toFixed(0)} %), so the car still opposes a change in body slip about as firmly as it does in a straight line.`);let k=Math.abs(e.control),v=k>1e-9?Math.abs(d)/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.`),h>.97?y.push(`At the edge of the diagram: ${Math.abs(i).toFixed(2)} g is essentially all this car has at this speed.`):h<.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:d,gripUsed:h,notes:y}}var PS=1e-4;function bg(e){let t=null,r=d=>{if(!t)return!0;let p=Math.abs(d),h=Math.abs(t.ay);return p>h*(1+PS)?!0:p<h*(1-PS)?!1:d>0&&t.ay<0};for(let d=0;d<e.isoDelta.length;d++){let p=e.isoDelta[d];for(let h=1;h<p.cn.length;h++){if(!(p.cn[h-1]===0||p.cn[h-1]<0!=p.cn[h]<0))continue;let b=p.cn[h-1]===p.cn[h]?0:p.cn[h-1]/(p.cn[h-1]-p.cn[h]),g=p.ay[h-1]+b*(p.ay[h]-p.ay[h-1]);r(g)&&(t={ay:g,d,b:b<.5?h-1:h})}}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}}function IS(e=0){return FS(e)}var e_=IS(0);function _S(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 t_=_S(0);var r_=9.81;function n_(e){let t=e.wheelbase/1e3;return{lf:t*(1-e.frontMassFrac),lr:t*e.frontMassFrac}}function uc(e,t,r,n){let o=t.tire;if(!o)return null;let s=(r==="limit"?Ib(e,o,t.speed):Hn(e,o,t.speed,t.ayG)).wheels;return Jr(n??So(o,e.massTotal*r_*1.2),{FL:s.FL,FR:s.FR,RL:s.RL,RR:s.RR},n_(e))}function o_(e){if(!e.tire)return e.cornerStiffness;let t=Fe(e.tire,"front"),r=Fe(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)=>Dm(e,t.ayG,o_(t),t.speed).gradient},{key:"rollGradient",label:"Roll gradient",unit:"\xB0/g",compute:e=>Be(e).rollGradient},{key:"pitchGradient",label:"Pitch gradient",unit:"\xB0/g",compute:e=>Be(e).pitchGradient},{key:"tlltdFront",label:"TLLTD front",unit:"%",compute:e=>100*Uf(e)},{key:"rollStiffFront",label:"Front roll-stiffness",unit:"%",compute:e=>100*Be(e).frontRollStiffFrac},{key:"rideFreqFront",label:"Ride freq front",unit:"Hz",compute:e=>Be(e).rideFreqFront},{key:"rideFreqRear",label:"Ride freq rear",unit:"Hz",compute:e=>Be(e).rideFreqRear},{key:"rollFreq",label:"Roll-mode freq",unit:"Hz",compute:e=>Nm(e).roll.freq},{key:"pitchFreq",label:"Pitch-mode freq",unit:"Hz",compute:e=>Nm(e).pitch.freq},{key:"zetaFront",label:"Damping \u03B6 front",unit:"-",compute:e=>Im(e).front.dampingRatio},{key:"zetaRear",label:"Damping \u03B6 rear",unit:"-",compute:e=>Im(e).rear.dampingRatio},{key:"yawFreq",label:"Yaw natural freq",unit:"Hz",compute:(e,t)=>lc(e,t.speed)?.yawFreq??NaN},{key:"yawZeta",label:"Yaw damping \u03B6",unit:"-",compute:(e,t)=>lc(e,t.speed)?.dampingRatio??NaN},{key:"stabilitySpeed",label:"Char./critical speed",unit:"km/h",compute:(e,t)=>{let r=lc(e,t.speed);return r?r.criticalSpeed??r.characteristicSpeed??NaN:NaN}},{key:"maxAy",label:"Max lateral accel",unit:"g",compute:(e,t)=>t.fyAxle?pg(e,t.fyAxle,t.speed,{betaMaxDeg:12,deltaMaxDeg:12}).maxAy:NaN},{key:"yawReserveRear",label:"Yaw stability reserve",unit:"N\xB7m",compute:(e,t)=>uc(e,t,"operating")?.stabil??NaN},{key:"yawReserveFront",label:"Yaw agility reserve",unit:"N\xB7m",compute:(e,t)=>uc(e,t,"operating")?.agil??NaN},{key:"limitBalance",label:"Limit balance (+US / \u2212OS)",unit:"-",compute:(e,t)=>uc(e,t,"limit")?.rel??NaN},{key:"yawStiffness",label:"Yaw stiffness N_\u03B2",unit:"N\xB7m/rad",compute:(e,t)=>t.tire?Eb(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorque",label:"Steering holding torque",unit:"N\xB7m",compute:(e,t)=>t.tire?Lb(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorqueGradient",label:"Steering feedback gradient",unit:"N\xB7m/g",compute:(e,t)=>t.tire?Db(e,t.tire,t.speed,t.ayG):NaN}],gg=Object.fromEntries(NS.map(e=>[e.key,e]));var Or=9.81;function a_(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 s_={front:!1,rear:!0};function us(e,t,r,n){let o=e.muX(t)*t,a=e.muY(t)*t;if(!(o>0))return 0;let s=a>0?Math.min(1,r/a):1;return n&&t>0?o*Zf(n,t,s):o*Math.sqrt(1-s*s)}function OS(e,t,r,n,o,a,s,i){let c=e[t]+e[r];if(!(c>0))return;let l=us(n,o[t],a[t],i),u=us(n,o[r],a[r],i),m=!(l+u>0);if(m&&(l=n.muX(o[t])*o[t],u=n.muX(o[r])*o[r]),!(l+u>0))return;let d=s?.[t],p=s?.[r];if(d===void 0&&p===void 0){e[t]=c*(l/(l+u)),e[r]=c-e[t];return}let h=[Math.min(l,d??1/0),Math.min(u,p??1/0)],f=m?void 0:VS(n,o,a,t,r,l,u,s,i);if(f&&c>h[0]+h[1]){let b=Math.min(c-f.capC,f.xMax),g=Math.min(a[f.o],f.fyO(b));a[f.c]+=a[f.o]-g,a[f.o]=g,e[f.o]=b,e[f.c]=c-b;return}e[t]=BS(c,h,[l,u])[0],e[r]=c-e[t]}function VS(e,t,r,n,o,a,s,i,c){let l=i[n]??1/0,u=i[o]??1/0,m,d,p;if(l<a&&!(u<s))[m,d,p]=[n,o,s];else if(u<s&&!(l<a))[m,d,p]=[o,n,a];else return;let h=i[m],f=i[d]??1/0,b=e.muX(t[d])*t[d],g=e.muY(t[d])*t[d],y=e.muX(t[m])*t[m],x=e.muY(t[m])*t[m];if(!(b>0&&g>0&&y>0&&x>0))return;let k=(P,S)=>c?Cv(c,P,S):Math.sqrt(Math.max(0,1-S*S)),v=(P,S)=>c?Zf(c,P,S):Math.sqrt(Math.max(0,1-S*S)),R=P=>g*k(t[d],P/b),M=x*k(t[m],h/y),A=r[m]+r[d]-M,F=Math.min(f,b*v(t[d],0)),T=A<=0?F:Math.max(p,Math.min(F,A<g?b*v(t[d],A/g):0));return{c:m,o:d,capC:h,xMax:T,fyO:R}}function BS(e,t,r){let n=t.reduce((a,s)=>a+s,0),o=r.reduce((a,s)=>a+s,0);return n>0&&e<=n?t.map(a=>e*a/n):o>n&&e<=o?t.map((a,s)=>a+(e-n)*(r[s]-a)/(o-n)):r.map(a=>e*a/o)}function $S(e,t,r,n,o,a={},s="open",i,c){if(!e.rear)return 1;if(!e.front)return 0;let l=(b,g,y)=>y?Ei(b,g,y):s==="own"?b+g:2*Math.min(b,g),u={FL:us(n,t.FL,r.FL,c?.front),FR:us(n,t.FR,r.FR,c?.front),RL:us(o,t.RL,r.RL,c?.rear),RR:us(o,t.RR,r.RR,c?.rear)},m=(b,g)=>u[g],d=l(u.FL,u.FR,a.front),p=l(u.RL,u.RR,a.rear);if(i&&i.total>0&&d+p>0){let b=(R,M)=>Math.min(m(R,M),i.caps[M]??1/0),g=(R,M,A,F,T)=>{let P=M==="FL"?c?.front:c?.rear,S=F||s!=="own"?void 0:VS(R,t,r,M,A,m(R,M),m(R,A),i.caps,P),w=S?S.capC+S.xMax:l(b(R,M),b(R,A),F);return[w,Math.max(T,w)]},[y,x]=g(n,"FL","FR",a.front,d),[k,v]=g(o,"RL","RR",a.rear,p);return BS(i.total,[y,k],[x,v])[0]/i.total}if(d+p>0)return d/(d+p);let h=n.muX(t.FL)*t.FL+n.muX(t.FR)*t.FR,f=o.muX(t.RL)*t.RL+o.muX(t.RR)*t.RR;return h+f>0?h/(h+f):.5}function yg(e,t,r,n){return{car:t?HS(t,r.loadFactor[n]):e,ayTyre:at(r.ay[n],r.bank?.[n]??0),axCar:r.ax[n]-(r.axGrade?.[n]??0)}}function GS(e,t){if(!e.aero?.model)return 0;let r=Math.min(t.v.length,t.ax.length,t.ay.length),n=t.loadFactor?$m(e):void 0,o=0,a=0;for(let s=0;s<r;s++){let i=t.ds?.[s]??1,c=yg(e,n,t,s);o+=i,jf(c.car,t.v[s],c.axCar/Or,c.ayTyre/Or)&&(a+=i)}return o>0?a/o:0}function KS(e,t,r){let n=fr(Fe(t,"front")),o=fr(Fe(t,"rear")),a=Math.min(r.v.length,r.ax.length,r.ay.length),s=r.loadFactor?$m(e):void 0,i=0,c=0;for(let l=0;l<a;l++){let u=r.ds?.[l]??1,m=yg(e,s,r,l);i+=u;let d=$e(m.car,m.ayTyre/Or,m.axCar/Or,r.v[l]);(d.FL>n||d.FR>n||d.RL>o||d.RR>o)&&(c+=u)}return i>0?c/i:0}function Bm(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=Xa(t,e.massTotal*Or*1.2),l=Oa(c,"front"),u=Oa(c,"rear"),m={mu:1},d=K=>({muX:D=>m.mu*K.muX(D),muY:D=>m.mu*K.muY(D)}),p=r.mu?d(l):l,h=r.mu?u===l?p:d(u):u,f=r.mu?{front:p,rear:h}:c,b=Dt(Fe(t,"front")),g=Dt(Fe(t,"rear")),y=Jf(b,l),x=g===b?y:Jf(g,u),k={front:y,rear:x},v=n.driven??s_,R={front:qt(e,"front",1),rear:qt(e,"rear",1)},M={front:0,rear:0},A=new Array(o),F=new Array(o),T=new Array(o),P=1/0,S=0,w=0,C=fr(b),L=fr(g),E=0,_=0,O=0,I=0,z=0,B=0,V=["FL","FR","RL","RR"],j=n.perWheel?Object.fromEntries(V.map(K=>[K,{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,q=r.loadFactor?$m(e):void 0;for(let K=0;K<o;K++){let D=yg(e,q,r,K),{ayTyre:N,axCar:Y}=D,H=N/Or,W=$e(D.car,H,Y/Or,r.v[K]),X=r.mu?Fm(r.mu,K):1;m.mu=X;let ne=e.massTotal*N,Z=ne*i/a,xe=ne*s/a,de=pi(b,Z/X,W.FL,W.FR,z),be=pi(g,xe/X,W.RL,W.RR,B);z=de,B=be;let U={FL:X*Math.abs(b.Fy(de,W.FL,0)),FR:X*Math.abs(b.Fy(de,W.FR,0)),RL:X*Math.abs(g.Fy(be,W.RL,0)),RR:X*Math.abs(g.Fy(be,W.RR,0))},ee=(Y-(r.axDrag?.[K]??0)-(r.axScrub?.[K]??0))/Or,se=r.wheelMotor,ie=se?Object.fromEntries(V.flatMap(Ae=>se[Ae]?[[Ae,se[Ae][K]*e.massTotal]]:[])):void 0,Re=ie?{total:ee*Or*e.massTotal,caps:ie}:void 0,pe=ee>0&&v.front?$S(v,W,U,p,h,R,"own",Re,k):0,ce=r.v[K]*r.v[K],Pe=e.driveline?{Fz:W,alpha:{front:de,rear:be},curvature:ce>1?r.ay[K]/ce:0,seed:M,...X!==1?{grip:X}:{}}:void 0,ke={...Tb(e,ee,r.v[K],t,H,pe,Pe,X)};ee>0&&(R.front||OS(ke,"FL","FR",p,W,U,ie,y),R.rear||OS(ke,"RL","RR",h,W,U,ie,x));let ae=!1,ge=!1;for(let Ae of["FL","FR","RL","RR"]){let Ge=(Ae==="FL"||Ae==="FR"?p:h).muX(W[Ae])*W[Ae];Math.abs(ke[Ae])>Ge&&(ae=!0),W[Ae]>(Ae==="FL"||Ae==="FR"?C:L)&&(ge=!0)}ge&&(w+=r.ds?.[K]??1);let fe=Jr(f,{FL:{Fz:W.FL,Fy:U.FL,Fx:ke.FL},FR:{Fz:W.FR,Fy:U.FR,Fx:ke.FR},RL:{Fz:W.RL,Fy:U.RL,Fx:ke.RL},RR:{Fz:W.RR,Fy:U.RR,Fx:ke.RR}},{lf:s,lr:i});if(A[K]=fe.stabil,F[K]=fe.agil,T[K]=fe.rel,j){let Ae=.5*(W.FL+W.FR),Ge=.5*(W.RL+W.RR),Ne=p.muX(Ae)*Ae,Te=h.muX(Ge)*Ge;for(let ye of V){let me=W[ye],Me=ye==="FL"||ye==="FR",Xe=Me?p:h,Ye=Xe.muY(me)*me,Le=Xe.muX(me)*me,Ke=j[ye],vt=Me?de:be;Ke.Fz[K]=me,Ke.alpha[K]=vt,Ke.Fy[K]=U[ye],Ke.Fx[K]=ke[ye],Ke.Mz[K]=me>0?X*(Me?b:g).Mz(vt,me,0):0,Ke.FxCap[K]=Le,Ke.FyCap[K]=Ye;let Nt=Ye>0?Math.min(1,Math.abs(U[ye])/Ye):0,Sr=a_(ke[ye],Le,Me?Ne:Te),wn=Me?y:x,mt=wn&&me>0?wn.reach(me,Math.sign(ke[ye])*Sr,Nt):1;Ke.used[K]=Math.hypot(Nt,Sr)/mt}}fe.stabil<P&&(P=fe.stabil,S=K);let Ce=r.ds?.[K]??1;I+=Ce,fe.diff>0&&(E+=Ce),ae&&(_+=Ce),jf(D.car,r.v[K],Y/Or,H)&&(O+=Ce)}return{stabil:A,agil:F,rel:T,minStabil:Number.isFinite(P)?P:0,minStabilAt:S,pastTurnoverFrac:I>0?w/I:0,understeerFrac:I>0?E/I:0,beyondFrac:I>0?_/I:0,aeroOutsideFrac:I>0?O/I:0,wheels:j}}function $m(e){return Object.create(e,{loadFactor:{value:1,writable:!0,enumerable:!0}})}function HS(e,t){return e.loadFactor=t,e}var xg=9.81;function Rg(e,t,r,n={}){let o=r.v.length,a=e.massTotal,s=un(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),d=m-(r.axDrag?.[l]??0)-(r.axScrub?.[l]??0),p=-a*d;if(!(p>0))continue;let h=at(r.ay[l],r.bank?.[l]??0)/xg,f=Math.min(.99,Math.max(.01,Ya(e,d/xg,u,t,h)));c.front[l]=p*f,c.rear[l]=p*(1-f);let b=i?Ku(e,t,p,u,h):void 0;if(c.regen&&n.regen&&(c.regen[l]=b?Math.min(p,b.regenFront+b.regenRear):n.regen(p,u,m/xg)),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 MJ=Math.PI/180;var SJ=lg.map(Ki);var AJ=[he.zFL,he.zFR,he.zRL,he.zRR];var wJ=Array.from({length:he.rollRate+1},(e,t)=>t);var x_=9.81,R_=.001,v_=.6,k_=2,jS=4;function US(e,t,r,n=jS){let o=Math.min(e.v.length,t.npts),{ds:a,closed:s}=t,i=r.massTotal*x_*r.wheelbase,c=M_(e.ay.slice(0,o).map((m,d)=>m/Math.max(R_,e.v[d])),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 d=m===0?s?o-1:-1:m-1,p=m===o-1?s?0:-1:m+1;if(d<0||p<0)continue;let h=a[d]+a[m];if(!(h>0))continue;u[m]=e.v[m]*(c[p]-c[d])/h;let f=Math.sign(c[m]);l[m]=f===0?0:f*r.yawInertia*u[m]/i}return{demand:l,rdot:u}}function M_(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,d=0;for(let p=1;p<=s&&!(!r&&c+p>=o||(d+=t[(c+p-1)%o],!(d<l)));p++){let h=1-d/l;u+=h*e[(c+p)%o],m+=h}d=0;for(let p=1;p<=s&&!(!r&&c-p<0);p++){let h=(c-p+o)%o;if(d+=t[h],!(d<l))break;let f=1-d/l;u+=f*e[h],m+=f}i[c]=u/m}return i}function XS(e,t,r,n,o={}){let a=o.maxIter??20,s=o.tol??.001,i=Math.min(1,Math.max(.001,o.relax??v_)),c=o.smoothM??jS,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=Kt(e.steady,t,n,l),m=[u.laptime],d=new Array(t.npts).fill(0),p=d.slice(),h=u,f=0,b=!1,g=0;for(let k=0;k<a;k++){f=k+1;let v=US(h,t,r,c);d=v.demand.map((A,F)=>d[F]+i*(A-d[F])),p=v.rdot;let R=Kt(e.steady,t,n,{...l,envelope:A=>e.at(d[A]??0)});m.push(R.laptime);let M=Math.abs(R.laptime-h.laptime);if(h=R,g=M<=s?g+1:0,g>=k_){b=!0;break}}let y=0,x=0;for(let k=0;k<t.npts;k++)x+=t.ds[k],e.clamps(d[k]??0)&&(y+=t.ds[k]);return{...h,steady:u,demand:d,rdot:p,history:m,iterations:f,converged:b,clampedFrac:x>0?y/x:0}}var _J=Math.PI/180;var Ree=180/Math.PI;function vn(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=d=>{let p=e[d];return i*(r-s)*(r-p)/((a-s)*(a-p))+c*(r-a)*(r-p)/((s-a)*(s-p))+t[d]*(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 QS(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(f=>f.v),ayMax:p.map(f=>f.ayMax),radius:p.map(f=>Math.max(f.v,t)**2/f.ayMax),accel:p[0].axAccelN.map((f,b)=>p.map(g=>g.axAccelN[b])),decel:p[0].axDecelN.map((f,b)=>p.map(g=>g.axDecelN[b])),scrub:p[0].axScrubN.map((f,b)=>p.map(g=>g.axScrubN[b])),motors:p.every(f=>f.motorTyreN&&f.motorLoss)?{tyreN:p[0].motorTyreN.map((f,b)=>f.map((g,y)=>p.map(x=>x.motorTyreN[b][y]))),loss:p[0].motorLoss.map((f,b)=>p.map(g=>g.motorLoss[b])),gain:p.every(f=>f.motorGain)?p[0].motorGain.map((f,b)=>f.map((g,y)=>p.map(x=>x.motorGain[b][y]))):void 0}:void 0}),s=(p,h)=>({axAccelN:p.accel.map(f=>vn(p.vs,f,h)),axDecelN:p.decel.map(f=>vn(p.vs,f,h)),axScrubN:p.scrub.map(f=>vn(p.vs,f,h)),...p.motors?{motorTyreN:p.motors.tyreN.map(f=>f.map(b=>vn(p.vs,b,h))),motorLoss:p.motors.loss.map(f=>vn(p.vs,f,h)),...p.motors.gain?{motorGain:p.motors.gain.map(f=>f.map(b=>vn(p.vs,b,h)))}:{}}:{}});if(!o){let p=a(e);return h=>({ayMax:vn(p.vs,p.ayMax,h),...s(p,h)})}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/vn(i.vs,i.radius,p),d=p=>p>=u||c.vs.length<2?vn(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:d(p),...s(c,p)};let h=m(p),f=d(p);return h<f?{ayMax:h,...s(i,p)}:{ayMax:f,...s(c,p)}}}function $_(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 ZS(e,t,r,n,o){let a=r>t?Math.max(2,Math.min(5,Math.floor(n))):1,s=[];for(let d=0;d<a;d++)s.push(e(a===1?t:t+(r-t)*d/(a-1)));let i=QS(s,t),c=[],l=a,u=(d,p)=>{let h=.5*(d+p),f=e(h);l++;let b=$_(i(h),f);s.splice(s.findIndex(g=>g.v>h),0,f),i=QS(s,t),b>o&&c.push({lo:d,hi:h,misfit:b},{lo:h,hi:p,misfit:b})},m=s.map(d=>d.v);for(let d=0;d+1<m.length&&l<n;d++)m[d+1]-m[d]>=1&&u(m[d],m[d+1]);if(m.length>1){let d=.5*(m[0]+m[1]);if(s.some(p=>p.v===d))for(let[p,h]of[[m[0],d],[d,m[1]]]){if(l>=n||h-p<1)break;let f=c.findIndex(b=>b.lo===p&&b.hi===h);f>=0&&c.splice(f,1),u(p,h)}}for(;l<n&&c.length>0;){let d=0;for(let b=1;b<c.length;b++)c[b].misfit>c[d].misfit&&(d=b);let{lo:p,hi:h,misfit:f}=c.splice(d,1)[0];if(f<=o)break;h-p<1||u(p,h)}return{anchors:s,at:i}}var G_=2,K_=.5,mc=Math.PI/180,JS=21,H_={nCoarse:11,nSteer:13,nNorm:41,nAngle:45},z_={nCoarse:11,nSteer:13,nNorm:41,nAngle:61},Y_=.005,W_=.05,vg=e=>e<0?0:e>1?1:e;function j_(e,t,r,n){let o=e.massTotal,a=n.nSteer??7,s=(n.drivenFront?2:0)+(n.drivenRear?2:0),i=$e(e,0,0,r),c=Math.max(1,(i.FL+i.FR+i.RL+i.RR)/4),l=8*mc,u=0,m=(b,g,y)=>{for(let x=b;x<=g;x+=y){let k=Math.abs(t.Fy(x*mc,c,0));k>u&&(u=k,l=x*mc)}};m(1,45,1),m(Math.max(.1,l/mc-1),l/mc+1,.1);let d=[],p=[],h=[],f=[];for(let b=0;b<a;b++){let g=b/(a-1),y=l*(g+Math.sin(Math.PI/2*g))/2,x=Math.abs(t.Fy(y,c,0));d.push(4*x/o),p.push(s*jt(t,c,x,!1)/o),h.push(4*jt(t,c,x,!0)/o),f.push(-4*x*Math.sin(y)/o)}return d[0]=0,{ayMax:4*u/o,ay:d,axAccel:p,axDecel:h,axScrub:f,rollover:!1}}function U_(e,t,r){if(e.engine)return;let n=Do(e.params),o=hr(e.params),a=[];for(let s of["front","rear"]){if(!(s==="front"?t:r))continue;let[i,c]=s==="front"?["FL","FR"]:["RL","RR"];if(n[s]==="independent")a.push({wheels:[i],axle:s,motors:o[s]/2},{wheels:[c],axle:s,motors:o[s]/2});else if(n[s]==="diff")a.push({wheels:[i,c],axle:s,motors:o[s]});else return}return a.length>1?a:void 0}var X_=.001;function eA(e,t){let r=e.flatMap((n,o)=>n===void 0?[]:[o]);return r.length===0?e.map(()=>t):e.map((n,o)=>{if(n!==void 0)return n;let a=r[0];for(let s of r)Math.abs(s-o)<Math.abs(a-o)&&(a=s);return e[a]})}var q_=.01,Q_=.05;function tA(e,t,r,n){let o=0,a=0;for(let s of e.motors){let i=r*s.tyreN[t]*e.axAccelN[t],c=s.share>0?s.share*n:0;i>c&&(o+=i-c,a+=c)}return{short:o,theirs:a}}function pc(e,t,r,n){let o=e.motors;if(!o)return 1/0;let a=n>=1?e.axDrive:n*e.axDrive,s=r*e.axAccelN[t],{short:i,theirs:c}=tA(e,t,r,a);if(!(i>0))return s;let l=e.motorLoss?.[t]??1;if(r===1&&n>=1||!o.every(h=>h.gain)){let h=r>=1?l:l/(r+l*(1-r));return Math.max(c,s-h*i)}let u=Math.min(s,rA(e,t,r,a)),m=tA(e,t,1,e.axDrive);if(!(m.short>0))return Math.max(c,u);let p=Math.max(m.theirs,e.axAccelN[t]-l*m.short)-Math.min(e.axAccelN[t],rA(e,t,1,e.axDrive));return Math.max(c,Math.min(s,u+p*(i/m.short)))}function rA(e,t,r,n){let o=e.motors,a=r*e.axAccelN[t],s=a;for(let i=0;i<=o.length+1;i++){let c=0,l=0,u=0;for(let d of o){let p=r*d.gain[t],h=r*d.tyreN[t]*e.axAccelN[t],f=d.share>0?d.share*n:0,b=h+p*(s-a);u+=Math.min(f,b),(p>0?b<=f:b<f)?(l+=p,c+=h-p*a):c+=f}if(!(u<s))return s;if(!(l<1))return 0;let m=c/(1-l);if(!(m<s))return s;s=m}return s}function kg(e,t,r,n,o){if(!e.motors)return 1/0;let a=t.length-1;if(!(r<t[a]))return pc(e,a,n,o);let s=0,i=a;for(;i-s>1;){let u=s+i>>1;t[u]<=r?s=u:i=u}let c=(r-t[s])/(t[i]-t[s]),l=pc(e,s,n,o);return c===0?l:l+c*(pc(e,i,n,o)-l)}function Vr(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?z_:H_),{nCoarse:c,nSteer:l,nAngle:u}=i,m=ln(0,1,i.nNorm).map(D=>Math.sin(Math.PI/2*D)),d=e.params,p=d.m.value,h=d.rho.value,f=d.fr_0.value,b=d.driven_wheels.value,g=d.power_scale.value,y=e.FG,x=It(d);s!==1&&(x.loadFactor=s);let k=Nr(d),v=J1(0,n?.vRes??(e.engine?K_:G_),e.vMax);v[v.length-1]<e.vMax&&v.push(e.vMax);let R=e.fRad.map(D=>D*b),M=e.fAxle,{drivenFront:A,drivenRear:F}=Oo(e),T=No(d,A,F),P=(D,N)=>{let Y=M?ht(M.vVehicle,D,N):NaN;return Number.isFinite(Y)?Y:1/0},S=r==="fast"?void 0:U_(e,A,F),w=hr(d),C=(D,N)=>{if(M){let H=P(M.fFront,N),W=P(M.fRear,N),X=D.map(Z=>(Z.axle==="front"?H:W)*(Z.motors/w[Z.axle])),ne=X.reduce((Z,xe)=>Z+xe,0);if(Number.isFinite(ne)&&ne>0)return X.map(Z=>Z/ne)}let Y=D.reduce((H,W)=>H+W.motors,0);return D.map(H=>H.motors/Y)},L=D=>{let N=D*D,{cl:Y,cw:H,A:W}=km(d,D,0,x),X=.5*h*-H*W*N,ne=.5*h*-Y*W*N,Z=f*(-ne+y);return X+Z},E=D=>{let N=L(D)/p*T.powerFactor,Y=L(D)/p*T.tractionFactor,H;if(e.engine){let X=L(D);H=Ha(e.engine,D,T.effective,X,g).accel-N}else if(M){let X=0;A&&(X+=P(M.fFront,D)),F&&(X+=P(M.fRear,D)),H=g*X/p*T.powerFactor}else{let X=ht(e.vVehicle,R,D),ne=g*X/p*T.powerFactor;H=Number.isFinite(ne)?ne:1/0}let W=Tm(d,D,o)/p*T.powerFactor;return{axDrag:N,axDragTyre:Y,axDrive:H,axPackCap:W,axPower:Math.min(H,W)}},_=v.map(E),O=e.vMax;for(let D=1;D<v.length;D++){let N=_[D].axDrive+_[D].axDrag;if(N>0)continue;let Y=_[D-1].axDrive+_[D-1].axDrag;O=Y>0?v[D-1]+(v[D]-v[D-1])*Y/(Y-N):v[D-1];break}let I=Math.min(e.vMax,(1+W_)*O),z=r==="fast"?j_:Nb,B=D=>{let N=S?E(D).axDrive:1/0,Y=S&&Number.isFinite(N)?C(S,D).map((ie,Re)=>({wheels:S[Re].wheels,cap:ie*N*p/T.tractionFactor})):void 0,H=z(x,k,D,{drivenFront:A,drivenRear:F,nSteer:l,yawDemandCn:a,axDrag:L(D)/p,...d.diffYaw?{diffYaw:!0}:{},...Y?{motorCaps:Y}:{}}),W=H.ay[0],X=H.ay[H.ay.length-1],ne=ie=>Math.min(Math.max(ie*H.ayMax,W),X),Z=m.map(ie=>Eu(H.ay,H.axAccel,ne(ie))*T.tractionFactor),xe=m.map(ie=>Eu(H.ay,H.axDecel,ne(ie))),de=m.map(ie=>Eu(H.ay,H.axScrub,ne(ie))*T.tractionFactor),be=H.axAccelWheels,U=H.axAccelHeld,ee=H.axAccelWheelsHeld,se=S&&Y&&be&&U?(()=>{let ie=S.map(ke=>H.ay.map((ae,ge)=>ke.wheels.reduce((fe,Ce)=>fe+be[ge][Ce],0))),Re=ie.map(ke=>{let ae=ke.map((ge,fe)=>ge/Math.max(H.axAccel[fe],X_));return m.map(ge=>ht(H.ay,ae,ne(ge)))}),pe=H.ay.map((ke,ae)=>{let ge=ie.reduce((fe,Ce,Ae)=>fe+Math.max(0,Ce[ae]-Y[Ae].cap/p),0);return ge>q_?Math.max(0,H.axAccel[ae]-U[ae])/ge:void 0}),ce=m.map(ke=>ht(H.ay,eA(pe,1),ne(ke))),Pe=ee?S.map((ke,ae)=>{let ge=H.ay.map((fe,Ce)=>{let Ae=ee[Ce],Ge=H.axAccel[Ce]-U[Ce];if(!(!Ae||!(Ge>Q_)))return(ie[ae][Ce]-ke.wheels.reduce((Ne,Te)=>Ne+Ae[Te],0))/Ge});return m.map(fe=>ht(H.ay,eA(ge,0),ne(fe)))}):void 0;return{motorTyreN:Re,motorLoss:ce,...Pe?{motorGain:Pe}:{}}})():void 0;return{v:D,ayMax:H.ayMax,axAccelN:Z,axDecelN:xe,axScrubN:de,...se??{},atLock:H.atLock===!0}},V=r==="fast"?0:Math.min(qu,I),j=ZS(B,V,I,c,i.anchorTol??Y_),q=[],K=[];for(let D=0;D<v.length;D++){let N=v[D],{axDrag:Y,axDragTyre:H,axDrive:W,axPackCap:X,axPower:ne}=_[D],{ayMax:Z,axAccelN:xe,axDecelN:de,axScrubN:be,motorTyreN:U,motorLoss:ee,motorGain:se}=j.at(N),ie=S&&U&&ee?C(S,N):void 0,Re=S&&U&&ie?S.map((ae,ge)=>({wheels:ae.wheels,share:ie[ge],tyreN:U[ge],...se?{gain:se[ge]}:{}})):void 0,pe={v:N,ayMax:Z,axTyreAcc:xe[0],axTyreDec:de[0],axDrive:W,axPackCap:X,axPower:ne,axDrag:Y,axDragTyre:H,axAccelN:xe,axDecelN:de,axScrubN:be,...Re&&ee?{motors:Re,motorLoss:ee}:{}};q.push(pe);let ce=[],Pe=[];for(let ae=0;ae<u;ae++){let ge=Math.PI*ae/(u-1),fe=Z*Math.cos(ge),Ce=vg(Math.abs(Math.cos(ge))),Ae=Math.min(ht(m,xe,Ce)+H,ne+Y,kg(pe,m,Ce,1,1)+Y);ce.push({ax:Ae+ht(m,be,Ce),ay:fe,v:N})}for(let ae=u-1;ae>=0;ae--){let ge=Math.PI*ae/(u-1),fe=Z*Math.cos(ge),Ce=vg(Math.abs(Math.cos(ge)));Pe.push({ax:ht(m,de,Ce)+Y+ht(m,be,Ce),ay:fe,v:N})}let ke=(ae,ge,fe)=>Array.from({length:JS},(Ce,Ae)=>({ax:ge+(fe-ge)*(Ae+1)/(JS+1),ay:ae,v:N}));K.push([...ce,...ke(-Z,ce[ce.length-1].ax,Pe[0].ax),...Pe,...ke(Z,Pe[Pe.length-1].ax,ce[0].ax)])}return{...sA(q,m),rows:q,norm:m,surf:K}}function ms(e,t){return e?.length?t.map(r=>Km(e,r)):t.map(()=>0)}function oA(e,t){let r=e?.[0]?.motors;if(!e||!r)return;let n={};return r.forEach((o,a)=>{o.wheels.length===1&&(n[o.wheels[0]]=t.map(s=>aA(e,s,i=>i.motors&&i.motors[a].share>0?i.motors[a].share*i.axDrive:0)))}),Object.keys(n).length?n:void 0}function Km(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 aA(e,t,r){let n=e.length-1;if(!(t>e[0].v))return r(e[0]);if(t>=e[n].v)return r(e[n]);let o=0,a=n;for(;a-o>1;){let l=o+a>>1;e[l].v<=t?o=l:a=l}let s=r(e[o]),i=r(e[a]);if(!Number.isFinite(s)||!Number.isFinite(i))return Math.max(s,i);let c=(t-e[o].v)/(e[a].v-e[o].v);return s+c*(i-s)}function sA(e,t){let r=e[e.length-1].v,n=f=>{if(f<=e[0].v)return{i0:0,i1:0,t:0};if(f>=r)return{i0:e.length-1,i1:e.length-1,t:0};let b=0,g=e.length-1;for(;g-b>1;){let y=b+g>>1;e[y].v<=f?b=y:g=y}return{i0:b,i1:g,t:(f-e[b].v)/(e[g].v-e[b].v)}},o=f=>{let{i0:b,i1:g,t:y}=n(f);return{a:e[b],b:e[g],t:b===g?0:y}},a=(f,b,g)=>f===0||b===g?b:b+f*(g-b),s=(f,b,g,y)=>f===0?ht(t,b,y):a(f,ht(t,b,y),ht(t,g,y)),i=(f,b)=>b>=1?f.axPower:Math.min(b*f.axDrive,f.axPackCap),c=({a:f,b,t:g},y,x)=>f.axScrubN?x*s(g,f.axScrubN,b.axScrubN,y):0,l=f=>f.axDragTyre??f.axDrag,u=({a:f,b,t:g},y,x)=>{let k=x*a(g,f.ayMax,b.ayMax);return k>0?vg(y/k):1},m=({a:f,b,t:g},y,x,k)=>a(g,kg(f,t,y,x,k),g===0?0:kg(b,t,y,x,k))+a(g,f.axDrag,b.axDrag),d=(f,b,g=1,y=1)=>{let{a:x,b:k,t:v}=f,R=u(f,b,g),M=g*s(v,x.axAccelN,k.axAccelN,R)+a(v,l(x),l(k)),A=a(v,i(x,y),v===0?0:i(k,y))+a(v,x.axDrag,k.axDrag);return x.motors?Math.min(M,A,m(f,R,g,y))+c(f,R,g):Math.min(M,A)+c(f,R,g)},p=(f,b,g=1,y=1)=>{let{a:x,b:k,t:v}=f,R=u(f,b,g),M=s(v,x.axDecelN,k.axDecelN,R);return(y===1||M>0?g*M:y*g*M)+a(v,x.axDrag,k.axDrag)+c(f,R,g)},h=({a:f,b,t:g},y,x=1)=>{let k=t.length-1,v=f.axAccelN,R=b.axAccelN,M=f.axDecelN,A=b.axDecelN,F=f.axScrubN,T=b.axScrubN,P=I=>v[I]+g*(R[I]-v[I]),S=I=>M[I]+g*(A[I]-M[I]),w=I=>F?x*(F[I]+g*(T[I]-F[I])):0,C=a(g,f.ayMax,b.ayMax),L=a(g,f.axDrag,b.axDrag),E=a(g,l(f),l(b)),_=a(g,f.axPower,b.axPower),O=f.motors?I=>a(g,pc(f,I,x,1),g===0?0:pc(b,I,x,1)):null;for(let I=k;I>=0;I--){let z=O?Math.min(x*P(I)+E,_+L,O(I)+L)+w(I):Math.min(x*P(I)+E,_+L)+w(I),B=x*S(I)+L+w(I);if(!(y<=z+1e-6&&y>=B-1e-6))continue;if(I===k)return t[I]*x*C;let V=(D,N,Y)=>{if(Y(N))return 1;let H=(D-y)/(D-N);return H>0?Math.min(H,1):0},j=D=>y<=D+1e-6,q=D=>y>=D-1e-6,K=Math.min(V(x*P(I)+E+w(I),x*P(I+1)+E+w(I+1),j),V(_+L+w(I),_+L+w(I+1),j),V(x*S(I)+L+w(I),x*S(I+1)+L+w(I+1),q),O?V(O(I)+L+w(I),O(I+1)+L+w(I+1),j):1);return(t[I]+K*(t[I+1]-t[I]))*x*C}return 0};return{vMax:r,axAccel:(f,b,g=1,y=1)=>d(o(f),b,g,y),axDecel:(f,b,g=1,y=1)=>p(o(f),b,g,y),ay:(f,b,g=1)=>h(o(f),b,g),scrub:(f,b,g=1)=>{let y=o(f);return c(y,u(y,b,g),g)},power:(f,b,g=1)=>{let y=o(f),{a:x,b:k,t:v}=y,M=(Number.isFinite(x.axPower)&&Number.isFinite(k.axPower)?a(v,x.axPower,k.axPower):Math.max(x.axPower,k.axPower))+a(v,x.axDrag,k.axDrag);return x.motors?Math.min(M,m(y,u(y,b,g),g,1)):M}}}function Z_(e,t,r){let n=e.params,o=n.m.value,{drivenFront:a,drivenRear:s}=Oo(e),i=No(n,a,s);return c=>Tm(n,c,t,r)/o*i.powerFactor}function dc(e,t,r,n){let o=Z_(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{...sA(a,e.norm),rows:a,norm:e.norm}}var J_=[-.2,-.08,0,.06,.12,.2,.3];function iA(e,t=!1,r="twoTrack",n,o,a=J_){let s=[...new Set([...a,0])].sort((h,f)=>h-f),i=s.map(h=>Vr(e,t,r,n,o,h)),c=i[s.indexOf(0)],l=s[0],u=s[s.length-1],m=h=>{if(h<=l)return{i:0,t:0};if(h>=u)return{i:s.length-1,t:0};let f=0;for(;f<s.length-2&&s[f+1]<=h;)f++;return{i:f,t:(h-s[f])/(s[f+1]-s[f])}},d=h=>{let f=b=>{let{i:g,t:y}=m(b);return{a:h[g],b:h[Math.min(h.length-1,g+1)],t:y}};return b=>{let{a:g,b:y,t:x}=f(b);if(x===0)return g;let k=(v,R)=>v+x*(R-v);return{vMax:g.vMax,axAccel:(v,R,M=1,A=1)=>k(g.axAccel(v,R,M,A),y.axAccel(v,R,M,A)),axDecel:(v,R,M=1,A=1)=>k(g.axDecel(v,R,M,A),y.axDecel(v,R,M,A)),ay:(v,R,M=1)=>k(g.ay(v,R,M),y.ay(v,R,M)),scrub:(v,R,M=1)=>k(g.scrub?.(v,R,M)??0,y.scrub?.(v,R,M)??0)}}},p=h=>h<l||h>u;return{anchors:s,steady:c,clamps:p,at:d(i),atSoc(h,f,b){let g=i.map(y=>dc(y,h,f,b));return{anchors:s,steady:g[s.indexOf(0)],clamps:p,at:d(g)}}}}function cA(e,t,r,n="twoTrack",o){let a=[...new Set([...t,1])].sort((i,c)=>i-c),s=a.map(i=>i===1?r:Vr(e,!1,n,o,void 0,0,i));return{...nA(a,s),atSoc:(i,c,l)=>nA(a,s.map(u=>dc(u,i,c,l)))}}function nA(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 h=0;for(;h<r-1&&e[h+1]<=p;)h++;if(o=h,p===e[h])return;a=h+1;let f=e[h],b=e[h+1];if(r<2){n=2,c=(p-f)/(b-f),i=1-c;return}s=h===0?2:h+1===r||p-e[h-1]<e[h+2]-p?h-1:h+2;let g=e[s];n=3,i=(p-b)*(p-g)/((f-b)*(f-g)),c=(p-f)*(p-g)/((b-f)*(b-g)),l=(p-f)*(p-b)/((g-f)*(g-b))},m=p=>{let h=p(t[o]);if(n===1)return h;let f=p(t[a]);if(n===2)return i*h+c*f;let b=i*h+c*f+l*p(t[s]);return Math.min(Math.max(h,f),Math.max(Math.min(h,f),b))},d=(p,h,f,b,g)=>{if(u(p),n===1||f===0)return m(k=>g(k,f));let y=m(k=>k.ay(h,0,b));if(!(y>0))return m(k=>g(k,f));let x=f/y;return m(k=>g(k,x*k.ay(h,0,b)))};return{anchors:e,axAccel:(p,h,f,b=1,g=1)=>d(p,h,f,b,(y,x)=>y.axAccel(h,x,b,g)),axDecel:(p,h,f,b=1,g=1)=>{let y=x=>d(p,h,f,b,(k,v)=>k.axDecel(h,v,b,x));return g===1?y(1):eg(y(g),y(1),g)},scrub:(p,h,f,b=1)=>d(p,h,f,b,(g,y)=>g.scrub?.(h,y,b)??0),ay:(p,h,f,b=1)=>{if(u(p),n===1||f===0)return m(k=>k.ay(h,f,b));let g=k=>f>0?k.axAccel(h,0,b):-k.axDecel(h,0,b),y=m(g);if(!(y>0))return m(k=>k.ay(h,f,b));let x=f/y;return m(k=>k.ay(h,x*g(k),b))}}}var lA=new WeakMap;function Mg(e,t){let r=lA.get(e);if(!r){let n=cn(e).regen?sg(t??Xt(e)):void 0;r={inp:It(e),ev:Nr(e),...n?{regen:n}:{}},lA.set(e,r)}return r}function Sg(e,t,r){let n=Mg(e,r);return Rg(n.inp,n.ev,t,n.regen?{regen:n.regen}:{})}function Ag(e){let t=Et(e);if(t.mode!=="hydraulic")return null;let r=a=>a.heat?{heat:Oh(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 eN(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 wg(e,t,r,n,o,a=Ut){if(!e)return null;let s=eN(t);return{...e.front?{front:Cu(e.front.heat,e.front.discs,s.front,r,n,o.front,a)}:{},...e.rear?{rear:Cu(e.rear.heat,e.rear.discs,s.rear,r,n,o.rear,a)}:{}}}var tN=.5,rN=.02,nN=6,Hm=9,uA=1e-9,oN={FL:0,FR:0,RL:0,RR:0};function Fg(e){return e?[...new Set([...e.padCurve.factor,1])].sort((t,r)=>t-r):[1]}function aN(e,t,r){let n=Dr(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 mA(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 pA(e,t,r,n,o=()=>0){let a=Array.from({length:Hm},(m,d)=>r*d/(Hm-1)),s=Vi(),{front:i,rear:c}=n,l=a.map(m=>{let d=o(m),p=f=>mn(f,t,m,s).limitAt(0,0,oN,d).ax,h=p(e);return i.map(f=>c.map(b=>{if(f===1&&b===1)return 1;let g=h<0?p(aN(e,f,b))/h:1;return Math.abs(g-1)<uA?1:g}))}),u=a[1]-a[0];return{share(m,d,p){if(d===1&&p===1)return 1;let h=u>0?Math.min(Hm-2,Math.max(0,Math.floor(m/u))):0,f=u>0?Math.min(1,Math.max(0,(m-a[h])/u)):0,b=mA(i,d),g=mA(c,p),y=k=>{let v=l[k],R=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]),F=v[R][g.i]+g.t*(v[R][M]-v[R][g.i]);return A+b.t*(F-A)},x=y(h)+f*(y(Math.min(Hm-1,h+1))-y(h));return Math.abs(x-1)<uA?1:x}}}function sN(e,t){let{front:r,rear:n}=t;return(o,a)=>e.share(a,r?.[o]??1,n?.[o]??1)}var iN=e=>(e.front??[]).every(t=>t===1)&&(e.rear??[]).every(t=>t===1);function dA(e,t,r){let n=e(),o=1,a=t(n);if(iN(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<nN;c++){let l=e(sN(r,s));o++;let u=Math.abs(l.laptime-n.laptime);if(n=l,u<rN){i=!0;break}a=t(n);let m=(h,f)=>h&&f?h.map((b,g)=>b+tN*((f[g]??1)-b)):h,d=m(s.front,a.front),p=m(s.rear,a.rear);s={...d?{front:d}:{},...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}=Oo(e),s=No(n,o,a).effective,i=n.power_scale.value,{up:c,down:l}=Zh(r.engine.gearbox),u=r.engine.idleRpm,m=(d,p,h)=>(i*r.force(d,p)+h)/(s+r.inertiaMass(d,p));return{count:r.gears.length,up:c,down:l,kept:Jh(r.engine.gearbox),limitRpm:r.engine.limitRpm,best:d=>Ha(r,d,s,Km(t,d)*s,i).gear,share:(d,p)=>{let h=Km(t,d),f=h*s,b=Ha(r,d,s,f,i);if(p===b.gear)return 1;let g=b.accel-h;return g>0?Math.min(1,Math.max(0,(m(d,p,f)-h)/g)):0},rpm:(d,p)=>r.slipping(d,p)?u:r.rpm(d,p),vIdle:d=>r.gears[d]?.vIdle??0}}var fA=new WeakMap;function Tg(e){let t=fA.get(e.ggv);return t===void 0&&(t=Wn(e.vehicle,e.ggv.rows)??null,fA.set(e.ggv,t)),t??void 0}function cN(e){return e.gear&&e.engineRpm&&e.shifting?{gear:e.gear,rpm:e.engineRpm,shifting:e.shifting}:{}}function lN(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}:{},...cN(t)}}var Ym=class extends Error{constructor(t){super(t),this.name="EventError"}};function uN(e,t){let{ggv:r}=t,n=At(t.numerics),o=n.accelStep,a=Math.max(1,Math.round(e.distance/o)),s=os(r,new Array(a+1).fill(0),n);s[0].v=e.vStart??0;for(let h=0;h<s.length-1;h++){let f=s[h],b=s[h+1];f.v>=b.v||(f.ax=r.axAccel(f.v,0),b.v=Math.min(r.vMax,Math.sqrt(Math.max(0,f.v*f.v+2*f.ax*o))))}let i=Tg(t),c=i?Am(s.map(h=>h.v),new Array(a).fill(o),!1,i,(h,f,b)=>r.axAccel(f,0,1,b)):void 0;if(c){for(let h=0;h<=a;h++)s[h].v=c.v[h];for(let h=0;h<a;h++)s[h].ax=(s[h+1].v*s[h+1].v-s[h].v*s[h].v)/(2*o)}let l=0;for(let h=0;h<a;h++){let f=s[h].v+s[h+1].v;f>0&&(l+=2*o/f)}let u=s.slice(0,a).map(h=>h.v),m=s.slice(0,a).map(h=>h.ax),d=new Array(a).fill(o),p=d.map((h,f)=>f*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:MA(t,d,[...u,s[a].v],m,1)}}function mN(e,t){let r=Math.max(1,Math.round(e.laps??1)),[n]=os(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=MA(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 Wm(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 pN(e,t){let r=e.distance!=null?t.v_limit_endurance?.value??0:0;return r>0?r/3.6:void 0}function dN(e,t){if(e.distance==null||pt(t.motorModel))return 0;let r=t.endurance_reserve?.value??0;return r>0?Math.min(r,95)/100:0}var hA=1;function RA(e,t,r,n){return{v:r.v,ax:r.ax,ay:r.ay,ds:t.ds,axDrag:ms(e.ggv.rows,r.v),...r.axScrub?{axScrub:r.axScrub}:{},axGrade:n,...t.bank?{bank:t.bank}:{}}}var bA=new WeakMap;function vA(e){let t=e.vehicle.params;if(!t.brakeFade)return null;let r=bA.get(t);if(r===void 0){let n=Ag(t),o=n?Et(t):null;if(!n||!o||o.mode!=="hydraulic")r=null;else{let a=Mg(t,e.vehicle),s=e.ggv.rows,i=pA(a.inp,a.ev,e.vehicle.vMax,{front:Fg(o.hydraulic.front.heat),rear:Fg(o.hydraulic.rear.heat)},c=>ms(s,[c])[0]);r={discs:n,table:i}}bA.set(t,r)}return r}function fN(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=Tg(e),u=(g,y)=>e.yaw?XS(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}:{}}):Kt(dc(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=ns(t.gradient,t.npts),d=g=>n.motorThermal?dS(e.vehicle,t.ds,e.energyOpts??sn,y=>u(y,g),o,a,m,t.bank).lap:u(void 0,g),p=vA(e);if(!p)return d();let h=cc(n),f=r.discC??{front:h,rear:h};return dA(d,g=>{let y=wg(p.discs,Sg(n,RA(e,t,g,m),e.vehicle),g.v,t.ds,f,h);return{...y?.front?{front:y.front.padFactor}:{},...y?.rear?{rear:y.rear.padFactor}:{}}},p.table).lap}function hN(e,t){let r=pN(e,t.vehicle.params),n=dN(e,t.vehicle.params);return n>0?yN(e,t,n,r):fc(e,t,r)}function zm(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 gA=5,bN=.1,gN=.005,yA=12;function yN(e,t,r,n){let o=fc(e,t,n),a=1,s=(h,f,b)=>({...h,energyTarget:{reserve:r,capKmh:f===void 0?null:f*3.6,met:b,solves:a}}),i=zm(o,r);if(i>=0)return s(o,n,!0);let c=Math.min(n??1/0,t.ggv.vMax),l=c/2,u=fc(e,t,l);a++;let m=zm(u,r);for(;m<0&&l>gA&&a<yA;)c=l,i=m,l=Math.max(gA,l/2),u=fc(e,t,l),a++,m=zm(u,r);if(m<0)return s(u,l,!1);let p=xN(h=>{let f=fc(e,t,h);return{run:f,margin:zm(f,r)}},{lo:l,hi:c,atLo:{run:u,margin:m},fHi:i},yA-a);return a+=p.solves,s(p.run,p.cap,!0)}function xN(e,t,r){let{lo:n,hi:o}=t,a=t.atLo,s=a.margin,i=t.fHi,c=0,l=0;for(;l<r&&o-n>bN&&a.margin>gN;){let u=o-n,m=Math.min(o-.05*u,Math.max(n+.05*u,n+s*u/(s-i))),d=e(m);l++,d.margin>=0?(n=m,a=d,s=d.margin,c===1&&(i/=2),c=1):(o=m,i=d.margin,c===-1&&(s/=2),c=-1)}return{cap:n,run:a.run,solves:l}}function kA(e,t,r){return r===0?e:e&&!t}function fc(e,t,r){let n=t.track;if(!n)throw new Ym(`Event "${e.id}" needs a track.`);let o=Wm(e,n),a=e.standingStart??t.standingStart??!1,s=D=>kA(a,n.closed,D),i=t.vehicle.params,c=jr(as(i)),l=c.capacityAh,u=pt(i.motorModel)?1:i.soc.value,m=cc(i),d=Cm(c,m),p=0,h=0,f=0,b=0,g=[],y=!1,x=-1/0,k=0,v=0,R=!1,M=-1/0,A=0,F=0,T=-1/0,P=(D,N,Y=1)=>{D.tempMaxC>T&&(T=D.tempMaxC),D.motorTempMaxC!==void 0&&(y=!0,R=!0,D.motorTempMaxC>x&&(x=D.motorTempMaxC),D.motorTempMaxC>M&&(M=D.motorTempMaxC),k+=(D.motorDerateTimeFrac??0)*N,A+=(D.motorDerateTimeFrac??0)*N,v+=(D.motorLossKwh??0)/Y,F+=(D.motorLossKwh??0)/Y)},S=null,w,C=Ag(i),L={front:m,rear:m},E=null,_=vA(t)!==null,O=(D,N)=>_&&(Math.abs(D.front-N.front)>hA||Math.abs(D.rear-N.rear)>hA),I=(D,N,Y)=>{let H=ig(i,D,N);if(E&&E.launch===Y&&!kN(H,E.pw)&&!O(L,E.discC))return E.lap;let W=fN(t,n,{soc:D,packTempC:N,launched:Y,...r?{vCeiling:r}:{},..._?{discC:L}:{}});return E={pw:H,launch:Y,discC:L,lap:W},W},z=ns(n.gradient,n.npts),B=(D,N,Y)=>ss(t.vehicle,n.ds,D.v,D.ax,t.energyOpts,N,Y,void 0,z,void 0,{ay:D.ay,bank:n.bank,...D.axScrub?{scrub:D.axScrub}:{}}),V=new WeakMap,j=(D,N)=>{let Y=V.get(D);return Y||(Y=Sg(i,RA(t,n,D,z),t.vehicle),V.set(D,Y)),wg(C,Y,D.v,n.ds,N,m)},q=(D,N,Y)=>{let H=`${(100*Y/n.npts).toFixed(0)} % of the way through lap ${D+1}`,W=N.cutoffAt>=0&&N.cutoffAt<=N.emptyAt;return{lapsCompleted:D,lapsAsked:o,why:W?`the pack reached its ${c.voltageFloor.toFixed(0)} V cut-off ${H}`:`the pack ran out ${H}`}};for(let D=0;D<o;D++){if(u<=0){w={lapsCompleted:D,lapsAsked:o,why:"the pack was empty"};break}let N=s(D),Y=u,H=d;R=!1,M=-1/0,A=0,F=0,T=-1/0;let W=I(u,d,N),X=B(W,u,d);if(X.emptyAt>=0){w=q(D,X,X.emptyAt);break}let Z=I(X.socEnd,X.tempEndC,N).laptime-W.laptime,xe,de,be,U,ee=d,se=-1,ie=null,Re=1;if(Z<=Cg)xe=W.laptime,de=X.net,be=X.loss,U=X.chargeAh,ee=X.tempEndC,P(X,xe),Re=1;else{let ce=Math.min(RN,Math.max(2,Math.ceil(Z/(2*Cg))));Re=ce;let Pe=u,ke=d;xe=0,de=0,be=0,U=0;for(let ae=0;ae<ce;ae++){let ge=I(Pe,ke,N),fe=B(ge,Pe,ke),Ce=fe.emptyAt>=0?fe.emptyAt/n.npts:1;if(Ce*ce<1){se=Math.round(n.npts*(ae/ce+Ce)),ie=fe;break}if(xe+=ge.laptime/ce,P(fe,ge.laptime/ce,ce),de+=fe.net/ce/Ce,be+=fe.loss/ce/Ce,U+=fe.chargeAh/ce/Ce,Pe-=fe.chargeAh/ce/Ce/l,ke+=(fe.tempEndC-ke)/ce,Pe<=0){se=Math.round(n.npts*(ae+1)/ce),ie=fe;break}}if(ee=ke,se>=0&&ie){w=q(D,ie,se);break}u=Pe}p+=xe,h+=de,f+=be,b+=U,Z<=Cg&&(u=X.socEnd),d=ee;let pe=C?j(W,L):null;pe&&(L={front:pe.front?.endC??L.front,rear:pe.rear?.endC??L.rear}),g.push({lap:D+1,time:xe,elapsed:p,entryTime:W.laptime,socStart:Y,socEnd:u,packTempStartC:H,packTempEndC:d,packTempMaxC:Number.isFinite(T)?T:H,energyKwh:de,lossKwh:be,chargeAh:U,launched:N,substeps:Re,...r?{vCeiling:r}:{},...R?{motor:{peakWindingC:M,derateTimeFrac:xe>0?A/xe:0,lossKwh:F}}:{},...pe?{brakes:{...pe.front?{front:xA(pe.front)}:{},...pe.rear?{rear:xA(pe.rear)}:{}}}:{}}),S=W}if(!S){let D=Tg(t);S=Kt(dc(t.ggv,t.vehicle,u),n,t.numerics,{standingStart:a,...t.load?{load:t.load.atSoc(t.vehicle,u)}:{},...D?{shifts:D}:{}}),w=w??{lapsCompleted:0,lapsAsked:o,why:"the pack was empty"}}let K=g.length;return{id:e.id,label:e.label,kind:e.kind,time:p,distance:n.length*K,laps:K,lapTime:S.laptime,trace:lN(n,S),energy:{consumed:h,loss:f,...pt(i.motorModel)?{}:{native:{value:b,unit:"Ah"}},remainingFraction:pt(i.motorModel)?1:u,...y?{motor:{peakWindingC:x,derateTimeFrac:p>0?k/p:0,lossKwh:v}}:{}},lapLog:g,...w?{incomplete:w}:{}}}var Cg=.05;function xA(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 RN=4,vN=.001;function kN(e,t){return e===t?!1:!Number.isFinite(e)||!Number.isFinite(t)?!0:Math.abs(e-t)>vN*Math.max(1,Math.abs(t))}function MA(e,t,r,n,o,a){return MN(e,t,o,()=>({v:r,ax:n,...a?{lateral:a}:{}}))}function MN(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=ss(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 pt(e.vehicle.params.motorModel)?{consumed:s,loss:i,remainingFraction:1}:{consumed:s,loss:i,native:{value:c,unit:"Ah"},remainingFraction:a}}function SA(e,t){switch(e.kind){case"straightLineAccel":return uN(e,t);case"constantRadius":return mN(e,t);case"trackLap":return hN(e,t)}}function Pg(e,t){let r={};for(let n of e)r[n.id]=SA(n,t);return r}function AA(e,t){if(e.kind!=="trackLap")return e;let{distance:r,...n}=e;return{...n,laps:Math.max(1,Math.round(t))}}function Vo(e,t,r,n,o="twoTrack",a){let s=1/0,i=-1/0;for(let d of r){let p=ac(d);if(!p)continue;let h=JM(p,Kt(t,d,n).v);h&&(s=Math.min(s,h.lo),i=Math.max(i,h.hi))}if(!(i>=s))return;let c=eS({lo:s,hi:i}),l=c.join(","),u=a?.get(l);if(u)return u;let m=cA(e,c,t,o);return a?.set(l,m),m}var hc=e=>e.distance/Math.max(1,e.laps);function bc(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 SN=e=>e.v.map(t=>t*3.6),AN=e=>e.ax.map(t=>t/9.81),wN=e=>e.ay.map(t=>t/9.81),FN=e=>e.ay.map((t,r)=>e.v[r]>1e-6?t/(e.v[r]*e.v[r]):0),jm=(e,t,r)=>e?.slice()??new Array(t.s.length).fill(r),CN=e=>jm(e.z,e,0),TN=e=>e.gradient?e.gradient.map(t=>100*Math.tan(t*Math.PI/180)):jm(void 0,e,0),PN=e=>jm(e.bank,e,0),LN=e=>jm(e.mu,e,1);function DN(e){let t=e.s.length,r=bc(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 wA(e){let t=bc(e);return{ds:t,vars:{s:e.s,ds:t,t:DN(e),v:e.v,speed:SN(e),ax:e.ax,ay:e.ay,axg:AN(e),ayg:wN(e),curv:FN(e),z:CN(e),grade:TN(e),bank:PN(e),grip:LN(e)}}}function Um(e){let t=e.rows?oA(e.rows,e.v):void 0;return{v:e.v,ax:e.ax,ay:e.ay,ds:e.ds,...e.rows?{axDrag:ms(e.rows,e.v)}:{},...e.axScrub?{axScrub:e.axScrub}:{},axGrade:ns(e.gradient,e.v.length),...e.bank?{bank:e.bank}:{},...e.loadFactor?{loadFactor:e.loadFactor}:{},...e.mu?.some(r=>r!==1)?{mu:e.mu}:{},...t?{wheelMotor:t}:{}}}function FA(e,t){return Um({v:e.v,ax:e.ax,ay:e.ay,ds:bc({s:e.s,length:t}),gradient:e.gradient,bank:e.bank,loadFactor:e.loadFactor})}function CA(e,t){let r=It(e);return{pastTurnover:KS(r,Nr(e),t),...e.aeroModel?{aeroOutside:GS(r,t)}:{}}}var Xm="Flying lap";function Dg(e,t){return e.kind!=="trackLap"||e.label!==Xm?e.label:e.standingStart??t?"Run":e.label}function EN(e){let t=It(e);return{yawInertia:t.yawInertia??0,massTotal:t.massTotal,wheelbase:t.wheelbase/1e3}}function IN(e,t,r){let n=e.params,o=n.ggvMode??"twoTrack",a=n.quasiTransient?iA(e,!1,o):null,s=a?a.steady:Vr(e,!1,o),i=t?Vo(e,s,[t],r,o):void 0;return{ggv:s,...a?{yaw:{family:a,car:EN(n)}}:{},...i?{load:i}:{}}}function _N(e,t){let r=t.lapCounts,n=t.standingStart??!1,o=!1,a=e.events.map(s=>{let i=r?.[s.id]!=null?AA(s,r[s.id]):s,c=Dg(i,n),l=c===i.label?i:{...i,label:c};return l!==s&&(o=!0),l});return o?a:e.events}function NN(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=Wm(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 ON(e,t){for(let[r,n]of Object.entries(e))n.trace&&(e[r]={...n,...CA(t,FA(n.trace,hc(n)))})}function gc(e,t,r={}){let n=Xt(e),o=IN(n,r.track,r.numerics),{ggv:a}=o,s=Pg(_N(t,r),{vehicle:n,...o,track:r.track,energyOpts:cn(e,r.energyOpts),numerics:r.numerics,standingStart:r.standingStart});return NN(s,t,r),ON(s,n.params),{name:e.name,rulesetId:t.id,events:s,ggv:a}}function Eg(e){return{...e,ggv:{rows:e.ggv.rows,vMax:e.ggv.vMax,surf:e.ggv.surf}}}var Ig=["<","<=",">",">=","==","!="],Je=class extends Error{at;constructor(t,r){super(t),this.name="ExprError",this.at=r}},yc=e=>e>="0"&&e<="9",TA=e=>/[A-Za-z_]/.test(e),VN=e=>/[A-Za-z0-9_]/.test(e);function BN(e){let t=[],r=0;for(;r<e.length;){let n=e[r];if(n===" "||n===" "||n===`
|
|
224
|
-
`||n==="\r"){r++;continue}if(yc(n)||n==="."&&yc(e[r+1]??"")){let o=r;for(;r<e.length&&(yc(e[r])||e[r]===".");)r++;if(e[r]==="e"||e[r]==="E"){let i=r;if(r++,(e[r]==="+"||e[r]==="-")&&r++,yc(e[r]??""))for(;r<e.length&&yc(e[r]);)r++;else r=i}let a=e.slice(o,r),s=Number(a);if(!Number.isFinite(s))throw new Je(`"${a}" is not a number`,o);t.push({t:"num",value:s,at:o});continue}if(TA(n)){let o=r;for(;;){for(;r<e.length&&VN(e[r]);)r++;if(e[r]==="."&&TA(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(Ig.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 Je(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 Je(`"${n}" is not something this expression can contain`,r)}return t.push({t:"end",at:e.length}),t}function _g(e){let t=BN(e),r=0,n=()=>t[r],o=f=>{let b=n();return b.t==="op"&&b.value===f},a=f=>o(f)?(r++,!0):!1,s=(f,b)=>{if(!a(f))throw new Je(`Expected ${b} here`,n().at)};function i(){let f=c(),b=n();if(b.t!=="op"||!Ig.includes(b.value))return f;r++;let g={kind:"binary",op:b.value,left:f,right:c(),at:b.at},y=n();if(y.t==="op"&&Ig.includes(y.value))throw new Je("Comparisons do not chain \u2014 write and(a < b, b < c)",y.at);return g}function c(){let f=l();for(;;){let b=n().at;if(a("+"))f={kind:"binary",op:"+",left:f,right:l(),at:b};else if(a("-"))f={kind:"binary",op:"-",left:f,right:l(),at:b};else return f}}function l(){let f=u();for(;;){let b=n().at;if(a("*"))f={kind:"binary",op:"*",left:f,right:u(),at:b};else if(a("/"))f={kind:"binary",op:"/",left:f,right:u(),at:b};else return f}}function u(){return a("-")?{kind:"unary",op:"-",arg:u()}:a("+")?u():m()}function m(){let f=d(),b=n().at;return a("^")?{kind:"binary",op:"^",left:f,right:u(),at:b}:f}function d(){let f=n();if(f.t==="num")return r++,{kind:"num",value:f.value};if(f.t==="name"){if(r++,a("(")){let b=[];if(!o(")"))do b.push(i());while(a(","));return s(")","a closing bracket"),{kind:"call",name:f.value,args:b,at:f.at}}return{kind:"var",name:f.value,at:f.at}}if(a("(")){let b=i();return s(")","a closing bracket"),b}throw f.t==="end"?new Je("The expression ends before it is finished",f.at):new Je(`"${f.value}" cannot start a value`,f.at)}let p=i(),h=n();if(h.t!=="end")throw new Je(`"${h.value}" is left over \u2014 check for a missing operator`,h.at);return p}function Ng(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 xc=(e,t)=>typeof e=="number"?new Array(t).fill(e):e;function $N(e){let t=1;for(let r of e)Array.isArray(r)&&(t=Math.max(t,r.length));return t}function er(e,t){if(e.every(a=>typeof a=="number"))return t(...e);let r=$N(e),n=e.map(a=>xc(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 et=(e,t)=>({arity:e,call:r=>er(r,t)}),Bo=e=>e!==0&&!Number.isNaN(e),Br=e=>e?1:0;function PA(e,t,r){let n=LA(t,r,"integrate"),o=n.length,a=xc(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 LA(e,t,r){if(!e.ds||e.ds.length===0)throw new Je(`${r}() needs to know the sample spacing, and this context has none`,t);return e.ds}var qm={abs:et(1,Math.abs),sqrt:et(1,Math.sqrt),sign:et(1,Math.sign),floor:et(1,Math.floor),ceil:et(1,Math.ceil),round:et(1,Math.round),exp:et(1,Math.exp),log:et(1,Math.log),sin:et(1,Math.sin),cos:et(1,Math.cos),tan:et(1,Math.tan),atan:et(1,Math.atan),atan2:et(2,Math.atan2),hypot:et(2,Math.hypot),min:et(2,Math.min),max:et(2,Math.max),clamp:et(3,(e,t,r)=>Math.min(r,Math.max(t,e))),if:et(3,(e,t,r)=>Bo(e)?t:r),and:et(2,(e,t)=>Br(Bo(e)&&Bo(t))),or:et(2,(e,t)=>Br(Bo(e)||Bo(t))),not:et(1,e=>Br(!Bo(e))),finite:et(1,e=>Br(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=PA(e,t,0),n=t.ds,o=xc(e,n.length),a=n.length-1;return r[a]+(o[a]+o[0])/2*n[a]}},integrate:{arity:1,call:([e],t)=>PA(e,t,0)},cum:{arity:1,call:([e],t)=>{let r=t.ds?.length??(Array.isArray(e)?e.length:1),n=xc(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=LA(t,0,"deriv"),n=r.length,o=xc(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}}},ps={g:9.81,pi:Math.PI,e:Math.E,nan:NaN,inf:1/0},Rc={fleetmin:"min",fleetmax:"max"};function $o(e){switch(e.kind){case"call":return Object.hasOwn(Rc,e.name)||e.args.some($o);case"unary":return $o(e.arg);case"binary":return $o(e.left)||$o(e.right);default:return!1}}var GN=e=>typeof e=="number"?`${e}`:`between ${e[0]} and ${e[1]}`;function KN(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 HN(e,t){let r=t.map(c=>({k:c,d:KN(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 $r(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(ps,e.name))return ps[e.name];let r=[...Object.keys(t.vars),...Object.keys(ps)].sort();throw new Je(HN(e.name,r),e.at)}case"unary":return er([$r(e.arg,t)],r=>-r);case"binary":{let r=$r(e.left,t),n=$r(e.right,t);switch(e.op){case"+":return er([r,n],(o,a)=>o+a);case"-":return er([r,n],(o,a)=>o-a);case"*":return er([r,n],(o,a)=>o*a);case"/":return er([r,n],(o,a)=>a===0?0:o/a);case"^":return er([r,n],(o,a)=>o**a);case"<":return er([r,n],(o,a)=>Br(o<a));case"<=":return er([r,n],(o,a)=>Br(o<=a));case">":return er([r,n],(o,a)=>Br(o>a));case">=":return er([r,n],(o,a)=>Br(o>=a));case"==":return er([r,n],(o,a)=>Br(o===a));case"!=":return er([r,n],(o,a)=>Br(o!==a))}break}case"call":{let r=Object.hasOwn(Rc,e.name)?Rc[e.name]:void 0;if(r){if(!t.fleet)throw new Je(`${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 Je(`${e.name}() takes 1 argument, not ${e.args.length}`,e.at);return t.fleet(e.args[0],r,e.at)}let n=Object.hasOwn(qm,e.name)?qm[e.name]:void 0;if(!n){let s=[...Object.keys(qm),...t.fleet?Object.keys(Rc):[]];throw new Je(`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 Je(`${e.name}() takes ${GN(n.arity)} argument${o===1&&a===1?"":"s"}, not ${e.args.length}`,e.at);return n.call(e.args.map(s=>$r(s,t)),t)}}throw new Je("Unreachable node",0)}var ds=e=>Number.isFinite(e)?e:NaN,Og=[{name:"time",unit:"s",what:"the whole event, every lap",read:e=>ds(e?.time)},{name:"lapTime",unit:"s",what:"one lap \u2014 the last one completed",read:e=>ds(e?.lapTime)},{name:"distance",unit:"m",what:"distance covered",read:e=>ds(e?.distance)},{name:"laps",unit:"-",what:"laps completed",read:e=>ds(e?.laps)},{name:"energy",unit:"kWh",what:"energy drawn over the event",read:e=>ds(e?.energy?.consumed)},{name:"remaining",unit:"-",what:"share of the pack or tank left afterwards",read:e=>ds(e?.energy?.remainingFraction)},{name:"finished",unit:"-",what:"1 when the car ran the whole event, else 0",read:e=>e&&!e.incomplete?1:0}],DA=/^[A-Za-z_][A-Za-z0-9_]*$/,zN=new Set([...Object.keys(ps),...Lg.map(e=>e.name)]);function Qm(e,t,r=[]){let n=[],o=new Set(r),a=t.map(b=>b.id),s=new Set;for(let b of a)DA.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(!DA.test(b.key)){n.push({key:b.key,message:`"${b.key}" must be one word \u2014 letters, digits and _`});continue}if(zN.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,_g(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,[...Ng(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=YN(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 d=(b,g,y)=>{throw new Je("fleetmin() and fleetmax() cannot sit inside one another",y)},p=new Set,h={};for(let b of a)for(let g of Og)h[`${b}.${g.name}`]=1;for(let b of o)h[b]=1;for(let b of i.keys())h[b]=1;let f={};for(let b of Lg)f[b.name]=[1,1];for(let b of m){let g=i.get(b),y=c.get(b);($o(y)||l.get(b).some(R=>p.has(R)))&&p.add(b);let x=g.over!=null?{...h,...f}:h,k=g.over!=null?[1,1]:void 0,v=(R,M,A)=>{let F=$r(R,{vars:x,ds:k,fleet:d});if(Array.isArray(F))throw new Je("fleetmin() and fleetmax() compare one number per car \u2014 reduce the channel first, e.g. peak(v)",A);return F};try{let R=$r(y,{vars:x,ds:k,fleet:v});Array.isArray(R)&&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(R){let M=R;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 YN(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 WN(e,t,r={}){let n={...r};for(let o of e.eventIds){let a=t.events[o];for(let s of Og)n[`${o}.${s.name}`]=s.read(a)}return{vars:n,laps:new Map,events:t.events}}function EA(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?wA({...n.trace,length:hc(n)}):null,e.laps.set(t.over,r)}return r?{vars:{...e.vars,...r.vars},ds:r.ds}:null}var IA=e=>Array.isArray(e)?NaN:e;function _A(e,t,r,n={}){let o=Object.keys(t),a=o.map(i=>WN(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 d of a)d.vars[i.key]=NaN;continue}let u=new Map,m=(d,p)=>{let h=u.get(d);if(h!==void 0)return h;let f=NaN;for(let b of a){let g=EA(b,i);if(!g)continue;let y=IA($r(d,g));Number.isFinite(y)&&(Number.isNaN(f)||(p==="min"?y<f:y>f))&&(f=y)}return u.set(d,f),f};for(let d of a){let p=EA(d,i);d.vars[i.key]=p?IA($r(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 vc(e,t,r){return _A(e,t,!0,r)}function Vg(e,t,r){return _A(e,{car:t},!1,r?{car:r}:void 0).car}var Zm=class extends Error{problems;constructor(t,r){super(`Ruleset "${t}" does not compile:
|
|
223
|
+
`}function en(e){let t=yi(x1(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 R1={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},v1={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},k1={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},M1={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},S1={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},A1={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},w1={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},F1={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},gh=()=>en(R1),yh=()=>en(v1),xh=()=>en(k1),Rh=()=>en(M1),vh=()=>en(S1),kh=()=>en(A1),Mh=()=>en(w1),Sh=()=>en(F1);var C1=e=>Number.isFinite(e)&&e>0;function Ru(e,t){let r=C1(t.grip)?t.grip:1,n=C1(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 Ri={ok:!0,violation:0},go=1e7;function tn(e,t){let r;try{r=e.build(t)}catch(s){return{total:go*2,feasible:!1,terms:[],reason:`build failed: ${String(s)}`}}let n=e.feasible(r);if(!n.ok)return{total:go+Math.max(0,n.violation),feasible:!1,terms:[],reason:n.reason};let o;try{o=e.terms(r)}catch(s){return{total:go*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:go*2,feasible:!1,terms:o,reason:"objective was not finite"}}var vi=(e,t)=>!t||(e.feasible!==t.feasible?e.feasible:e.total<t.total);function Ah(e,t){return t.map((r,n)=>Math.min(e[n].hi,Math.max(e[n].lo,r)))}var rn=e=>e.map(t=>t.start);function vu(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 HD(e){let t=0;for(;t===0;)t=e();return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e())}function wh(e,t){let{budget:r}=t,n=Math.max(1,Math.floor(t.progressEvery??1)),o=e.variables,a=p=>Ah(o,p.map((h,f)=>o[f].lo+h*(o[f].hi-o[f].lo))),s=p=>p.map((h,f)=>(h-o[f].lo)/(o[f].hi-o[f].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 h=p.map(g=>Math.min(1,Math.max(0,g))),f=tn(e,a(h));f.feasible||c++;let b=vi(f,l)?f:l;return b===f&&(l=f,u=h),m.push(b.total),t.onProgress&&(i%n===0||i===r)&&t.onProgress({evaluations:i,budget:r,x:a(u),score:b,infeasible:c}),f.total},left:()=>r-i,result:p=>({method:p,x:u?a(u):rn(o),score:l??tn(e,rn(o)),evaluations:i,history:m,infeasible:c})}}var Fh=(e,t,r,n=0,o)=>{let a=t?r.norm(rn(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 T1(e,t){let r=wh(e,t),n=vu(t.seed??1),o=e.variables.length;for(r.evaluate(Fh(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 $a(e,t){let r=wh(e,t),n=e.variables.length,o=vu(t.seed??1),a=1,s=2,i=.5,c=.5,l=Fh(e,t.warmStart!==!1,r,t.startJitter,o),u=.25;for(;r.left()>0;){let m=[{u:l,f:r.evaluate(l)}];for(let d=0;d<n&&r.left()>0;d++){let p=l.slice();p[d]+=p[d]+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 d=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 h=g=>p.map((y,x)=>y+g*(y-d.u[x])),f=h(a),b=r.evaluate(f);if(b<m[0].f){let g=h(s),y=r.evaluate(g);m[n]=y<b?{u:g,f:y}:{u:f,f:b}}else if(b<m[n-1].f)m[n]={u:f,f:b};else{let g=h(-i),y=r.evaluate(g);if(y<d.f)m[n]={u:g,f:y};else{let x=m[0],k=0;for(let v=1;v<=n;v++)for(let R=0;R<n;R++)k=Math.max(k,Math.abs(m[v].u[R]-x.u[R]));if(k<1e-4)break;for(let v=1;v<=n&&r.left()>0;v++){let R=m[v].u.map((M,A)=>x.u[A]+c*(M-x.u[A]));m[v]={u:R,f:r.evaluate(R)}}}}}m.sort((d,p)=>d.f-p.f),l=m[0].u.map(d=>Math.min(1,Math.max(0,d+.05*(o()-.5)))),u=Math.max(.02,u*.5)}return r.result("nelder-mead")}function P1(e,t){let r=wh(e,t),n=e.variables.length,o=vu(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,d=(4+l/n)/(n+4+2*l/n),p=(n+2)/3,h=Math.min(1,p*2/((n+1.3)**2+l)),f=Math.min(1-h,p*2*(l-2+1/l)/((n+2)**2+l)),b=Math.sqrt(n)*(1-1/(4*n)+1/(21*n*n)),g=Fh(e,t.warmStart!==!1,r,t.startJitter,o),y=.25,x=new Array(n).fill(1),k=new Array(n).fill(0),v=new Array(n).fill(0),R=0;for(;r.left()>0;){R++;let M=[];for(let S=0;S<a&&r.left()>0;S++){let w=[];for(let L=0;L<n;L++)w.push(HD(o));let C=g.map((L,E)=>L+y*x[E]*w[E]);M.push({z:w,u:C,f:r.evaluate(C)})}if(M.length<s)break;M.sort((S,w)=>S.f-w.f);let A=g.slice(),F=new Array(n).fill(0);g=new Array(n).fill(0);for(let S=0;S<s;S++)for(let w=0;w<n;w++)g[w]+=i[S]*M[S].u[w],F[w]+=i[S]*M[S].z[w];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)*F[S];let T=Math.sqrt(k.reduce((S,w)=>S+w*w,0)),P=T/Math.sqrt(1-(1-u)**(2*R))/b<1.4+2/(n+1)?1:0;for(let S=0;S<n;S++){let w=(g[S]-A[S])/(y*x[S]);v[S]=(1-d)*v[S]+P*Math.sqrt(d*(2-d)*l)*w}for(let S=0;S<n;S++){let w=0;for(let E=0;E<s;E++)w+=i[E]*M[E].z[S]*M[E].z[S];let C=x[S]*x[S],L=(1-h-f)*C+h*(v[S]*v[S]+(1-P)*d*(2-d)*C)+f*w*C;x[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 Ga=[{name:"random",run:T1},{name:"nelder-mead",run:$a},{name:"sep-cma-es",run:P1}];var W6=Math.PI/180;var ku=Math.PI/180;var q6={Fz:100,alpha:.25*ku,kappa:.005,gamma:.5*ku,p:6900},L1={Fz:100,alpha:1*ku,kappa:.02,gamma:.5*ku,p:6900};var D1=Math.PI/180,rY={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:D1},gamma:{rad:1,deg:D1},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 iY=Math.PI/180;var tE=Math.PI/180;var fY=3*tE;var xY=Math.PI/180;var LY=Math.PI/180;var lE={RCX1:1,RCY1:1,REX1:0,REY1:0,RBY3:0,RHX1:0,RHY1:0},_1={RBX1:15,RBX2:15,RBY1:18,RBY2:19,...lE};var KY=Math.PI/180;var fE=Math.PI/180,Mu=[{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"}],n8=new Map(Mu.map(e=>[e.id,e]));var o8=.01*fE;var st=Math.PI/180;var V1=new Set(Mu.filter(e=>e.group!=="inputs"&&(e.unit==="N"||e.unit==="N\xB7m"||e.unit==="N/rad")).map(e=>e.id)),B1={alpha:{from:-15*st,to:15*st,n:61},kappa:{from:-.25,to:.25,n:61},gamma:{from:-6*st,to:6*st,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*st,n:7},kappa:{from:-.2,to:.2,n:9},gamma:{from:-4*st,to:4*st,n:5},Fz:{from:400,to:1600,n:5},p:{from:6e4,to:12e4,n:4},V:{from:5,to:35,n:4}};var Eh={alpha:{from:0,to:12*st,n:25},kappa:{from:-.2,to:.2,n:25},gamma:{from:-4*st,to:4*st,n:17},Fz:{from:300,to:1800,n:16},p:{from:6e4,to:12e4,n:13},V:{from:5,to:35,n:13}};var Ie=(e,t,r,n={},o={})=>({id:e,form:"curves",sweep:[{input:t,...B1[t],...o}],x:t,y:r,...n}),Su=(e,[t,r],n,o,a={})=>({id:e,form:"carpet",sweep:[{input:t,...Dh[t]},{input:r,...Dh[r]}],x:n,y:[o],...a}),nn=(e,t)=>({id:e,fixed:t}),ir={input:"Fz",values:"car"},Lh={alpha:0,kappa:0},$t={kappa:0},N1={alpha:0},bE={input:"Fz",values:[500,1e3,1500]},gE=[{id:"overview",name:"Overview",cards:[nn("tyre","tyre"),Ie("fy","alpha",["Fy"],{title:"Lateral force",hold:$t}),Ie("mz","alpha",["Mz"],{title:"Aligning moment",hold:$t}),Ie("fx","kappa",["Fx"],{title:"Longitudinal force",hold:N1}),Su("combined-carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),nn("ellipse","ellipse")]},{id:"lateral",name:"Lateral",cards:[Ie("fy-load","alpha",["Fy"],{title:"Lateral force per wheel load",series:ir,hold:$t}),Ie("muy-load","alpha",["muY"],{title:"Lateral force per unit load",series:ir,hold:$t}),Ie("fy-peak","alpha",["Fy"],{title:"Lateral force over its peak",series:ir,hold:$t,scale:{per:"peak"}},{from:0,to:15*st,n:61}),Ie("muy-peak","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load"}),Ie("calpha","Fz",["Calpha"],{title:"Cornering stiffness over load"}),Ie("alpha-peak","Fz",["alphaPeak"],{title:"Slip angle at the peak over load"})]},{id:"aligning",name:"Aligning",cards:[Ie("mz-load","alpha",["Mz"],{title:"Aligning moment per wheel load",series:ir,hold:$t}),Ie("trail","alpha",["t"],{title:"Pneumatic trail",series:ir,hold:$t},{from:0,to:12*st,n:49}),Ie("mzr","alpha",["Mzr"],{title:"Residual aligning moment",series:ir,hold:$t},{from:0,to:12*st,n:49}),Su("gough",["alpha","Fz"],"Fy","Mz",{title:"Gough plot",hold:$t}),Ie("steering-feel","alpha",["t"],{title:"Steering feel",x:"FyRel",series:ir,hold:$t},{from:0,to:12*st,n:49})]},{id:"longitudinal",name:"Longitudinal",cards:[Ie("fx-load","kappa",["Fx"],{title:"Longitudinal force per wheel load",series:ir,hold:N1}),Ie("mux-peak","Fz",["muXPeak"],{title:"Peak longitudinal \u03BC over load"}),Ie("kx","Fz",["dFxdk"],{title:"Slip stiffness at zero slip over load",hold:Lh}),Ie("kappa-peak","Fz",["kappaPeak"],{title:"Slip ratio at the peak over load"})]},{id:"combined",name:"Combined",cards:[Su("carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),Su("envelope-load",["kappa","alpha"],"Fy","Fx",{title:"Friction envelope per load",scale:{per:"Fz"},facet:bE}),Ie("fy-kappa","kappa",["Fy"],{title:"Side force while driving or braking",series:{input:"alpha",values:[2*st,4*st,8*st]}}),Ie("fx-kappa","kappa",["Fx"],{title:"Driving force while cornering",series:{input:"alpha",values:[0,4*st,8*st]}}),nn("ellipse","ellipse")]},{id:"camber",name:"Camber",cards:[Ie("fy-gamma","alpha",["Fy"],{title:"Lateral force per inclination",series:{input:"gamma",values:[-4,-2,0,2,4].map(e=>e*st)},hold:$t}),Ie("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",...Eh.gamma},{input:"Fz",...Eh.Fz,follow:!0}],x:"gamma",y:["Fz"],z:"muYPeak"},Ie("camber-stiffness","alpha",["dFydg"],{title:"Camber stiffness at the point",series:ir,hold:$t}),Ie("mx","alpha",["Mx"],{title:"Overturning moment",series:ir,hold:$t})]},{id:"rolling",name:"Rolling and radius",cards:[Ie("my","V",["My"],{title:"Rolling-resistance moment",series:ir,hold:Lh}),Ie("radius","Fz",["R0","Rl","Re"],{title:"Radius over load"},{from:0}),Ie("p-roll","V",["Proll"],{title:"Rolling power",series:ir,hold:Lh})]},{id:"transient",name:"Transient",cards:[Ie("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},Ie("delta-fy","alpha",["Fy"],{title:"Lateral force, minus the reference",hold:$t,scale:{delta:!0}}),Ie("delta-mu","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load, minus the reference",scale:{delta:!0}}),Ie("delta-calpha","Fz",["Calpha"],{title:"Cornering stiffness over load, minus the reference",scale:{delta:!0}})]},{id:"car",name:"Car",cards:[nn("operating","operating"),nn("wheels","wheels")]},{id:"fit",name:"Fit check",cards:[nn("fitLateral","fitLateral"),nn("fitLongitudinal","fitLongitudinal"),nn("fitCoupling","fitCoupling"),nn("fitEnvelope","fitEnvelope")]}];var SE=5670374e-14,Ih=273.15,K1=.95,H1=60,Au=10,AE=.55,Ut=25,_h=-20,Nh=50,Mi={tempC:[20,100,200,550,650,750],factor:[.8,.92,1,1,.85,.65]},Si={discMassKg:.5,discOuterMm:220,specificHeatJPerKgK:460,emissivity:.6,coolingWPerM2K:200,padCurve:{tempC:[...Mi.tempC],factor:[...Mi.factor]}},wu={...Si,discMassKg:.4,discOuterMm:200,padCurve:{tempC:[...Mi.tempC],factor:[...Mi.factor]}};function Oh(e,t){let r=t==="front"?Si:wu,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 wE=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},ki=(e,t,r,n)=>Math.min(r,Math.max(t,wE(e,n)));function FE(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 Vh(e,t){return{discMassKg:ki(e?.discMassKg,.05,20,t.discMassKg),discOuterMm:ki(e?.discOuterMm,50,600,t.discOuterMm),specificHeatJPerKgK:ki(e?.specificHeatJPerKgK,100,3e3,t.specificHeatJPerKgK),emissivity:ki(e?.emissivity,.02,1,t.emissivity),coolingWPerM2K:ki(e?.coolingWPerM2K,Au,5e3,t.coolingWPerM2K),padCurve:FE(e?.padCurve,t.padCurve)}}function Fu(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 Bh(e,t=1){let r=e.discMassKg*e.specificHeatJPerKgK,n=e.discOuterMm*.001/2,o=2*Math.PI*n*n,a=H1/3.6,s=e.emissivity*SE*o,i=m=>Au+(e.coolingWPerM2K-Au)*Math.pow(Math.max(0,m)*t/a,AE),c=(m,d,p)=>{let h=m+Ih,f=p+Ih;return i(d)*o*(m-p)+s*(h**4-f**4)},l=(m,d)=>i(d)*o+4*s*Math.max(0,m+Ih)**3,u=(m,d)=>r/l(d,m);return{heatCapacityJPerK:r,areaM2:o,convectionAt:i,coolingW:c,timeConstantS:u,step(m,d,p,h,f){if(!(h>0))return m+d/r;let b=u(p,m+Math.max(0,d)/r),g=Math.max(1,Math.ceil(h/(.25*b))),y=h/g,x=d/g;for(let k=0;k<g;k++)m+=(x-c(m,p,f)*y)/r;return m},padFactor:m=>Fu(e.padCurve,m),window:z1(e.padCurve)}}function Cu(e,t,r,n,o,a,s=Ut){let i=n.length,c=new Array(i),l=new Array(i),u=new Array(i),m=K1/Math.max(1,t),d=a,p=d,h=0,f=0,b=0;for(let g=0;g<i;g++){let y=Math.max(0,r[g]??0);c[g]=d,l[g]=y*n[g],u[g]=e.padFactor(d);let x=y*(o[g]??0);h+=x,d<e.window.fromC?f+=x:d>e.window.toC&&(b+=x);let k=g+1<i?n[g+1]:n[g],v=.5*(n[g]+k),R=v>0?(o[g]??0)/v:0;d=e.step(d,m*x,v,R,s),d>p&&(p=d)}return{tempC:c,heatW:l,padFactor:u,startC:a,endC:d,maxC:p,workJ:h,coldWorkJ:f,hotWorkJ:b}}function z1(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])&&Fu(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 $h=1e5,U1=.001,yo={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},Kh={fullAtBar:10,maxPowerKw:0,fadeBelowKmh:0,distribution:"equal"};var Hh=q1(Pu(yo,"Formula Student brakes")),zh=40,X1={ideal:!1,barFront:yo.barFront,pedalForceMaxN:0,testSpeedKmh:zh,regen:Kh};function Y1(e){let{heat:t,...r}=e;return t?{...r,heat:{...t,padCurve:{tempC:[...t.padCurve.tempC],factor:[...t.padCurve.factor]}}}:r}function q1(e){let t=(r,n)=>r.heat?r:{...r,heat:Oh(r,n)};return{...e,front:t(e.front,"front"),rear:t(e.rear,"rear")}}function Pu(e,t){return{name:t,pedalRatio:e.pedalRatio,masterFrontMm:e.masterFrontMm,masterRearMm:e.masterRearMm,valve:e.valve,valveKneeBar:e.valveKneeBar,valveSlope:e.valveSlope,front:Y1(e.front),rear:Y1(e.rear),adjusterPitchMm:e.adjusterPitchMm,barLengthMm:e.barLengthMm}}function Yh(e,t){return Q1({...e,barFront:t.barFront,pedalForceMaxN:t.pedalForceMaxN})}function Wh(e,t){let r=an(t),n=e?Lr(e):void 0;return{mode:r.ideal?"tyre":n?"hydraulic":"balance",hydraulic:n?Yh(n,r):yo,regen:r.regen}}var CE=["none","proportioning","limiter"],Tu=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},ft=(e,t,r,n)=>Math.min(r,Math.max(t,Tu(e,n))),TE=(e,t)=>{let r=Tu(e,t);return r>0?r:t};function W1(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(Tu(e?.discs,n==="inboard"?1:t.discs)))),pistonsPerSide:Math.max(1,Math.min(6,Math.round(Tu(e?.pistonsPerSide,t.pistonsPerSide)))),pistonDiaMm:ft(e?.pistonDiaMm,5,80,t.pistonDiaMm),padMu:ft(e?.padMu,.05,1.5,t.padMu),effRadiusMm:ft(e?.effRadiusMm,20,300,t.effRadiusMm),ratio:n==="inboard"?ft(e?.ratio,1,20,t.ratio):1,...e?.heat&&typeof e.heat=="object"?{heat:Vh(e.heat,t.heat??r)}:{}}}function Q1(e){let t=yo;return{pedalRatio:ft(e?.pedalRatio,.5,15,t.pedalRatio),pedalForceMaxN:ft(e?.pedalForceMaxN,0,5e3,t.pedalForceMaxN),barFront:ft(e?.barFront,.05,.95,t.barFront),masterFrontMm:ft(e?.masterFrontMm,8,40,t.masterFrontMm),masterRearMm:ft(e?.masterRearMm,8,40,t.masterRearMm),valve:CE.includes(e?.valve)?e?.valve:t.valve,valveKneeBar:ft(e?.valveKneeBar,0,200,t.valveKneeBar),valveSlope:ft(e?.valveSlope,0,1,t.valveSlope),front:W1(e?.front,t.front,Si),rear:W1(e?.rear,t.rear,wu),adjusterPitchMm:TE(e?.adjusterPitchMm,t.adjusterPitchMm),barLengthMm:ft(e?.barLengthMm,0,500,t.barLengthMm)}}function PE(e){let t=Kh;return{fullAtBar:ft(e?.fullAtBar,0,200,t.fullAtBar),maxPowerKw:ft(e?.maxPowerKw,0,1e3,t.maxPowerKw),fadeBelowKmh:ft(e?.fadeBelowKmh,0,100,t.fadeBelowKmh),distribution:e?.distribution==="wheel"?"wheel":"equal"}}function Lr(e){let t=Q1(e??void 0),r=typeof e?.name=="string"&&e.name.trim()?e.name:LE;return Pu(t,r)}function an(e){return{ideal:e?.ideal===!0,barFront:ft(e?.barFront,.05,.95,yo.barFront),pedalForceMaxN:ft(e?.pedalForceMaxN,0,5e3,0),testSpeedKmh:ft(e?.testSpeedKmh,5,150,zh),regen:PE(e?.regen)}}var LE="Formula Student brakes";var Gh=e=>Math.PI/4*(e*U1)**2;function Bn(e,t){let r=e.pistonsPerSide*Gh(e.pistonDiaMm)*$h;return e.discs*2*e.padMu*r*e.effRadiusMm*U1*e.ratio/Math.max(.05,t)}function Z1(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/Gh(e.masterFrontMm)/$h,o=(1-e.barFront)*r/Gh(e.masterRearMm)/$h;return{front:n,rearIn:o,rear:Z1(e,o)}}function DE(e,t){let r=Ai(e,1);return{front:Bn(e.front,t)*r.front,rear:Bn(e.rear,t)*r.rearIn}}function wi(e,t){let r=DE(e,t);return r.front/Math.max(1e-12,r.front+r.rear)}function Fi(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=J1(t,l),m=t.maxPowerKw>0&&l>0?t.maxPowerKw*1e3/l:1/0,d=Math.max(0,e.fFront[c]),p=Math.max(0,e.fRear[c]),h=d+p>0?Math.min(1,m/(d+p)):1;r.push(l),n.push(d*h*u),o.push(p*h*u)}}function J1(e,t){let r=e.fadeBelowKmh/3.6;return r>0?Math.max(0,Math.min(1,t/r)):1}function on(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 j1=new WeakMap;function xo(e){let t=j1.get(e);return t||(t=e.mode==="hydraulic"&&e.hydraulic?IE(e,e.hydraulic):EE(e),j1.set(e,t)),t}function EE(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 IE(e,t){let r=Bn(t.front,e.tyreRadiusM),n=Bn(t.rear,e.tyreRadiusM),o=e.regen,a=(c,l)=>{let u=Ai(t,c),m=0,d=0;if(o&&u.front>0){let p=o.fullAtBar>0?Math.min(1,u.front/o.fullAtBar):1;m=p*on(o.v,o.front,l),d=p*on(o.v,o.rear,l)}return{front:r*u.front+m,rear:n*u.rear+d,regenFront:m,regenRear:d,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 d=0;d<60;d++){let p=.5*(m+u);i(p,l)<c?m=p:u=p}return u}}}function jh(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 Lu=oi,_E=.1,Ro=(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 d=0;d<48;d++)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 d of[t,r]){let p=e(d);p>m&&(u=d,m=p)}return u}function qh(e,t,r){let n=Math.max(0,r-Lu*t.b),o=Math.min(r,Lu*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 Qh(e,t,r,n,o=0){let a=Math.max(0,r),s=qh(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],d=u.Fz/Math.max(1e-9,u.Fz+m.Fz),p=Math.max(0,Math.min(1,1-d/_E)),h=p>0&&a<Lu*m.b?m.cap(a):0,f=h>l?l+p*(h-l):0,b=Math.max(0,Math.min(u.slide,u.a)),g={xNoLock:l,xLock:f,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:x,hi:k}=s,v=Du(P=>{let S=Ro(e,P),w=Ro(t,a-P);return Math.min(S+w,2*Math.min(S,w)+y)},x,k),R=e.cap(v),M=t.cap(a-v),A=Math.max(2*l,Math.min(R+M,2*Math.min(R,M)+y)),F=(P,S,w)=>Math.min(y,Math.max(0,P-w))+Math.min(y,Math.max(0,S-w));return{...g,regenWheel:y,mixedMax:A,regenRoom:P=>{let S=F(i,c,P);if(!(a>0))return S;let w=_=>Lu*_.b*Math.sqrt(Math.max(0,1-(P/Math.max(1e-9,_.a))**2)),C=Math.max(x,a-w(t)),L=Math.min(k,w(e));if(!(C<=L))return S;let E=Du(_=>Math.min(y,Ro(e,_)-P)+Math.min(y,Ro(t,a-_)-P),C,L);return Math.max(S,F(e.cap(E),t.cap(a-E),P))}}}var Uh=e=>Math.max(e.xNoLock,e.xLock),Xh=e=>Math.max(e.mixedMax,2*e.xLock);function Ka(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 Ha(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?NE(e,e.shares,t,r,n):OE(e,t,r,n)}function ek(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 NE(e,t,r,n,o){let a=Xh(r),s=Xh(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=Ha(r,t.front*b),y=Ha(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,d=[{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&&d.push({u:b,by:"front"})}if(n.xLock>n.xNoLock){let b=t.rear>0?n.mixedMax/t.rear:1/0;b<i&&d.push({u:b,by:"rear"})}let{cand:p,force:h}=ek(d,l),f=e.demand(p.u,o);return{force:Math.max(0,Number.isFinite(h)?h:0),control:p.u,demand:f,limitedBy:p.by,lockFront:f.front/2>r.mixedMax/2*(1+1e-9),lockRear:f.rear/2>n.mixedMax/2*(1+1e-9)}}function OE(e,t,r,n){let o=Uh(t),a=Uh(r),s=v=>(v.front-v.regenFront)/2,i=v=>(v.rear-v.regenRear)/2,c=v=>{let R=e.demand(v,n);return s(R)<=o*(1+1e-12)&&i(R)<=a*(1+1e-12)},l=(v,R)=>{if(v(e.demand(R,n)))return R;let M=0,A=R;for(let F=0;F<60;F++){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),d=Number.isFinite(e.uMax)&&m>=e.uMax,p=v=>{let R=e.demand(v,n),M=Ka(t,s(R),R.regenFront),A=Ka(r,i(R),R.regenRear);return Number.isFinite(M)&&Number.isFinite(A)?M+A:-1/0},h=e.demand(m,n),f=o>0?s(h)/o:1/0,b=a>0?i(h)/a:1/0,g=[{u:m,by:d?"pedal":f>=b?"front":"rear"}];if(t.xLock>t.xNoLock){let v=l(R=>s(R)<=t.xNoLock,m);v<m&&g.push({u:v,by:"front"})}if(r.xLock>r.xNoLock){let v=l(R=>i(R)<=r.xNoLock,m);v<m&&g.push({u:v,by:"rear"})}let{cand:y,force:x}=ek(g,p),k=e.demand(y.u,n);return{force:Math.max(0,Number.isFinite(x)?x: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 sn={regen:!0,regenEfficiency:.6};function cn(e,t){let r=e.energy??t??sn;return{regen:r.regen===!0,regenEfficiency:Math.min(1,Math.max(0,Number.isFinite(r.regenEfficiency)?r.regenEfficiency:0))}}function ln(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 tk(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 ht(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 Eu(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 h=o+a>>1;e[h]<=r?o=h:a=h}if(o===n-1)return t[n-1];let s=h=>e[h+1]-e[h],i=h=>(t[h+1]-t[h])/s(h),c=h=>{if(h===0||h===n-1){let[y,x]=h===0?[0,1]:[n-2,n-3],k=i(y)*(1+s(y)/(s(y)+s(x)))-i(x)*(s(y)/(s(y)+s(x)));return k*i(y)<=0?0:Math.abs(k)>2*Math.abs(i(y))?2*i(y):k}let f=i(h-1),b=i(h),g=(f*s(h)+b*s(h-1))/(s(h-1)+s(h));return(Math.sign(f)+Math.sign(b))*Math.min(Math.abs(f),Math.abs(b),.5*Math.abs(g))},l=s(o),u=i(o),m=c(o),d=c(o+1),p=r-e[o];return t[o]+p*(m+p*((3*u-2*m-d)/l+p*(m+d-2*u)/(l*l)))}function Ti(e,t,r){return r.map(n=>ht(e,t,n))}var Pi=e=>e.reduce((t,r)=>r>t?r:t,-1/0),za=e=>e.reduce((t,r)=>r<t?r:t,1/0);var VE=[-.906179845938664,-.538469310105683,0,.538469310105683,.906179845938664],BE=[.236926885056189,.478628670499366,.568888888888889,.478628670499366,.236926885056189];function Zh(e,t,r){let n=.5*(r-t),o=.5*(t+r),a=0;for(let s=0;s<5;s++)a+=BE[s]*e(n*VE[s]+o);return n*a}var $E=Math.PI*2,GE=.5/3.6;function Li(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 Jh(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*$E;c[g]=y*o/n,l[g]=s[g]*n/o}let u=Pi(c),m=ln(za(c),u,u/GE),d=Ti(c,l,m),{front:p,rear:h}=Li(t,r),f=d.map(g=>g*p),b=d.map(g=>g*h);return{vVehicle:m,fFront:f,fRear:b,vMax:u}}var rk=60/(2*Math.PI),nk=.1,ok=.08,ak=0;function eb(e){let t=(r,n)=>r===void 0||!Number.isFinite(r)?n:Math.max(0,r);return{up:t(e.upshiftTime,nk),down:t(e.downshiftTime,ok)}}function tb(e){let t=e.driveKept;return t===void 0||!Number.isFinite(t)?ak:Math.max(0,Math.min(1,t))}function rb(e,t,r){let{primary:n,ratios:o,efficiency:a}=e.gearbox,s=t>0&&r>0&&n>0,i=(b,g)=>b/rk*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,Ue(e.rpm,e.torque,b)),d=(b,g)=>{let y=c[g];return y?b*y.ratio/r*rk:0},p=(b,g)=>g===0&&c.length>0&&b<c[0].vIdle,h=(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(d(b,g))*y.ratio*l/r:0},f=(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:d,torque:m,force:h,inertiaMass:f,slipping:p}}function Ya(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 nb(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 sk=9.81,ik=Math.PI*2;function Xt(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]*(ik/60),a[v]=t[v]/60*ik,s[v]=a[v]*u/l,i[v]=r[v]*l,c[v]=i[v]/u;let m=Pi(s),d=m,p=.5/3.6,h=ln(za(s),m,m/p),f=Ti(s,c,h),b=ln(za(t),Pi(t),250),g=Ti(t,o,b).map(v=>v*e.power_scale.value),y,x=d,k;if(e.motorModel?.kind==="ice"){k=rb(e.motorModel,l,u);let v=ln(0,k.vMax,Math.max(2,Math.ceil(k.vMax/p)+1)),R=v.map(F=>nb(k,F)),M=v.map(()=>0),A=e.motorPlacement==="front";y={vVehicle:v,fFront:A?R:M,fRear:A?M:R,vMax:k.vMax},x=k.vMax}else e.motorModel&&(y=Jh(e.motorModel,Math.max(1,Math.round(e.motorCount??e.driven_wheels.value)),e.motorPlacement??"rear",l,u),x=y.vMax);return{params:e,g:sk,FG:e.m.value*sk,vMax:x,vVehicle:h,fRad:f,uMotor:b,pMotor:g,vRad:s,fAxle:y,...k?{engine:k}:{}}}var hr=e=>e.motorModel?.kind==="ice"?Li(1,e.motorPlacement==="front"?"front":"rear"):Li(Math.max(1,Math.round(e.motorCount??e.driven_wheels?.value??2)),e.motorPlacement??"rear");function ck(e){let t=hr(e);return t.front>=2||t.rear>=2}function lk(e){return ck(e)?e.motorMount??"hub":"chassis"}function ob(e){if(!e.motorModel)return{front:!1,rear:!0};let t=hr(e);return{front:t.front>0,rear:t.rear>0}}function ab(e){let t=hr(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=lk(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 Et(e){return Wh(e.brakeModel,e.brakeSetup)}function Di(e){return an(e.brakeSetup).ideal?"tyre":e.brakeModel||e.brakeModelId?"hydraulic":"balance"}function Iu(e){let t=Di(e);return t==="hydraulic"?{brake_balance:"set by the balance bar and the brake hardware"}:t==="tyre"?{brake_balance:"tyre-limited brakes split as the grip does"}:{}}function uk(e,t){if(!(pt(e.motorModel)||!cn(e).regen))return Fi(_u(Xt(e)),t??Et(e).regen)}function _u(e){return e.fAxle??{vVehicle:e.vVehicle,fFront:e.vVehicle.map(()=>0),fRear:e.fRad.map(t=>t*e.params.driven_wheels.value)}}function sb(e,t=Et(e)){if(t.mode==="hydraulic")return wi(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+re(e,"cg_height")/Math.max(1,re(e,"wheelbase"))))}return re(e,"brake_balance")}function ib(e,t=Et(e)){return{front:t.hydraulic.front.location==="inboard",rear:t.hydraulic.rear.location==="inboard"}}function cb(e){let t=Et(e);return{brakeBalanceFront:sb(e,t),brakeInboard:ib(e,t)}}function mk(e,t=Et(e)){if(t.mode==="tyre"||t.regen.distribution!=="wheel"||pt(e.motorModel))return;let r=hr(e),n={front:r.front>=2,rear:r.rear>=2};return n.front||n.rear?n:void 0}function Ei(e){let t=Et(e),r=e.r_dyn.value,n=ib(e,t),o=sb(e,t),a=mk(e,t),s=t.mode==="hydraulic"||a?uk(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 HE=9.81;function ub(e,t){let r=pk(e,t);return(n,o,a)=>r(n,o,a).total}var lb={front:0,rear:0,total:0};function pk(e,t){if(pt(e.motorModel))return()=>lb;let r=Et(e),n=Fi(t,r.regen);if(r.mode==="hydraulic"){let a=xo({mode:"hydraulic",balanceFront:wi(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 lb;let c=a.demand(a.controlFor(s,i),i),l=c.regenFront+c.regenRear,u=Math.min(s,l),m=l>0?u/l:0;return{front:c.regenFront*m,rear:c.regenRear*m,total:u}}}let o=r.mode==="tyre"?zE(e):()=>Math.min(.99,Math.max(.01,re(e,"brake_balance")));return(a,s,i)=>{if(!(a>0))return lb;let c=o(s,i),l=Math.min(c*a,on(n.v,n.front,s)),u=Math.min((1-c)*a,on(n.v,n.rear,s));return{front:l,rear:u,total:l+u}}}function zE(e){let t=e.m.value*HE,r=e.front_mass_diss.value>1?e.front_mass_diss.value/100:e.front_mass_diss.value,n=re(e,"cg_height")/Math.max(1,re(e,"wheelbase")),o=1-Math.max(0,Math.min(1,re(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 dk(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 mb={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"},...dk("front"),...dk("rear")},pb={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 db(e){let t=mb[e];return`${t.label}, ${t.section}`.toLowerCase()}function fb(e){let t=pb[e];return t.section?`${t.section} ${t.label.charAt(0).toLowerCase()}${t.label.slice(1)}`:t.label}var fk=new WeakMap;function Dr(e){if(e.brakes)return e.brakes;let t=fk.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},fk.set(e,t)}return t}var un=e=>xo(Dr(e));var UE=Math.PI/180,Wa=Object.freeze({tbr:1,preloadN:0}),Nu=Object.freeze({tbr:1/0,preloadN:0}),bb=e=>e.faces*e.muClutch*e.rFrictionMm/e.rRampMm;function gb(e,t){if(!(e>0)||Number.isNaN(t))return 0;let r=Math.tan(Math.min(90,t)*UE);return r>0?Math.min(1,e/r):1}function bk(e){if(e>=1)return 1/0;let t=e>0?e:0;return(1+t)/(1-t)}function Ou(e){return e===1/0?1:e>1?(e-1)/(e+1):0}function vo(e,t){return e.tbr===1/0?1/0:(e.preloadN>0?e.preloadN:0)+Ou(e.tbr)*Math.abs(t)}function _i(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 Nu;case"independent":return t==="hubs"?Wa:Nu;case"clutch":{let o=n(e.preloadNm);return t==="hubs"?{tbr:1,preloadN:o}:{tbr:bk(gb(bb(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 Ii(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 hk=4;function hb(e,t){let r=0;for(let a of e)r=Math.max(r,Ii(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=d=>{d>0&&d<1&&(r=Math.max(r,Ii(s.m1+d*i,s.m2+d*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 Ni(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=qh(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=>Ro(e,b)+Ro(t,c-b),l.lo,l.hi),d=[{m1:l.c1,m2:l.c2}];for(let b=1;b<=hk&&m!==l.y1;b++){let g=l.y1+(m-l.y1)*b/hk;d.push({m1:e.cap(g),m2:t.cap(c-g)})}let p=hb(d,Wa),h=hb(d,Nu);if(!(h>p))return u;let f=(hb(d,{tbr:s,preloadN:i})-p)/(h-p);return Math.min(a,u+(a-u)*Math.min(1,Math.max(0,f)))}function gk(e,t,r,n,o,a){return yb(e,o,Ni(t,r,n,o,a))}function yb(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 xb(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,d=l-s,p=d!==0?i-l*(i-o)/d: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 h=e(p),f=h-p;if(u++,m&&f<0==l<0?s*=.5:(o=i,s=l),i=p,c=h,l=f,s<0!=l<0&&Math.abs(i-o)<=r)break}return{x:i,fx:c,evals:u}}function yk(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),d=0;for(let p=o;l<a;p*=2){if(d=Math.min(d+p,m),d>m-n)return null;let h=t+u*d,f=e(h),b=f-h;if(l++,!(Math.abs(b)>n))return{x:h,fx:f,evals:l};if(c<0!=b<0)return Rk(e,s,c,h,f,b,n,l,a);s=h,c=b}return null}function xk(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 Rk(e,o,s,c,u,m,r,l,n);if(l>=n)return{x:c,fx:u,evals:l};let d=Math.abs(c-o),p=s!==m?m*(c-o)/(s-m):NaN,h=p*i>0?Math.min(Math.abs(p),10*Math.abs(m),2*d):2*d;o=c,s=m,c+=i*h}}function Rk(e,t,r,n,o,a,s,i,c){let l=t,u=r,m=n,d=a,p=n,h=o,f=0;for(;i<c&&Math.abs(m-l)>s;){p=(l*d-m*u)/(d-u),h=e(p);let b=h-p;if(i++,!(Math.abs(b)>s))break;b<0==u<0?(l=p,u=b,f===-1&&(d*=.5),f=-1):(m=p,d=b,f===1&&(u*=.5),f=1)}return{x:p,fx:h,evals:i}}function Vu(e,t){return Math.abs(e.fx-e.x)>t?e.x:e.fx}var XE=(e,t)=>{let r=e.brakes?.hydraulic?.[t];return!!r&&r.location==="inboard"&&r.discs===1};function qt(e,t,r){let n=e.driveline?.[t];if(n)return r>=0?n.drive:XE(e,t)?n.coast:n.hubs}var vk=e=>e.tbr>1||e.preloadN>0;var qE=9.81,kk=["FL","FR","RL","RR"],Rb=e=>e==="FL"||e==="FR",Bu=e=>Rb(e)?"front":"rear",Mk={front:["FL","FR"],rear:["RL","RR"]},Bi=()=>({peak:new Map,freeBrake:new Map}),Vi=25;function Oi(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 $n=1e-4,QE=.05;function mn(e,t,r,n=Bi(),o=!1){let a=r,s=e.massTotal,i=n.peak,c=(S,w)=>{let C=`${S}:${w}`,L=i.get(C);return L||(L=Ql(Fe(t,S),Math.max(1,w*Vi)),i.set(C,L)),L},l=(S,w)=>({aPeak:Oi(w,C=>c(S,C).aPeak),fyPeak:Oi(w,C=>c(S,C).fyPeak)}),u=n.freeBrake,m=(S,w)=>{let C=`${S}:${w}`,L=u.get(C);if(L===void 0){let E=Math.max(1,w*Vi);L=jt(Fe(t,S),E,0,!0,c(S,w)),u.set(C,L)}return L},d=(S,w)=>w>0?Oi(w,C=>m(S,C)):0,p=un(e),h=Dr(e),f=S=>h.regen&&h.regenPerWheel?.[S]?on(h.regen.v,h.regen[S],a)/2:0,b=f("front"),g=f("rear"),y=(S,w,C)=>{let L=Math.max(0,w[S]),E=l(Bu(S),L);return jt(Fe(t,Bu(S)),L,C[S]*E.fyPeak,!0,E)},x=(S,w,C,L,E=!0,_=1)=>{let O=ne=>{let Z=Math.max(0,w[ne]),xe=Fe(t,S),de=l(S,Z),be={Fz:Z,a:Math.abs(d(S,Z)),b:de.fyPeak,slide:Z>0?Math.abs(xe.forces({Fz:Z,kappa:-1,alpha:0}).Fx):0,cap:U=>Math.abs(jt(xe,Z,U,!0,de))};return _===1?be:{Fz:Z,a:_*be.a,b:_*be.b,slide:_*be.slide,cap:U=>_*be.cap(U/_)}},I=ne=>_*Math.abs(C[ne])*l(Bu(ne),Math.max(0,w[ne])).fyPeak,[z,B]=Mk[S],V=O(z),j=O(B),q=I(z)+I(B),K=Qh(V,j,q,L,S==="front"?b:g),D=E?K:{...K,xLock:0},N=qt(e,S,-1),Y=N&&vk(N)?N:void 0;if(!Y)return{axle:S,eq:D,cap:D};let H=Number.isFinite(L)?L:V.cap(I(z))+j.cap(I(B)),W=gk(D,V,j,q,Y,H);return{axle:S,eq:D,cap:W,law:Y,strong:()=>V.cap(I(z))>=j.cap(I(B))?z:B}},k=(S,w,C,L,E=1)=>x(S,w,C,L,!0,E).cap,v=(S,w,C)=>{let L=S.demand,E=p.shares?Ha(w,L.front):Ka(w,(L.front-L.regenFront)/2,L.regenFront),_=p.shares?Ha(C,L.rear):Ka(C,(L.rear-L.regenRear)/2,L.regenRear);return{front:Number.isFinite(E)?E:0,rear:Number.isFinite(_)?_:0}},R=S=>({muX:w=>w>0?Math.abs(d(S,w))/w:0,muY:w=>w>0?l(S,w).fyPeak/w:0}),M={front:R("front"),rear:R("rear")},A={lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},F={front:e.trackFront/2e3,rear:e.trackRear/2e3},T=(S,w,C,L,E)=>{let _=L.cap,O=E.cap,I=Ci(p,_,O,a),z={arms:A,halfTrack:F,ayDir:Math.sign(S)};for(let B=0;B<2;B++){let V=v(I,_,O),j={};for(let K of kk){let D=Math.max(0,w[K]);j[K]={Fz:D,Fy:Math.abs(C[K])*l(Bu(K),D).fyPeak,Fx:-(Rb(K)?V.front:V.rear)/2}}let q=K=>{if(!K.law||!K.strong)return K.cap;let D={axle:K.axle,strong:K.strong(),full:2*K.cap.xNoLock,open:2*K.eq.xNoLock,sense:-1};return yb(K.eq,K.law,yu(D,j,M,z))};_=q(L),O=q(E),I=Ci(p,_,O,a)}return{limit:I,front:_,rear:O}};return{peakAt:l,axle:k,ceiling:(S,w,C)=>{let[L,E]=Mk[S];return Math.abs(y(L,w,C)+y(E,w,C))},limitAt:(S,w,C,L=0)=>{let E={FL:0,FR:0,RL:0,RR:0},_=$e(e,S,0,a,0,w),O,I=ne=>(O?.ax!==ne&&(O={ax:ne,loads:$e(e,S,(ne+L)/qE,a,0,w)}),O.loads),z=Zl(ne=>Ia(C,I(ne),_,l).short,-L,-1),B=C,V={front:0,rear:0},j,q,K=(ne,Z=!0)=>{let xe=z.at(ne);E=I(xe),B=Ia(C,E,_,l).util;let de=0,be=0,U=0;for(let ee of kk){let se=y(ee,E,B);de+=se,Rb(ee)?be+=se:U+=se}if(V={front:Math.abs(be),rear:Math.abs(U)},p.mode!=="tyre"){let ee=x("front",E,B,Math.abs(be),Z),se=x("rear",E,B,Math.abs(U),Z);if(o&&(ee.law||se.law)){let ie=T(S,E,B,ee,se);j=ie.limit,q={front:ie.front,rear:ie.rear}}else j=Ci(p,ee.cap,se.cap,a),q={front:ee.cap,rear:se.cap};de=-j.force}return de/s},D=xb(K,0,$n),N=Vu(D,$n),Y=N;if(j?.lockFront||j?.lockRear){let ne=xb(xe=>K(xe,!1),0,$n);Y=Vu(ne,$n);let Z=yk(K,ne.x,D.x,$n,QE);Z||K(D.x),N=Vu(Z??D,$n)}let H=z.edge(),W=H!==void 0&&N<H;W&&(N=Math.min(0,H),K(N),Y=Math.max(Y,N));let X={loads:E,ceiling:V,limit:j,axles:q};return{ax:N,axUnlocked:Y,...W?{edge:H}:{},...X,split:()=>X.limit&&X.axles?v(X.limit,X.axles.front,X.axles.rear):{...X.ceiling}}}}}var Gu=9.81;function ZE(e,t,r){let n=$e(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 wk=(e,t)=>t.mode==="hydraulic"&&!!Dr(e).regen;function ja(e,t,r=0,n,o=0,a=1){if(!e.brakes&&e.brakeBalanceFront==null)return e.frontMassFrac;let s=un(e);if(s.shares&&s.mode!=="tyre")return s.shares.front;let i=n&&wk(e,s)?Tk(e,n):void 0,c=i?Fk(a):ko,l=i?Ck(i,c).shares:Sk.get(e);l||Sk.set(e,l=new Map);let u=Math.round(Math.abs(t)/.005),m=Math.round(Math.max(0,r)/.25),d=i?Math.round(o/.01):0,p=Pk(u,m,d),h=l.get(p);if(h===void 0){let f=-u*.005,b=m*.25,g=e.massTotal*Math.abs(f)*Gu;if(i){let y=Dk(s,Lk(e,i,u,m,d,c),g,b);h=y.front+y.rear>0?y.front/(y.front+y.rear):.5}else h=s.mode==="tyre"?ZE(e,f,b):jh(s,g,b);l.size>5e4&&l.clear(),l.set(p,h)}return h}var Sk=new WeakMap;function Ku(e,t,r,n,o=0,a=1){let s=un(e);if(!wk(e,s))return;let i=Math.round(Math.max(0,r)/(e.massTotal*Gu)/.005),c=Math.round(Math.max(0,n)/.25);return Dk(s,Lk(e,Tk(e,t),i,c,Math.round(o/.01),Fk(a)),Math.max(0,r),n)}var ko=100,Fk=e=>e>0&&Number.isFinite(e)?Math.max(1,Math.round(e*ko)):ko;function Ck(e,t){if(t===ko)return e;let r=e.roads.get(t);return r||e.roads.set(t,r={shares:new Map,rooms:new Map}),r}var Ak=new WeakMap;function Tk(e,t){let r=Ak.get(e);r||Ak.set(e,r=new WeakMap);let n=r.get(t);return n||r.set(t,n={ev:t,tyres:Bi(),shares:new Map,rooms:new Map,speeds:new Map,roads:new Map}),n}var Pk=(e,t,r)=>(r*1001+e)*100003+t;function Lk(e,t,r,n,o,a=ko){let s=Pk(r,n,o),i=Ck(t,a),c=a===ko?1:a/ko,l=i.rooms.get(s);if(!l){let u=n*.25,m=o*.01,d=t.speeds.get(n);d||(d={cap:mn(e,t.ev,u,t.tyres),dragG:-Math.max(0,Bs(e,u).drag)/(e.massTotal*Gu)},t.speeds.set(n,d));let{cap:p}=d,h=$e(e,m,-r*.005+d.dragG,u),f=Math.abs(m)*e.massTotal*Gu,b=x=>{let[k,v]=x==="front"?["FL","FR"]:["RL","RR"],R=f*(x==="front"?e.frontMassFrac:1-e.frontMassFrac),M=c*(p.peakAt(x,Math.max(0,h[k])).fyPeak+p.peakAt(x,Math.max(0,h[v])).fyPeak),A=R>0&&M>0?Math.min(1,R/M):0;return p.axle(x,h,{FL:A,FR:A,RL:A,RR:A},1/0,c)},g,y;l=(x,k)=>(x==="front"?g??=b("front"):y??=b("rear")).regenRoom(k),i.rooms.size>5e4&&i.rooms.clear(),i.rooms.set(s,l)}return l}function $u(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 Dk(e,t,r,n){if(!(r>0))return $u(e,t,1,n);let o=c=>c.front+c.rear,a=e.controlFor(r,n),s=$u(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=$u(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=$u(e,t,l,n);o(u)<r?a=l:(i=l,s=u)}return s}var Ua={rel:.003,abs:2,kappa:1e-5,iters:12},Gn={rel:1e-6,abs:.001,kappa:1e-12,iters:40};function Kn(e,t,r,n=Ua){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)),d=e(o*m),p=Math.abs(d.Fx)-a,h=null;for(;p<0&&m<.3;){let g=Math.min(.3,m*1.9),y=e(o*g),x=Math.abs(y.Fx);if(x<Math.abs(d.Fx)){h={kappa:g,forces:y};break}c=m,l=d,u=p,m=g,d=y,p=x-a}if(p<0){let g=tI(e,o,c,l,m,d,h),y=Math.abs(g.forces.Fx);if(y<a)return{kappa:o*g.kappa,forces:g.forces};m=g.kappa,d=g.forces,p=y-a}let f=d,b=o*m;for(let g=0;g<n.iters&&m-c>n.kappa;g++){let y=p-u,x=Math.abs(y)>1e-12?(c*p-m*u)/y:.5*(c+m);x>c&&x<m||(x=.5*(c+m));let k=e(o*x),v=Math.abs(k.Fx)-a;if(f=k,b=o*x,Math.abs(v)<s)break;v<0?(c=x,u=v,p*=.5):(m=x,p=v,u*=.5)}return{kappa:b,forces:f}}var Ek=1e-6,JE=40,eI=(3-Math.sqrt(5))/2;function tI(e,t,r,n,o,a,s){let i=a,c,l,u,m=-Math.abs(a.Fx),d,p,h=-Math.abs(n.Fx);if(s){c=s.kappa;let g=-Math.abs(s.forces.Fx);[l,d,u,p]=g<=h?[c,g,r,h]:[r,h,c,g]}else{c=.3;let g=.3*(1-Ek),y=e(t*g),x=-Math.abs(y.Fx);if(x>=m)return{kappa:o,forces:a};[l,d,u,p]=[o,m,r,h],o=g,m=x,i=y}h<m&&([l,d]=[o,m],o=r,m=h,i=n);let f=c-r,b=0;for(let g=0;g<JE;g++){let y=Ek*Math.abs(o)+1e-10,x=.5*(r+c);if(Math.abs(o-x)<=2*y-.5*(c-r))break;let k=!0;if(Math.abs(f)>y){let A=(o-l)*(m-p),F=(o-u)*(m-d),T=(o-u)*F-(o-l)*A;F=2*(F-A),F>0&&(T=-T),F=Math.abs(F);let P=f;if(f=b,Math.abs(T)<Math.abs(.5*F*P)&&T>F*(r-o)&&T<F*(c-o)){b=T/F;let S=o+b;(S-r<2*y||c-S<2*y)&&(b=x>=o?y:-y),k=!1}}k&&(f=o>=x?r-o:c-o,b=eI*f);let v=Math.abs(b)>=y?o+b:o+(b>=0?y:-y),R=e(t*v),M=-Math.abs(R.Fx);M<=m?(v>=o?r=o:c=o,u=l,p=d,l=o,d=m,o=v,m=M,i=R):(v<o?r=v:c=v,M<=d||l===o?(u=l,p=d,l=v,d=M):(M<=p||u===o||u===l)&&(u=v,p=M))}return{kappa:o,forces:i}}var Hu=e=>Math.max(2,.003*Math.abs(e)),rI=(e,t)=>Math.max(t.abs,t.rel*Math.abs(e)),vb=.5,nI=.03;function oI(e,t,r,n,o,a=!1){let s=.5*(e.vx+t.vx),i=M=>{let A=(1+M)*s/e.vx-1,F=(1+M)*s/t.vx-1,T=e.at(A),P=t.at(F);return{kappaM:M,kl:A,kr:F,fl:T,fr:P,g:T.Fx+P.Fx-r}},c=rI(r,o),l=Math.max(-vb,Math.min(vb,n)),u=i(l);if(Math.abs(l)>nI){let M=i(.8*l);(u.g-M.g)/(l-M.kappaM)>0||(u=i(0))}if(Math.abs(u.g)<c)return u;let m=u.g<0?1:-1,d=u,p=u,h=.004,f=u,b=u;for(let M=0;M<12;M++){let A=d.kappaM+m*h;if(Math.abs(A)>vb)break;let F=i(A);if(Math.abs(F.g)<c)return F;if(Math.abs(F.g)<Math.abs(f.g)&&(f=F),Math.sign(F.g)!==Math.sign(d.g)){p=F;break}if(m*(F.g-d.g)<=0){if(!a)return f;let T=(Math.sqrt(5)-1)/2,P=b.kappaM,S=F.kappaM,w=i(S-T*(S-P)),C=i(P+T*(S-P));for(let E=0;E<40&&Math.abs(S-P)>1e-7;E++)m*(w.g-C.g)<0?(P=w.kappaM,w=C,C=i(P+T*(S-P))):(S=C.kappaM,C=w,w=i(S-T*(S-P)));let L=m*(w.g-C.g)>0?w:C;if(Math.abs(L.g)<c||Math.sign(L.g)===Math.sign(u.g))return Math.abs(L.g)<Math.abs(f.g)?L:f;d=m*(L.kappaM-d.kappaM)>0?d:b,p=L;break}b=d,d=F,h*=1.9}if(p===u)return f;let g=d,y=p,x=g.g,k=y.g,v=Math.abs(x)<Math.abs(k)?g:y,R=Math.min(1e-7,o.kappa);for(let M=0;M<30&&Math.abs(y.kappaM-g.kappaM)>R;M++){let A=k-x,F=Math.abs(A)>1e-12?(g.kappaM*k-y.kappaM*x)/A:.5*(g.kappaM+y.kappaM),T=Math.min(g.kappaM,y.kappaM),P=Math.max(g.kappaM,y.kappaM);F>T&&F<P||(F=.5*(T+P));let S=i(F);if(v=S,Math.abs(S.g)<c)break;Math.sign(S.g)===Math.sign(x)?(g=S,x=S.g,k*=.5):(y=S,k=S.g,x*=.5)}return v}function Ik(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 $i(e,t,r,n,o,a=Ua,s=!1){let i=oI(e,t,r,o,a,s),c=i.fr.Fx-i.fl.Fx,l=vo(n,r);if(Math.abs(c)<=l){let k=r-(i.fl.Fx+i.fr.Fx),v=Math.max(0,Math.abs(k)-Hu(r))/2;return{left:{kappa:i.kl,forces:i.fl,want:i.fl.Fx+k/2,short:v},right:{kappa:i.kr,forces:i.fr,want:i.fr.Fx+k/2,short:v},locked:!0,spoolKappa:i.kappaM}}let u=Math.sign(c),m=r/2-u*l/2,d=r/2+u*l/2,p=Kn(e.at,m,e.seed||i.kl,a),h=Kn(t.at,d,t.seed||i.kr,a),f=Math.abs(m-p.forces.Fx)>Hu(m),b=Math.abs(d-h.forces.Fx)>Hu(d),g=Math.max(0,n.preloadN),y=Ou(n.tbr);f&&!b?h=Kn(t.at,Ik(p.forces.Fx,u,g,y),h.kappa,a):b&&!f&&(p=Kn(e.at,Ik(h.forces.Fx,-u,g,y),p.kappa,a));let x=(k,v)=>({kappa:k.kappa,forces:k.forces,want:v,short:Math.max(0,Math.abs(v-k.forces.Fx)-Hu(v))});return{left:x(p,m),right:x(h,d),locked:!1,spoolKappa:i.kappaM}}var aI={front:["FL","FR"],rear:["RL","RR"]},sI=Object.freeze({Fx:0,Fy:0,Mz:0});function zu(e,t,r,n){let o=r;for(let a of["front","rear"]){let[s,i]=aI[a],c=r[s]+r[i],l=qt(e,a,c);if(!l||!(vo(l,c)>0))continue;let u=Fe(t,a),m=n.alpha[a],d=(a==="front"?e.trackFront:e.trackRear)/2e3,p=n.grip??1,h=y=>x=>u.forces({Fz:y,kappa:x,alpha:m,gamma:0}),f=y=>x=>{let k=u.forces({Fz:y,kappa:x,alpha:m,gamma:0});return{Fx:p*k.Fx,Fy:p*k.Fy,Mz:p*k.Mz}},b=(y,x)=>{let k=Math.max(0,n.Fz[y]);return{at:k>0?p===1?h(k):f(k):()=>sI,vx:Math.max(.05,1-x*n.curvature),seed:0}},g=$i(b(s,d),b(i,-d),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 Xa=["FL","FR","RL","RR"];function kb(e,t,r,n={}){let o={FL:0,FR:0,RL:0,RR:0},a={FL:!1,FR:!1,RL:!1,RR:!1};if(t===0&&!e.tvRearDiffN)return{want:o,held:a,left:0};let s=t>=0?1:-1,i=Math.abs(t),c={FL:0,FR:0,RL:0,RR:0},l={FL:1/0,FR:1/0,RL:1/0,RR:1/0};if(s>0){let p=["front","rear"].filter(h=>e.drive[h]);for(let h of p){let[f,b]=h==="front"?["FL","FR"]:["RL","RR"],g=e.drive[h],y=r[f]+r[b];g==="ideal"?(c[f]=r[f],c[b]=r[b],a[f]=a[b]=!0):c[f]=c[b]=y/2}for(let h of Xa){let f=e.motorCap?.[h];f!==void 0&&(l[h]=Math.max(0,f))}}else if(e.brake.kind==="ideal")for(let p of Xa)c[p]=r[p],a[p]=!0;else{let p=Math.min(1,Math.max(0,e.brake.front));c.FL=c.FR=p/2,c.RL=c.RR=(1-p)/2;for(let h of Xa)a[h]=e.brake.abs}let u=Math.max(-1,Math.min(1,e.idealShift??0));if(u!==0){let p={front:s>0?e.drive.front==="ideal":e.brake.kind==="ideal",rear:s>0?e.drive.rear==="ideal":e.brake.kind==="ideal"};for(let h of["front","rear"]){if(!p[h])continue;let[f,b]=h==="front"?["FL","FR"]:["RL","RR"],[g,y]=(e.turn??1)>0?[f,b]:[b,f],[x,k]=u>0?[g,y]:[y,g],v=Math.abs(u)*c[x];c[x]-=v,c[k]+=v}}for(let p of Xa){let h=n[p];a[p]&&h!==void 0&&(l[p]=Math.min(l[p],Math.max(0,h)))}let m=iI(i,c,l);for(let p of Xa)o[p]=s*m.each[p];let d=e.tvRearDiffN??0;return d&&(o.RL-=d/2,o.RR+=d/2),{want:o,held:a,left:m.left}}function iI(e,t,r){let n={FL:0,FR:0,RL:0,RR:0},o=Xa.filter(i=>t[i]>0),a=e,s=o;for(let i=0;i<4&&s.length>0&&a>0;i++){let c=s.reduce((m,d)=>m+t[d],0),l=a/c,u=s.filter(m=>l*t[m]>=r[m]);if(u.length===0){for(let m of s)n[m]=l*t[m];a=0,s=[];break}for(let m of u)n[m]=r[m],a-=r[m];s=s.filter(m=>!u.includes(m))}return{each:n,left:Math.max(0,a)}}var De=9.81,ue=Math.PI/180,cI=8,lI=.02,uI=12,_k=e=>10*Math.max(Gn.abs,Gn.rel*Math.abs(e)),Nk=1e-6,br=["FL","FR","RL","RR"],Qt=e=>e==="FL"||e==="FR",dn=e=>Qt(e)?"front":"rear";function Qa(e,t){let r=Fe(e,"front"),n=Fe(e,"rear");return r===n?So(r,t):{front:So(r,t),rear:So(n,t)}}function So(e,t){return fh(e,Math.min(t,fr(e)))}var Gi=e=>e==="FL"||e==="RL",Ok=new WeakMap;function mI(e,t){let r=Ok.get(e);r||Ok.set(e,r=new Map);let n=100*Math.ceil(2*t*De/100),o=r.get(n);if(!o){let a=Qa(e,n);o="front"in a?a:{front:a,rear:a},r.set(n,o)}return o}function Za(e,t,r=0,n,o=0,a=1){let s=t?.axG??0;if(t?.balance)return{axG:Number.isFinite(s)?s:0,fx:{FL:0,FR:0,RL:0,RR:0},balance:t.balance};let i=Number.isFinite(t?.tvRearDiffN)?t?.tvRearDiffN:0;if(!(!!s&&Number.isFinite(s))&&!i)return null;let l=e.massTotal*s*De,u=s>=0?Math.min(1,Math.max(0,t?.driveFrontFrac??0)):Math.min(.99,Math.max(.01,ja(e,s,r,n,o,a))),m=l*u/2,d=l*(1-u)/2;return{axG:s,fx:{FL:m,FR:m,RL:d-i/2,RR:d+i/2}}}function Tb(e,t,r,n){return Math.abs(Ao(e,t,r,n!==void 0?{steerMaxDeg:n}:{}).peak.steerDeg)}function Pb(e,t,r,n){let o=e.tv;if(!o?.enabled)return 0;let a=oM(o)(t,Math.abs(r),n);return r<0?-a:a}function Lb(e,t,r=0,n,o=0,a=0,s,i=1){let c=Za(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?zu(e,n,l,s):l}var Hi=e=>Gi(e)?-1:1,Wu=(e,t,r,n,o)=>t*e.Fy(t*r,n,t*o);function Fb(e){let t=e.wheelbase/1e3,r=t*(1-e.frontMassFrac),n=t*e.frontMassFrac;return{wb:t,lf:r,lr:n,m:e.massTotal}}function pI(e,t,r){let n=Math.abs(t),o=e.steerFront;if(o&&o.meanDeg.length>1){let u=t>=0,m=r&&o.travelSurface?Pa(o,n/ue,u?r.FL:r.FR,u?r.FR:r.FL):La(o,n/ue);return{innerMag:m.innerDeg*ue,outerMag:m.outerDeg*ue,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)),d=Math.atan(s/(u+a/2));c=n+i*(m-n),l=n+i*(d-n)}return{innerMag:c,outerMag:l,innerCamber:0,outerCamber:0,atLock:!1}}function wo(e,t,r){let n=(e.toeFrontDeg??0)*ue,o=(e.toeRearDeg??0)*ue,a=pI(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 ju(e,t,r){if(r.Fz<=0)return 0;let n=Dt(Fe(e,dn(t))),o=Hi(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 Vk(e,t,r,n){if(!bo(e))return null;let o=Dt(Fe(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:ju(o,s,i)}}return bi(e,r/ue,a,Nn(o.model),{FL:n.FL.travelMm,FR:n.FR.travelMm})}var Bk=()=>({totalNm:[],aligningNm:[],lateralNm:[],longitudinalNm:[],jackingNm:[]});function $k(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 dI=Object.freeze({Fx:0,Fy:0,Mz:0});function Gk(e,t,r){let n=t==="front"?(r?.FL??0)+(r?.FR??0):(r?.RL??0)+(r?.RR??0),o=qt(e,t,n);return o&&vo(o,n)>0?{F:n,law:o}:null}function Zt(e,t,r,n,o,a,s,i,c){let l=s?.fx,u=s?.axG??0,{wb:m,lf:d,lr:p,m:h}=Fb(e),f=Gk(e,"front",l),b=Gk(e,"rear",l),g={front:0,rear:0},y=i!==void 0&&i>0&&Number.isFinite(i)?i:null,x=U=>y===null?r:Math.sqrt(Math.max(0,U)*y),k=Dt(Fe(t,"front")),v=Dt(Fe(t,"rear")),R=e.trackFront/2e3,M=e.trackRear/2e3,A=!!(e.kinFront&&e.kinRear),F=A&&y===null?Vn(e,e.kinFront,e.kinRear,r):null,T=NaN,P=null,S=U=>{if(!A)return null;if(y===null)return F;let ee=x(U);return ee!==T&&(T=ee,P=Vn(e,e.kinFront,e.kinRear,ee)),P},w={},C={FL:0,FR:0,RL:0,RR:0},L=e.kinFront?.compliance,E=e.kinRear?.compliance,_=!!(L||E),O=!!(L?.toePerMz||E?.toePerMz),I=U=>Qt(U)?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}},B=!1,V=s?.balance,j=0,q=V?mI(t,h):null,K=(U,ee)=>ee>0&&q?q[dn(U)].muX(ee)*ee:0,D=U=>{let ee=U/r,se=y===null?n+d*ee/r:n+d/y,ie=y===null?n-p*ee/r:n-p/y,Re=S(U),pe=x(U),ce=Re?Re(U/De,u,n/ue,o/ue):null,Pe=ce?{FL:ce.FL.travel,FR:ce.FR.travel}:void 0,ke=Xl(e,U/De,u,pe,n/ue,o/ue,Pe,ce?.steeringJacking),ae=ke.loads;B=ke.overturned;let ge=wo(e,o,Pe),fe=ge.steer,Ce=0,Ae=Ne=>{let Te=Math.max(0,ae[Ne]),ye=Hi(Ne),me=Qt(Ne)?k:v,Me=I(Ne),Xe=0,Ye=0;if(Me){let Nt=z[Ne];Xe=Me.toePerFy*Nt.fy+Me.toePerFx*Nt.fx+Me.toePerMz*Nt.mz,Ye=Me.camberPerFy*Nt.fy+Me.camberPerFx*Nt.fx}let Le=fe[Ne]+(ce?ye*ce[Ne].bumpToe*ue:0)+ye*Xe*ue,Ke=Le-(Qt(Ne)?se:ie),vt=(ce?ce[Ne].camberRoad:0)*ue+ye*(ge.camber[Ne]+Ye)*ue;return{Fz:Te,mir:ye,t:me,gains:Me,complianceToe:Xe,steerK:Le,slip:Ke,camberRad:vt}},Ge=(Ne,Te)=>{let ye=y===null?ee/r:1/y,me=Qt(Ne)?d:-p,Me=(Gi(Ne)?1:-1)*(Qt(Ne)?R:M),Xe=(Math.cos(n)-Me*ye)*Math.cos(Te.steerK)+(Math.sin(n)+me*ye)*Math.sin(Te.steerK);return{at:Te.Fz>0?Ye=>Te.t.forces({Fz:Te.Fz,kappa:Ye,alpha:Te.mir*Te.slip,gamma:Te.mir*Te.camberRad}):()=>dI,vx:Math.max(.05,Xe),seed:C[Ne]}};if(V){let Ne=h*(u*De-(V.axDrag??0)),Te=0;for(let ye=0;ye<uI;ye++){let me={FL:Ae("FL"),FR:Ae("FR"),RL:Ae("RL"),RR:Ae("RR")},Me={FL:K("FL",me.FL.Fz),FR:K("FR",me.FR.Fz),RL:K("RL",me.RL.Fz),RR:K("RR",me.RR.Fz)},Xe=Ne-j,Ye={...V.spec,turn:o<0?-1:1,...Xe<0&&V.brakeFront&&V.spec.brake.kind==="shares"?{brake:{...V.spec.brake,front:V.brakeFront(Xe)}}:{}},Le={},Ke=kb(Ye,Xe,Me,Le),vt={};for(let mt=0;mt<5;mt++){let He=!1;for(let We of["front","rear"]){let[Oe,rt]=We==="front"?["FL","FR"]:["RL","RR"],Pt=Ke.want[Oe]+Ke.want[rt],pr=qt(e,We,Pt);if(pr&&vo(pr,Pt)>0){let Ve=ct=>Math.max(0,Math.abs(Pt-ct.left.forces.Fx-ct.right.forces.Fx)-_k(Pt)),ve=$i(Ge(Oe,me[Oe]),Ge(rt,me[rt]),Pt,pr,g[We],Gn,!0);if(Ve(ve)>0&&(g[We]!==0||C[Oe]!==0||C[rt]!==0)){let ct=$i({...Ge(Oe,me[Oe]),seed:0},{...Ge(rt,me[rt]),seed:0},Pt,pr,0,Gn,!0);Ve(ct)<Ve(ve)&&(ve=ct)}g[We]=ve.spoolKappa,C[Oe]=ve.left.kappa,C[rt]=ve.right.kappa;let kt=Ke.held[Oe]&&Ke.held[rt],oo=Ve(ve);if(kt&&oo>0){let ct=Math.abs(ve.left.forces.Fx),Wr=Math.abs(ve.right.forces.Fx);(Le[Oe]===void 0||Le[rt]===void 0||ct<Le[Oe]-1e-6||Wr<Le[rt]-1e-6)&&(Le[Oe]=Math.min(ct,Le[Oe]??1/0),Le[rt]=Math.min(Wr,Le[rt]??1/0),He=!0)}vt[Oe]={kappa:ve.left.kappa,Fx:ve.left.forces.Fx,Fy:me[Oe].mir*ve.left.forces.Fy,short:kt?0:oo/2},vt[rt]={kappa:ve.right.kappa,Fx:ve.right.forces.Fx,Fy:me[rt].mir*ve.right.forces.Fy,short:kt?0:oo/2};continue}for(let Ve of[Oe,rt]){let ve=me[Ve],kt=Ke.want[Ve];if(kt===0||ve.Fz<=0){let da=ve.Fz<=0&&!Ke.held[Ve]?Math.abs(kt):0;ve.Fz<=0&&Ke.held[Ve]&&kt!==0&&Le[Ve]===void 0&&(Le[Ve]=0,He=!0),vt[Ve]={kappa:0,Fx:0,Fy:ve.Fz>0?Wu(ve.t,ve.mir,ve.slip,ve.Fz,ve.camberRad):0,short:da};continue}let ct=Kn(da=>ve.t.forces({Fz:ve.Fz,kappa:da,alpha:ve.mir*ve.slip,gamma:ve.mir*ve.camberRad}),kt,C[Ve],Gn);C[Ve]=ct.kappa;let Wr=_k(kt),Nx=Math.abs(kt-ct.forces.Fx);if(Nx>Wr&&Math.abs(ct.forces.Fx)<Math.abs(kt)&&Ke.held[Ve]){let da=Math.abs(ct.forces.Fx);(Le[Ve]===void 0||da<Le[Ve])&&(Le[Ve]=da,He=!0)}vt[Ve]={kappa:ct.kappa,Fx:ct.forces.Fx,Fy:ve.mir*ct.forces.Fy,short:Ke.held[Ve]?0:Math.max(0,Nx-Wr)}}}if(!He)break;Ke=kb(Ye,Xe,Me,Le)}let Nt=0,Sr=0;Te=0;for(let mt of br){let He=me[mt],We=vt[mt];if(w[mt]={Fz:He.Fz,travelMm:ce?.[mt].travel??0,steerRad:He.steerK,slipRad:He.slip,camberRad:He.camberRad,Fy:We.Fy,Fx:We.Fx,kappa:We.kappa,fxShort:We.short+Ke.left/4,lifted:ke.lifted[mt]},He.gains){let rt=O&&He.gains.toePerMz?ju(He.t,mt,w[mt]):0;z[mt]={fy:-He.mir*We.Fy,fx:We.Fx,mz:-He.mir*rt*1e3};let Pt=z[mt];Sr=Math.max(Sr,Math.abs(He.gains.toePerFy*Pt.fy+He.gains.toePerFx*Pt.fx+He.gains.toePerMz*Pt.mz-He.complianceToe))}let Oe=He.steerK-n;Nt+=We.Fx*(Math.cos(Oe)-1)-We.Fy*Math.sin(Oe),Te+=We.Fy*Math.cos(Oe)+We.Fx*Math.sin(Oe)}let wn=Math.abs(Nt-j);if(j=Nt,wn<lI&&Sr<Nk)break}return Te/h}for(let Ne=0;Ne<(_?cI:1);Ne++){Ce=0;let Te=0,ye={};for(let me of br){let Me=Qt(me)?f:b;if(Me&&!ye[me]){let[Ve,ve]=Qt(me)?["FL","FR"]:["RL","RR"],kt=Ae(Ve),oo=Ae(ve),ct=dn(me),Wr=$i(Ge(Ve,kt),Ge(ve,oo),Me.F,Me.law,g[ct],Gn);g[ct]=Wr.spoolKappa,ye[Ve]={w:kt,share:Wr.left},ye[ve]={w:oo,share:Wr.right}}let Xe=ye[me]?.w??Ae(me),{Fz:Ye,mir:Le,t:Ke,gains:vt,complianceToe:Nt,steerK:Sr,slip:wn,camberRad:mt}=Xe,He=l?.[me]??0,We,Oe=0,rt=0,Pt=0,pr=ye[me]?.share;if(pr)C[me]=pr.kappa,rt=pr.kappa,Oe=pr.forces.Fx,Pt=pr.short,We=Le*pr.forces.Fy;else if(He===0||Ye<=0)We=Wu(Ke,Le,wn,Ye,mt),Pt=Ye<=0?Math.abs(He):0;else{let ve=Kn(kt=>Ke.forces({Fz:Ye,kappa:kt,alpha:Le*wn,gamma:Le*mt}),He,C[me],Gn);C[me]=ve.kappa,rt=ve.kappa,Oe=ve.forces.Fx,Pt=Math.max(0,Math.abs(He-Oe)-Math.max(Ua.abs,Ua.rel*Math.abs(He))),We=Le*ve.forces.Fy}if(w[me]={Fz:Ye,travelMm:ce?.[me].travel??0,steerRad:Sr,slipRad:wn,camberRad:mt,Fy:We,Fx:Oe,kappa:rt,fxShort:Pt,lifted:ke.lifted[me]},vt){let Ve=O&&vt.toePerMz?ju(Ke,me,w[me]):0;z[me]={fy:-Le*We,fx:Oe,mz:-Le*Ve*1e3};let ve=z[me];Te=Math.max(Te,Math.abs(vt.toePerFy*ve.fy+vt.toePerFx*ve.fx+vt.toePerMz*ve.mz-Nt))}Ce+=We*Math.cos(Sr)+Oe*Math.sin(Sr)}if(Te<Nk)break}return Ce/h},N=U=>{let ee=$e(e,0,u,U,0,o/ue);return ee.FL+ee.FR+ee.RL+ee.RR},Y=Math.max(20,3.5*N(r)/h);if(y!==null){Y=4*De;for(let U=0;U<8;U++){let ee=Math.min(40*De,3.5*N(x(Y))/h);if(ee<=Y)break;Y=ee}Y=Math.max(20,Y)}let H=U=>D(U)-U,W=Math.max(.001,Y*1e-4),X=(U,ee,se,ie)=>{let Re=U,pe=se,ce=ee,Pe=ie,ke=Re;for(let ae=0;ae<40;ae++){let ge=Pe-ce,fe=Math.abs(ge)>1e-12?(Re*Pe-pe*ce)/ge:.5*(Re+pe),Ce=Math.min(Re,pe),Ae=Math.max(Re,pe);fe>Ce&&fe<Ae||(fe=.5*(Re+pe));let Ge=H(fe);if(ke=fe,Math.abs(Ge)<1e-4||Ae-Ce<1e-6)break;Ge<0==ce<0?(Re=fe,ce=Ge,Pe*=.5):(pe=fe,Pe=Ge,ce*=.5)}return ke},ne=(U,ee,se,ie=!1)=>{let Re=(ae,ge)=>se>0?ae>0&&ge<0:ge>0&&ae<0,pe=U,ce=ee,Pe=U+se*Math.min(Math.abs(ee),Y);if(!ie&&Math.abs(Pe-U)>W){let ae=H(Pe);if(Re(ce,ae))return{root:X(pe,ce,Pe,ae),last:pe};pe=Pe,ce=ae}let ke=ie?Y/24:Math.max(Y/24,Math.abs(Pe-U)/4);for(let ae=1;ae<=24;ae++){let ge=pe+se*ke;if(Math.abs(ge)>Y)break;let fe=H(ge);if(Re(ce,fe))return{root:X(pe,ce,ge,fe),last:pe};if(ie&&fe*se<0&&(fe-ce)*se<0)break;pe=ge,ce=fe}return{root:null,last:pe}},Z=c??null;if(c===void 0&&a!==void 0&&Number.isFinite(a)&&Math.abs(a)<=Y){let U=H(a);if(Math.abs(U)<=1e-4)H(a+W)<0&&H(a-W)>0&&(Z=a);else{let ee=ne(a,U,Math.sign(U)).root;Z=ee!==null&&(ee===0||Math.sign(ee)===Math.sign(a))?ee:null}}let xe=Z===null;if(Z===null){let U=H(0),ee=H(W),se=Math.abs(U)<=1e-4,ie=se?y!==null?1:o!==0?Math.sign(o):ee>0?1:-1:Math.sign(U),Re=se?ie*W:0,pe=se?ie>0?ee:H(-W):U,ce=ne(Re,pe,ie);Z=ce.root??(se?0:ce.last)}let de=D(Z);if(xe&&o!==0&&y===null){let U=Math.sign(o);if(Z*U<=0||(w.RL.Fy+w.RR.Fy)*U<0){let ee={...w},se=B,ie=U*Math.max(Z*U+W,n*U*r*r/p),Re=null;if(ie*U<Y){let pe=H(ie);if(pe*U>0)Re=ne(ie,pe,U).root;else{let ce=ie+U*Y/24,Pe=H(ce);(Pe-pe)*U>0&&(Re=ne(ce,Pe,U,Pe*U<=0).root)}}Re!==null&&Re*U>0?(Z=Re,de=D(Z)):(Object.assign(w,ee),B=se)}}let be=d*(w.FL.Fy*Math.cos(w.FL.steerRad)+w.FR.Fy*Math.cos(w.FR.steerRad))-p*(w.RL.Fy+w.RR.Fy);if(V){be=0;for(let U of br){let ee=w[U],se=Qt(U)?d:-p,ie=(Gi(U)?1:-1)*(Qt(U)?R:M),Re=Math.cos(ee.steerRad),pe=Math.sin(ee.steerRad);be+=se*(ee.Fy*Re+ee.Fx*pe)-ie*(ee.Fx*Re-ee.Fy*pe)}}else if(s||f||b){let U=ee=>(Gi(ee)?1:-1)*(Qt(ee)?R:M);for(let ee of br){let se=w[ee],ie=Qt(ee)?d:-p;be+=ie*se.Fx*Math.sin(se.steerRad)-U(ee)*se.Fx*Math.cos(se.steerRad)}}return y!==null&&Z<-1e-6?{ay:NaN,cn:NaN,wheels:w,overturned:B,res:NaN}:{ay:Z/De,cn:be/(h*De*m),wheels:w,overturned:B,res:de-Z}}function fI(e,t,r,n,o,a,s,i=0){let c=20*ue,l=.001,u=(f,b)=>{let g=Zt(e,t,r,f,n,b,s);return{cn:g.cn-i,ay:g.ay*De}},m=f=>n===0||i!==0||Math.abs(f)<.05||Math.sign(f)===Math.sign(n),d=(f,b,g,y)=>{let x=u(f,y);if(Math.abs(x.cn)<1e-5)return{beta:f,trimmed:!0};let k=y===void 0?void 0:x.ay,v={pos:{b:f,cn:x.cn,ay:k},neg:{b:f,cn:x.cn,ay:k}},R=null,M=f,A=Math.abs(x.cn);for(let F=0;F<b.length&&!R;F++)for(let T of[v.pos,v.neg]){let P=T===v.pos?1:-1,S=f+P*b[F];if(Math.abs(S)>c)continue;let w=u(S,T.ay);if(Math.abs(w.cn)<A&&m(w.ay)&&(A=Math.abs(w.cn),M=S),w.cn===0&&m(w.ay))return{beta:S,trimmed:!0};if(w.cn<0!=T.cn<0){let C={lo:T.b,hi:S,ayLo:T.ay},L=Kk(u,C),E=u(L,T.ay);if(Math.abs(E.cn)<l&&m(E.ay))return R=C,{beta:L,trimmed:!0}}T.b=S,T.cn=w.cn,y!==void 0&&(T.ay=w.ay)}return R?{beta:Kk(u,R),trimmed:!0}:g?{beta:M,trimmed:!1}:null},p=[.25,.75,2,5].map(f=>f*ue);if(o!==void 0&&Number.isFinite(o)&&Math.abs(o)<=c){let f=d(o,p,!1,a);if(f)return f;if(!s&&i===0&&a!==void 0&&Number.isFinite(a)){let b=hI(e,t,r,n,o,a,c);if(b&&m(b.ay))return{beta:b.beta,trimmed:!0,ay:b.ay}}}let h=[1,3,7,15,20].map(f=>f*ue).filter(f=>f<=c);return d(0,h,!0)??{beta:0,trimmed:!1}}function Kk(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),d=m.cn;if(o!==void 0&&(o=m.ay),i=u,Math.abs(d)<1e-5||Math.abs(n-r)<1e-5)break;d<0==a<0?(r=u,a=d,s*=.5):(n=u,s=d,a*=.5)}return i}function hI(e,t,r,n,o,a,s){let i=(d,p)=>{let h=Zt(e,t,r,d,n,void 0,null,void 0,p);return{r:h.res,c:h.cn}},c=o,l=a,u=i(c,l),m=0;for(let d=0;d<bI;d++){let p=i(c+Mb,l),h=i(c,l+Sb),f=(p.r-u.r)/Mb,b=(h.r-u.r)/Sb,g=(p.c-u.c)/Mb,y=(h.c-u.c)/Sb,x=f*y-b*g;if(!Number.isFinite(x)||x===0||Math.abs(x)<RI*(Math.abs(f*y)+Math.abs(b*g)))return null;if(d===0)m=Math.sign(x);else if(Math.sign(x)!==m)return null;if(Math.abs(u.r)<=1e-4&&Math.abs(u.c)<=1e-5)return{beta:c,ay:l};let k=(u.c*b-u.r*y)/x,v=(u.r*g-u.c*f)/x,R=Math.min(1,gI/Math.max(Math.abs(k),1e-300),yI/Math.max(Math.abs(v),1e-300));if(c+=R*k,l+=R*v,Math.abs(c-o)>xI||Math.abs(c)>s||l*a<0)return null;u=i(c,l)}return null}var bI=8,Mb=1e-5,Sb=.001,gI=1*ue,yI=2,xI=5*ue,RI=.5;function Xk(e,t,r,n,o,a,s,i){let c=Zt(e,t,r,n,o,a,s,void 0,i),l=c.ay*De/r,u={},m=0;for(let h of br){let f=c.wheels[h],b=Fe(t,dn(h)),g=fr(b),y=b.muY(Math.min(f.Fz,g)),x=b.muX(Math.min(f.Fz,g));m+=f.fxShort,u[h]={Fz:f.Fz,steerDeg:f.steerRad/ue,slipDeg:f.slipRad/ue,camberDeg:f.camberRad/ue,Fy:f.Fy,Fx:f.Fx,Mz:ju(b,h,f),gripUtil:y*f.Fz>0?Math.hypot(f.Fy/(y*f.Fz),x*f.Fz>0?f.Fx/(x*f.Fz):0):0,...f.Fz>g?{pastTurnover:!0}:{},lifted:f.lifted}}let d=bi(e,o/ue,u,Nn(Fe(t,"front").model),{FL:c.wheels.FL.travelMm,FR:c.wheels.FR.travelMm}),p=wo(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/ue,yawRate:l*180/Math.PI,steerDeg:o/ue,...p.atLock?{lockDeg:(p.steer.FL+p.steer.FR)/2/ue}:{},converged:!0,trimmed:!c.overturned,overturned:c.overturned,driving:!1,fxShortfall:m,...d?{steering:d}:{}}}function fn(e,t,r,n,o,a,s=0){let i=Math.max(8,r),c=Mo(e,t,i,n,o,a,s);return n!==0&&o?.driving===void 0&&(c.driving=_I(e,t,i,c,a,s)),c}function Mo(e,t,r,n,o,a,s){let i=n*ue,c=Za(e,a,r,t),l=o&&Number.isFinite(o.ay)?o.ay*De:void 0,u=o&&Number.isFinite(o.beta)?o.beta*ue:void 0,{beta:m,trimmed:d,ay:p}=fI(e,t,r,i,u,l,c,s),h=Xk(e,t,r,m,i,l,c,p),f={...h,trimmed:d&&!h.overturned};return f.driving=n===0?f.trimmed:o?.driving!==void 0&&o.driving&&f.trimmed&&Math.abs(f.beta-o.beta)<=vI,f}var vI=3;function Ao(e,t,r,n={}){let o=Math.max(8,r),a=n.direction??1,s=n.yawDemandCn??0,i=n.steerMaxDeg??kI,c=typeof n.op=="function"?n.op:()=>n.op,l=typeof n.op=="function"||n.op?.balance?null:`${o}|${a}|${s}|${i}|${n.op?`${n.op.axG}|${n.op.driveFrontFrac??""}|${n.op.tvRearDiffN??""}`:""}`;if(l!==null){let R=Ab.get(e)?.get(t)?.get(l);if(R)return R}let u=(R,M)=>M.trimmed&&Math.abs(M.beta-R.beta)<=Uu&&Math.abs(M.ay-R.ay)*De<=Xu,m=!1,d=(R,M)=>{let A=Mo(e,t,o,a*R,M,c(a*R),s);return u(M,A)?(A.driving=!0,A):(m=A.overturned,null)},p=[Mo(e,t,o,0,void 0,c(0),s)],h=null,f=!1,b,g=R=>{let M=p.length-1;for(;M>1&&R.sb*(p[M].beta-p[M-1].beta)>=0;)M--;let A=a*(R.state.ay-p[M].ay)>0,F=T=>R.sb*(T.beta-R.state.beta)>0||a*T.steerDeg>=a*R.state.steerDeg||A&&a*T.ay>=a*R.state.ay;for(;p.length>Math.max(2,M)&&F(p[p.length-1]);)p.pop();b={state:R.state,stall:p[p.length-1]},p.push(R.state),h=Math.abs(R.state.steerDeg)},y=(R,M=!1)=>M||DI(p[p.length-1],R)?EI(e,t,o,a,p,R,c,s):null,x=p[0].trimmed?p[0]:null;if(!x){let R=0;for(let M=Hk;M<=i&&!x;M+=Hk){let A=Mo(e,t,o,a*M,void 0,c(a*M),s);if(A.trimmed){let F=M;x=A;for(let T=0;T<6;T++){let P=.5*(R+F),S=Mo(e,t,o,a*P,void 0,c(a*P),s);S.trimmed?(F=P,x=S):R=P}}else R=M}x&&(x.driving=!0,p.push(x))}if(x){let R=Math.abs(x.steerDeg),M=Math.min(wb,100/(o*o)),A=x;for(;R<i;){let F=Math.min(i,R+M),T=d(F,A);if(T){let L=y(T);if(L){g(L);break}if(p.push(T),F>=i||nM(e,a*F))break;Math.abs(T.beta-A.beta)<.5*Uu&&Math.abs(T.ay-A.ay)*De<.5*Xu&&(M=Math.min(wb,1.5*M)),R=F,A=T;continue}if(M>MI){M*=.5;continue}let P=m,S=!1,w=null;for(let L of SI){let E=Math.min(i,R+L);if(E<=R)continue;let _=d(E,A);if(_){if(w=y(_,!0),w)break;p.push(_),R=E,A=_,M=Math.min(wb,100/(o*o)),S=!0;break}}if(S)continue;if(w){g(w);break}h=R,f=P;let C=P?null:LI(e,t,o,a,p,c,s);C&&g(C);break}}else h=0;let k=p[0];for(let R of p)a*R.ay>a*k.ay&&(k=R);let v={states:p,foldDeg:h,rollover:f,peak:k,...b?{fold:b}:{}};if(l!==null){let R=Ab.get(e);R||(R=new WeakMap,Ab.set(e,R));let M=R.get(t);M||(M=new Map,R.set(t,M)),M.size>256&&M.clear(),M.set(l,v)}return v}var Ab=new WeakMap,kI=90,Uu=1.5,Xu=2.5,wb=5,MI=.002,SI=[.5,1],Hk=2.5,qk=.01,pn=.001,AI=.05,wI=.25,FI=5,CI=2,zk=1e-8,TI=1e-7,PI=1e-6;function Qk(e,t,r,n,o,a,s){let i=n*ue,c=o.ay*De,l=b=>{let g=Zt(e,t,r,i,b*ue,c,Za(e,a(b),r,t));return{g:g.cn-s,ay:g.ay}},u=o.steerDeg,m=l(u),d=u+(u<0?-.001:.001),p=l(d),h=()=>p.g===0||Math.abs(d-u)<zk;for(let b=0;b<40&&Math.sign(m.g)===Math.sign(p.g)&&!h();b++){let g=(p.g-m.g)/(d-u),y=g!==0?d-p.g/g:d+2*(d-u);if(!Number.isFinite(y))return null;let x=2*Math.abs(d-u)+.001;if(y=d+Math.max(-x,Math.min(x,y-d)),u=d,m=p,d=y,p=l(d),Math.abs(d-o.steerDeg)>CI)return null}let f={x:d,ay:p.ay};if(Math.sign(m.g)!==Math.sign(p.g)){let b=u,g=m.g,y=d,x=p.g;for(let k=0;k<60&&x!==0&&Math.abs(y-b)>zk;k++){let v=(b*x-y*g)/(x-g),R=l(v);if(f={x:v,ay:R.ay},R.g===0)break;Math.sign(R.g)===Math.sign(g)?(b=v,g=R.g,x*=.5):(y=v,x=R.g,g*=.5)}}else if(!h())return null;return Math.abs(f.ay-o.ay)*De>Xu?null:{steerDeg:f.x,ay:f.ay}}function Ki(e,t,r,n,o){let a=Xk(e,t,r,n.beta*ue,n.steerDeg*ue,n.ay*De,Za(e,o(n.steerDeg),r,t));return{...a,trimmed:!a.overturned,driving:!a.overturned}}function LI(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 d=Zk(e,t,r,a,s),p=d(u.beta,u),h=d(c.beta,c);if(!p||!h)return null;let f=n*h.steerDeg>=n*p.steerDeg,b=f?p:h,g=f?h:p,y=f?m:-m,x=null;for(let R=qk;Math.abs(g.beta-c.beta)<=Uu;R*=1.5){let M=d(g.beta+y*R);if(!M)return null;if(n*M.steerDeg<=n*g.steerDeg){x=M;break}b=g,g=M}if(!x)return null;let k=Jk(d,n,b,g,x);if(!k)return null;let v=Ki(e,t,r,k,a);return!v.trimmed||Math.abs(v.beta-c.beta)>Uu||Math.abs(v.ay-c.ay)*De>Xu?null:{state:v,sb:m}}function Zk(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=Qk(e,t,r,s,i,n,o);if(!c)return null;let l={beta:s,...c};return a.push(l),l}}function DI(e,t){let r=Math.abs(t.beta-e.beta);return r>wI&&r>FI*Math.abs(t.steerDeg-e.steerDeg)}function EI(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],d=Math.sign(a.beta-l.beta);if(d===0||Math.sign(l.beta-m.beta)!==d||!m.driving)return null;let p=Zk(e,t,r,s,i),h=p(m.beta,m),f=p(l.beta,l);if(!h||!f||n*f.steerDeg<n*h.steerDeg)return null;let b=h,g=f,y=null;for(let x=qk;d*(a.beta-g.beta)>0;x=Math.min(AI,1.5*x)){let k=p(d*(a.beta-g.beta)>x?g.beta+d*x: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 R=Jk(p,n,...y);if(!R)return null;let M=Ki(e,t,r,R,s);return M.trimmed?{state:M,sb:d}:null}b=g,g=k}return null}function Jk(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,d=0;for(let p=0;p<100;p++){let h=.5*(s+i);if(Math.abs(c.beta-h)<=2*pn-.5*(i-s))break;let f=!0;if(Math.abs(m)>pn){let g=(c.beta-l.beta)*(a(c)-a(u)),y=(c.beta-u.beta)*(a(c)-a(l)),x=(c.beta-u.beta)*y-(c.beta-l.beta)*g;y=2*(y-g),y>0&&(x=-x),y=Math.abs(y);let k=m;if(m=d,Math.abs(x)<Math.abs(.5*y*k)&&x>y*(s-c.beta)&&x<y*(i-c.beta)){d=x/y;let v=c.beta+d;(v-s<2*pn||i-v<2*pn)&&(d=h>=c.beta?pn:-pn),f=!1}}f&&(m=c.beta>=h?s-c.beta:i-c.beta,d=tM*m);let b=e(Math.abs(d)>=pn?c.beta+d:c.beta+(d>=0?pn:-pn));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],d=u[u.length-1],p=l(m),h=l(d);if(p>0||h<0)return null;if(h===0)return Ki(e,t,r,d,i);let f=m;for(let b=0;b<60&&Math.abs(d.beta-m.beta)>1e-9;b++){let g=(m.beta*h-d.beta*p)/(h-p),y=u[0];for(let R of u)Math.abs(R.beta-g)<Math.abs(y.beta-g)&&(y=R);let x=Qk(e,t,r,g,y,i,c);if(!x)return null;let k={beta:g,...x};u.push(k),f=k;let v=l(k);if(Math.abs(v)<("steerDeg"in a?TI:PI))break;v<0?(m=k,p=v,h*=.5):(d=k,h=v,p*=.5)}return Ki(e,t,r,f,i)}function II(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=Mo(e,t,r,o,l,u,a.yawDemandCn??0);return m.driving?m:null}function _I(e,t,r,n,o,a){if(!n.trimmed)return!1;let s=n.steerDeg<0?-1:1,{states:i}=Ao(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)],d=Math.abs(m.steerDeg)-Math.abs(u.steerDeg),p=d>0?Math.min(1,Math.max(0,(c-Math.abs(u.steerDeg))/d)):0,h=u.beta+p*(m.beta-u.beta),f=u.ay+p*(m.ay-u.ay);return Math.abs(n.beta-h)<=1&&Math.abs(n.ay-f)<=.05}function Hn(e,t,r,n,o){let a=Math.max(8,r),s=n>=0?1:-1,i=Math.abs(n),c=(b,g)=>fn(e,t,a,s*b,g,o),l=Ao(e,t,a,{direction:s,op:o}),{fold:u}=l;if(u&&Math.abs(u.state.steerDeg)<=qa){if(i>Math.abs(u.state.ay))return Wk(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)<=qa),d=m[m.length-1],p=l.states.length>m.length;p&&Math.abs(d.steerDeg)<qa&&m.push(c(qa,d));let h=m.findIndex(b=>Math.abs(b.ay)>=i);if(h===0)return fn(e,t,a,0,void 0,o);if(h>0)return Yk(m[h-1],m[h],i,c);let f=eM(m,c,void 0,p||l.foldDeg===null);return f.ay>=i?Yk(f.below,f.state,i,c):l.foldDeg!==null&&l.foldDeg<qa?Wk(e,t,a,s,i,o):f.state}var qa=20;function Yk(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 d=a.f===o.f?.5*(o.steer+a.steer):o.steer-o.f*(a.steer-o.steer)/(a.f-o.f),p=n(d,i),h=Math.abs(p.ay)-r;if(Math.abs(h)<u&&(l=p,u=Math.abs(h)),Math.abs(h)<=NI||a.steer-o.steer<=OI)break;h<0?(o={steer:d,f:h},c===-1&&(a.f*=.5),c=-1):(a={steer:d,f:h},c===1&&(o.f*=.5),c=1)}return l}var NI=1e-9,OI=1e-7;function eM(e,t,r,n=!1){let o=r??0;if(r===void 0)for(let R=1;R<e.length;R++)Math.abs(e[R].ay)>Math.abs(e[o].ay)&&(o=R);let a=e[Math.max(0,o-1)],s=Math.abs(e[o].steerDeg),i=VI/4,c,l,u,m,d,p,h,f,b=null,g;if(o>0&&o<e.length-1){let R=e[o+1];g=F=>{if(F<s)return t(F,a);let T=t(F,e[o]);return T.ay===e[o].ay?t(F,a):T},c=Math.abs(a.steerDeg),l=Math.abs(R.steerDeg),u=s,m=-Math.abs(e[o].ay);let[M,A]=Math.abs(a.ay)>=Math.abs(R.ay)?[a,R]:[R,a];d=Math.abs(M.steerDeg),p=-Math.abs(M.ay),h=Math.abs(A.steerDeg),f=-Math.abs(A.ay)}else{let R=Math.abs(e[o].lockDeg??e[o].steerDeg),M=R-BI,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 F=t(s,a);return{state:F,below:a,ay:Math.abs(F.ay)}}g=F=>t(F,a),c=Math.abs(a.steerDeg),l=R,u=M,m=-Math.abs(A.ay),b=A,d=R,p=-Math.abs(e[o].ay),h=c,f=-Math.abs(a.ay)}let y=l-c,x=0;for(let R=0;R<100;R++){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-d)*(m-f),w=(u-h)*(m-p),C=(u-h)*w-(u-d)*S;w=2*(w-S),w>0&&(C=-C),w=Math.abs(w);let L=y;if(y=x,Math.abs(C)<Math.abs(.5*w*L)&&C>w*(c-u)&&C<w*(l-u)){x=C/w;let E=u+x;(E-c<2*i||l-E<2*i)&&(x=M>=u?i:-i),A=!1}}A&&(y=u>=M?c-u:l-u,x=tM*y);let F=Math.abs(x)>=i?u+x:u+(x>=0?i:-i),T=g(F),P=-Math.abs(T.ay);P<=m?(F>=u?c=u:l=u,h=d,f=p,d=u,p=m,u=F,m=P,b=T):(F<u?c=F:l=F,P<=p||d===u?(h=d,f=p,d=F,p=P):(P<=f||h===u||h===d)&&(h=F,f=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 VI=.001,BI=.01,tM=(3-Math.sqrt(5))/2;function Wk(e,t,r,n,o,a){let s=l=>Math.abs(fn(e,t,r,n*l,void 0,a).ay),i=0,c=qa;if(s(c)<o)return fn(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 fn(e,t,r,n*.5*(i+c),void 0,a)}function Eb(e,t,r,n,o){let a=Hn(e,t,r,n,o);return a.steering?Math.abs(a.steering.totalNm):NaN}function Ib(e,t,r,n,o){if(!bo(e))return NaN;let a=n<0?-1:1,s=Math.abs(n),i=Hn(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,d=fn(e,t,r,a*u,void 0,o),p=fn(e,t,r,a*m,void 0,o),h=d.steering?Math.abs(d.steering.totalNm):NaN,f=p.steering?Math.abs(p.steering.totalNm):NaN,b=Math.abs(p.ay)-Math.abs(d.ay);if(Number.isFinite(h)&&Number.isFinite(f)&&b>=.01||l===.4&&Number.isFinite(h)&&Number.isFinite(f)&&b>.001)return(f-h)/b}return NaN}function Cb(e,t,r,n,o,a){let s=Math.max(8,r),i=Zt(e,t,s,n*ue,o*ue,void 0,Za(e,a,s,t)),c=0;for(let l of br)c+=i.wheels[l].fxShort;return{ay:i.ay,cn:i.cn,fxShortfall:c}}function _b(e,t,r,n,o){let a=Math.max(8,r),s=Hn(e,t,a,n,o),i=.5,c=Cb(e,t,a,s.beta+i,s.steerDeg,o).cn,l=Cb(e,t,a,s.beta-i,s.steerDeg,o).cn;return(c-l)/(2*i*ue)*e.massTotal*De*(e.wheelbase/1e3)}function Nb(e,t,r,n){let o=Math.max(8,r),{branch:a,opts:s}=$I(e,t,o,n);return rM(e,t,o,a,s)}function $I(e,t,r,n){if(!e.tv?.enabled||n?.balance){let s=n?{op:n}:{};return{branch:Ao(e,t,r,s),opts:s}}let o=Tb(e,t,r),a={op:s=>{let i=Pb(e,r,s,o);return i===0?n:{axG:n?.axG??0,driveFrontFrac:n?.driveFrontFrac,tvRearDiffN:i}}};return{branch:Ao(e,t,r,a),opts:a}}function rM(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 Ki(e,t,r,n.peak,a);let i=(l,u)=>Mo(e,t,r,l,u,a(l),s),c=n.states[0].driving||!n.peak.driving?n.states:n.states.slice(1);return eM(c,i,c.indexOf(n.peak),n.foldDeg===null).state}function Ob(e,t,r,n={}){let o=n.radius!==void 0&&n.radius>0&&Number.isFinite(n.radius)?n.radius:void 0,a=o===void 0?Math.max(8,r):Math.max(8,Math.sqrt(De*o)),s=(n.betaMaxDeg??10)*ue,i=(n.deltaMaxDeg??10)*ue,[c,l]=n.betaRangeDeg?[n.betaRangeDeg[0]*ue,n.betaRangeDeg[1]*ue]:[-s,s],[u,m]=n.deltaRangeDeg?[n.deltaRangeDeg[0]*ue,n.deltaRangeDeg[1]*ue]:[-i,i],{lf:d,lr:p}=Fb(e),h=o===void 0?0:p/o,f=o===void 0?0:(d+p)/o,b=n.nLines??9,g=n.nPts??21,y=n.steering!==!1&&bo(e),x=y?Nn(Fe(t,"front").model):void 0,k=(B,V,j,q)=>j===1?B:B+(V-B)*q/(j-1),v=e.tv?.enabled?Tb(e,t,a):0,R=B=>{let V=Pb(e,a,B/ue,v);return!n.axG&&V===0?null:Za(e,{axG:n.axG??0,driveFrontFrac:n.driveFrontFrac,tvRearDiffN:V},a,t)},{lf:M,lr:A}=Fb(e),F=n.reserves?Qa(t,e.massTotal*De*1.2):null,T=B=>F?Jr(F,{FL:B.FL,FR:B.FR,RL:B.RL,RR:B.RR},{lf:M,lr:A}):null,P=[],S={ay:[],cn:[]},w=0;for(let B=0;B<b;B++){let V=k(u,m,b,B),j=R(V),q=[],K=[],D=[],N=[],Y=F?{stabil:[],agil:[]}:void 0,H=y?Bk():void 0,W;for(let Z=0;Z<g;Z++){let xe=k(c,l,g,Z),de=Zt(e,t,a,xe,V,W,j,o);if(W=Number.isFinite(de.ay)?de.ay*De:void 0,q.push(de.ay),K.push(de.cn),D.push(xe/ue),N.push(V/ue),Y){let be=T(de.wheels);Y.stabil.push(be.stabil),Y.agil.push(be.agil)}H&&$k(H,Vk(e,t,V,de.wheels)),Math.abs(de.ay)>w&&(w=Math.abs(de.ay))}P.push({label:`\u03B4 ${(V/ue).toFixed(0)}\xB0`,ay:q,cn:K,betaDeg:D,deltaDeg:N,reserve:Y,steering:H});let X=null,ne=1/0;for(let Z=1;Z<K.length;Z++){if(!Number.isFinite(K[Z-1])||!Number.isFinite(K[Z])||K[Z-1]!==0&&K[Z-1]<0==K[Z]<0)continue;let xe=K[Z-1]===K[Z]?0:K[Z-1]/(K[Z-1]-K[Z]),de=q[Z-1]+xe*(q[Z]-q[Z-1]);if(o===void 0&&V!==0&&Math.abs(de)>=.05&&Math.sign(de)!==Math.sign(V))continue;let be=Math.abs(D[Z-1]+xe*(D[Z]-D[Z-1])-h/ue);be<ne&&(ne=be,X=de)}X!==null&&(S.ay.push(X),S.cn.push(0))}let C=[];for(let B=0;B<b;B++){let V=k(c,l,b,B),j=[],q=[],K=[],D=[],N=F?{stabil:[],agil:[]}:void 0,Y=y?Bk():void 0,H;for(let W=0;W<g;W++){let X=k(u,m,g,W),ne=Zt(e,t,a,V,X,H,R(X),o);if(H=Number.isFinite(ne.ay)?ne.ay*De:void 0,j.push(ne.ay),q.push(ne.cn),K.push(V/ue),D.push(X/ue),N){let Z=T(ne.wheels);N.stabil.push(Z.stabil),N.agil.push(Z.agil)}Y&&$k(Y,Vk(e,t,X,ne.wheels))}C.push({label:`\u03B2 ${(V/ue).toFixed(0)}\xB0`,ay:j,cn:q,betaDeg:K,deltaDeg:D,reserve:N,steering:Y})}let L=.5*ue,E=R(f),_,O;if(o===void 0)_=(Zt(e,t,a,h+L,f,void 0,E,o).cn-Zt(e,t,a,h-L,f,void 0,E,o).cn)/(2*L),O=(Zt(e,t,a,h,f+L,void 0,R(f+L),o).cn-Zt(e,t,a,h,f-L,void 0,R(f-L),o).cn)/(2*L);else{let B=(q,K)=>Zt(e,t,a,q,K,void 0,R(K),o).cn,V=(q,K,D)=>Number.isFinite(q)?(-3*q+4*K-D)/(2*L):(D-K)/L,j=B(h,f);_=-V(j,B(h-L,f),B(h-2*L,f)),O=V(j,B(h,f+L),B(h,f+2*L))}let I=0;if(E&&E.axG){let B=Zt(e,t,a,h,f,void 0,E,o),V=0;for(let j of br)V+=B.wheels[j].fxShort;I=V/Math.abs(e.massTotal*E.axG*De)}let z=S.ay.reduce((B,V)=>Math.max(B,Math.abs(V)),0);return{isoBeta:C,isoDelta:P,trim:S,maxAy:w,stability:_,control:O,speed:o===void 0?a:Math.sqrt(z*De*o),...o!==void 0?{radius:o}:{},axG:E?.axG??0,axShortfall:I,...x?{steeringAligningSource:x}:{}}}function nM(e,t){return wo(e,t*ue).atLock}function GI(e,t,r,n,o=mn(e,t,r)){let a=r,s=e.massTotal,i=br.filter(g=>Qt(g)?n.drivenFront:n.drivenRear),c=o.peakAt,l={front:n.drivenFront?qt(e,"front",1):void 0,rear:n.drivenRear?qt(e,"rear",1):void 0},u=new Map,m=(g,y)=>{let x=`${g}:${y}`,k=u.get(x);if(k===void 0){let v=Math.max(1,y*Vi);k=jt(Fe(t,g),v,0,!1,c(g,v)),u.set(x,k)}return k},d=(g,y)=>y>0?Oi(y,x=>m(g,x)):0,p=(g,y,x,k)=>{let v=Fe(t,g),R=E=>{let _=Math.max(0,x[E]),O=c(g,_);return{Fz:_,a:d(g,_),b:O.fyPeak,slide:0,cap:I=>_>0?jt(v,_,I,!1,O):0}},[M,A]=g==="front"?["FL","FR"]:["RL","RR"],F=R(M),T=R(A),P=k[M]*F.b,S=k[A]*T.b,w=F.cap(P)+T.cap(S),C=Ni(F,T,P+S,y,w);return{l:M,r:A,full:C,asHeld:()=>({axle:g,strong:F.cap(P)>=T.cap(S)?M:A,full:C,open:Ni(F,T,P+S,Wa,w),sense:1})}},h=g=>({muX:y=>y>0?d(g,y)/y:0,muY:y=>y>0?c(g,y).fyPeak/y:0}),f={front:h("front"),rear:h("rear")},b=g=>({arms:{lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},halfTrack:{front:e.trackFront/2e3,rear:e.trackRear/2e3},ayDir:Math.sign(g)});return{limitAt:(g,y,x,k=0)=>{let v={FL:0,FR:0,RL:0,RR:0},R=$e(e,g,0,a,0,y),M,A=I=>(M?.ax!==I&&(M={ax:I,loads:$e(e,g,(I+k)/De,a,0,y)}),M.loads),F=Zl(I=>Ia(x,A(I),R,c).short,-k,1),T=x,P={FL:0,FR:0,RL:0,RR:0},S,w=I=>{let z=F.at(I);v=A(z),T=Ia(x,v,R,c).util;let B={FL:0,FR:0,RL:0,RR:0};P=B;let V=0,j=n.diffYaw?{fx:{FL:0,FR:0,RL:0,RR:0},axles:[]}:null;for(let q of i){let K=l[dn(q)];if(K){if(Gi(q)){let H=p(dn(q),K,v,T);V+=H.full,B[H.l]=B[H.r]=H.full/2,j&&(j.fx[H.l]=j.fx[H.r]=H.full/2,j.axles.push(H.asHeld()))}continue}let D=Math.max(0,v[q]),N=c(dn(q),D),Y=jt(Fe(t,dn(q)),D,T[q]*N.fyPeak,!1,N);V+=Y,B[q]=Y,j&&(j.fx[q]=Y)}if(j){let q={};for(let K of br){let D=Math.max(0,v[K]);q[K]={Fz:D,Fy:T[K]*c(dn(K),D).fyPeak,Fx:j.fx[K]}}for(let K of j.axles){let D=yu(K,q,f,b(g))-K.full;V+=D;let[N,Y]=K.axle==="front"?["FL","FR"]:["RL","RR"];B[N]+=D/2,B[Y]+=D/2}}if(S)for(let q of S){let K=0;for(let D of q.wheels)K+=B[D];K>q.cap&&(V-=K-q.cap)}return V/s},C=()=>{let I=xk(w,-k,$n).fx,z=F.edge();return z!==void 0&&I>z&&(I=z,w(I)),{ax:I,loads:v,wheels:P}},L=C(),E=n.motorCaps;if(!E)return L;if(!E.some(I=>I.wheels.reduce((z,B)=>z+L.wheels[B],0)>I.cap))return{...L,held:L.ax};S=E;let O=C();return{...L,held:O.ax,heldWheels:O.wheels}}}}var Yu=.05,jk=.001,Uk=16,qu=8;function Vb(e,t,r,n){let o=Math.max(qu,r),a=n.nSteer??7,s=e.tv?.enabled?Tb(e,t,o,n.steerMaxDeg):0,i=D=>{let N=Pb(e,o,D,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=Ao(e,t,o,l),m=D=>{let N={},Y={};for(let H of br)N[H]=D.wheels[H].slipDeg*ue,Y[H]=Math.min(1,D.wheels[H].gripUtil);return{steerDeg:D.steerDeg,ayMs:Math.max(0,D.ay*De),ayG:D.ay,slip:N,util:Y,scrub:D.ay>0?KI(D,e.massTotal):0}},d=null,p=D=>{if(d&&D===d.steerDeg)return m(d);let N=II(e,t,o,u,D,l);if(N)return m(N);let Y=u.states[0];for(let H of u.states)H.steerDeg<=D&&(Y=H);return m(Y)},h=u.peak.driving&&u.peak.ay>0?rM(e,t,o,u,l):null,f=h?Math.max(0,h.ay*De):0,b=h?[...u.states.filter(D=>D.steerDeg<h.steerDeg),h]:u.states,g=h?b.findIndex(D=>D.ay*De>=.995*f):0,y=b[g].steerDeg,{fold:x}=u;if(h&&x&&u.peak===x.state){let D=.995*f/De,N=u.states.indexOf(x.stall),Y=N-1;for(;Y>0&&u.states[Y].beta===x.stall.beta;)Y--;let H=Math.sign(x.stall.beta-u.states[Y].beta),W=N;for(;W>0&&u.states[W].ay>=D&&Math.sign(u.states[W].beta-u.states[W-1].beta)!==-H;)W--;u.states[W].ay<D&&(d=Db(e,t,o,x,l,{ayG:D},u.states.slice(W,N+1)))}if(d)y=d.steerDeg;else if(g>0){let D=b[g-1].steerDeg,N=y;for(let Y=0;Y<8&&N-D>.001;Y++){let H=.5*(D+N);p(H).ayMs>=.995*f?N=H:D=H}y=N}let k=[];for(let D=0;D<(f>0?a:1);D++){let N=D/(a-1);k.push(p(y*(N+Math.sin(Math.PI/2*N))/2))}k[0].ayMs=0;let v=[],R=[],M=[],A=[],F=[],T=mn(e,t,o,void 0,n.diffYaw===!0),P=GI(e,t,o,n,T),S=n.axDrag??0,w=D=>{let N=T.limitAt(D.ayMs/De,D.steerDeg,D.util,S+D.scrub);return{axD:N.edge!==void 0&&N.edge>0?N.edge:N.ax,locked:N.axUnlocked-N.ax>Yu}},C=D=>{let N=P.limitAt(D.ayMs/De,D.steerDeg,D.util,S+D.scrub);return{axA:N.ax,wA:{wheels:N.wheels,held:N.held??N.ax,...N.heldWheels?{heldWheels:N.heldWheels}:{}}}},L=k.map(D=>({p:D,...C(D),...w(D)})),E=[];for(let D=0;D+1<L.length;D++){let N=L[D],Y=L[D+1],H=[];N.locked!==Y.locked?H.push({read:w,past:W=>W.locked===Y.locked,braking:!0}):(Y.axA>N.axA+Yu&&H.push({read:C,past:W=>(W.axA??-1/0)>N.axA}),-Y.axD>-N.axD+Yu&&H.push({read:w,past:W=>-(W.axD??0)>-N.axD}));for(let{read:W,past:X,braking:ne}of H){let Z=N.p.steerDeg,xe=Y.p.steerDeg,de=null,be=N.axD,U=Y.axD;for(let ee=0;ee<Uk&&xe-Z>jk&&!(ne&&Math.abs(U-be)<=Yu);ee++){let se=.5*(Z+xe),ie=p(se),Re=W(ie);X(Re)?(xe=se,de={p:ie,r:Re},U=Re.axD??U):(Z=se,be=Re.axD??be)}if(de){let{p:ee,r:se}=de,ie=se.axD!==void 0&&se.locked!==void 0?{axD:se.axD,locked:se.locked}:w(ee),Re=se.axA!==void 0&&se.wA!==void 0?{axA:se.axA,wA:se.wA}:C(ee);E.push({p:ee,...Re,...ie})}}}L.push(...E),L.sort((D,N)=>D.p.steerDeg-N.p.steerDeg);let _=D=>D.axA+S+D.p.scrub,O=.001*Math.max(1,k[k.length-1].ayMs),I=[];for(let D=0;D+1<L.length;D++){let N=L[D],Y=L[D+1];if(!(_(N)>=0&&_(Y)<0))continue;let H=N.p.steerDeg,W=Y.p.steerDeg,X=null,ne=null;for(let de=0;de<Uk&&W-H>jk;de++){let be=.5*(H+W),U=p(be),ee=C(U);_({p:U,axA:ee.axA})>=0?(H=be,X={p:U,wA:ee.wA}):(W=be,ne={p:U,wA:ee.wA})}let Z=X??ne,xe=Z?.p;if(Z&&xe&&xe.ayMs>N.p.ayMs&&xe.ayMs<Y.p.ayMs){let de=-(S+xe.scrub);I.push({p:xe,axA:de,wA:{wheels:Z.wA.wheels,held:Math.min(Z.wA.held,de)},steady:!0,...w(xe)})}}L.push(...I),L.sort((D,N)=>D.p.steerDeg-N.p.steerDeg);let z=!1;for(let{p:D,axA:N,wA:Y,axD:H,steady:W}of L){let X=v.length-1,ne=X>=0&&(W||z?!(D.ayMs>v[X]):D.ayMs-v[X]<O);z=W===!0&&!ne,ne?(N>R[X]&&(M[X]=Y),R[X]=Math.max(R[X],N),A[X]=Math.min(A[X],H)):(v.push(D.ayMs),R.push(N),M.push(Y),A.push(H),F.push(D.scrub))}for(let D=v.length-2;D>=0;D--)R[D+1]>R[D]&&(M[D]=M[D+1]),R[D]=Math.max(R[D],R[D+1]),A[D]=Math.min(A[D],A[D+1]);let B=v[v.length-1],V=e.massTotal,j=M.map(({wheels:D})=>({FL:D.FL/V,FR:D.FR/V,RL:D.RL/V,RR:D.RR/V})),q=D=>D?{FL:D.FL/V,FR:D.FR/V,RL:D.RL/V,RR:D.RR/V}:void 0,K=n.motorCaps?{axAccelHeld:M.map(D=>D.held),axAccelWheelsHeld:M.map(D=>q(D.heldWheels))}:{};return{ayMax:B,ay:v,axAccel:R,axAccelWheels:j,...K,axDecel:A,axScrub:F,rollover:u.rollover,atLock:h!==null&&nM(e,h.steerDeg)}}function KI(e,t){let r=e.beta*ue,n=0;for(let o of br){let a=e.wheels[o],s=a.steerDeg*ue-r;n+=a.Fx*(Math.cos(s)-1)-a.Fy*Math.sin(s)}return n/t}var MX=Math.PI/180,SX={speeds:Array.from({length:23},(e,t)=>8+t),steerMaxDeg:14,steerSteps:29};function aM(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 Ja={enabled:!1,kp:3e3,ffLow:150,ffHigh:300,vLow:18,vHigh:25},oM=e=>aM(e.ffLow,e.ffHigh,e.vLow,e.vHigh);var Er={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"}},HI=["k_yaw","k_roll","k_pitch"];function zi(e){for(let t of HI)delete e[t];for(let t of Object.keys(Er)){let r=e[t];if(!r){e[t]={...Er[t]};continue}e[t]={...r,label:Er[t].label,unit:Er[t].unit}}return e}function re(e,t){return e[t]?.value??Er[t].value}function Qu(e){let t=(r,n)=>e[r]?.value??n;return{enabled:t("tv_enabled",0)>=.5,kp:t("tv_kp",Ja.kp),ffLow:t("tv_ff_low",Ja.ffLow),ffHigh:t("tv_ff_high",Ja.ffHigh),vLow:t("tv_v_low",Ja.vLow),vHigh:t("tv_v_high",Ja.vHigh)}}var sM=[10,25,50,100,200,300];function Bb(e,t,r,n,o){let s=sM.map(i=>Math.round(i<=25?r*i:r*25+n*(i-25)));return{id:e,label:t,speedMmS:[...sM],reboundN:s,bumpN:s.map(i=>Math.round(i*o))}}var Zu={name:"Generic FS damper",curves:[Bb("c1","Soft",1.6,1,.65),Bb("c2","Medium",3,1.6,.65),Bb("c3","Firm",8,2.4,.65)]};function Ju(e){let t=e.curves.length;return t>0?e.curves[Math.floor((t-1)/2)].id:""}var zn=25;function es(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 iM(e,t){return t>=0?es(e.rebound,t):-es(e.bump,-t)}function cM(e,t,r){return t*iM(e,t*r)}var $b=(e,t)=>e.curves.find(r=>r.id===t);function Yi(e,t){let r=$b(e,Ju(e)),n=(t&&$b(e,t.bump))??r,o=(t&&$b(e,t.rebound))??r;return{bump:{speedMmS:n?.speedMmS??[],forceN:n?.bumpN??[]},rebound:{speedMmS:o?.speedMmS??[],forceN:o?.reboundN??[]}}}var em=5e3;function Wi(e,t){let r=t>0?t:1,n=[],o=[],a=e.bump.speedMmS.map(c=>c/r).filter(c=>c<em),s=e.rebound.speedMmS.map(c=>c/r).filter(c=>c<em),i=c=>{n.push(c),o.push(cM(e,r,c))};i(-em);for(let c=a.length-1;c>=0;c--)i(-a[c]);i(0);for(let c of s)i(c);return i(em),{kind:"map",input:"velocity",x:n,y:o}}var Gb=64;function ji(e,t,r){let n=t>0?t:1,o=Math.max(r,1e-6),a=0;for(let s=0;s<Gb;s++){let i=Math.sin((s+.5)*Math.PI/Gb),c=n*o*i;a+=n*(es(e.rebound,c)+es(e.bump,c))*i}return a*(Math.PI/Gb)/(Math.PI*o)}function Fo(e,t,r,n,o=e){let a=(c,l,u)=>{if(!c||c.curves.length===0)return;let m=Yi(c,l);return{law:m,curve:Wi(m,u),rate:ji(m,u,zn)}},s=a(e,t?.front,r),i=a(o??e,t?.rear,n);return!s&&!i?null:{...s?{front:s}:{},...i?{rear:i}:{}}}var lM=(e,t)=>({...e,y:e.y.map(r=>r*t)}),zI=e=>({...e,x:e.x.map(t=>-t).reverse(),y:e.y.map(t=>-t).reverse()});function Kb(e,t,r){let n=Math.abs(r)>0?Math.abs(r):1,o=Yi(e,t);return{law:o,curve:lM(Wi(o,n),.5),rate:ji(o,n,zn)/2,mr:n,ratio:n,share:.5}}function Hb(e,t,r,n,o){let a=n*(Math.abs(r)>0?Math.abs(r):1),s=Yi(e,t),i=lM(Wi(s,a),1/n);return{law:s,curve:o?zI(i):i,rate:ji(s,a,zn)/n,mr:a/n,ratio:a,share:1/n}}function Ui(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 tm=["front","rear","heaveFront","heaveRear","rollFront","rollRear"];function Xi(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 hn(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 Qi(e){return e.kind==="coil"?2:1}function qi(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 mM(e){return qi(e)/2}function pM(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 uM(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 YI(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 Zi(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*qi(e.section)/e.barLength,a=2*o/(n*n),s=mM(e.armSection??e.section),i=3*e.E*s/n**3,c=e.dropLinkRate??1/0;return{rateAtLink:uM([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*qi(e.section)/e.barLength,a=2*o/(n*n),s=3*e.E*pM(e.blade)/n**3,i=e.dropLinkRate??1/0;return{rateAtLink:uM([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*qi(e.section)/e.length,a=2*o/(n*n);return{rateAtLink:a,contributions:{barTwist:a},torsional:o}}case"coil":{let n=hn(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=YI(e.linkTravel,e.force,t);return{rateAtLink:Math.max(0,n),contributions:{},torsional:0}}}}function rm(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?Ff(t,r):1,o=t?Cf(t,r):0,a=Zi(e,o).rateAtLink;return{wheelRate:Math.max(0,a*n*n),motionRatio:n,rateAtLink:a}}function Ji(e,t){let r=e.damper??0;return!r||e.design.kind==="none"?0:Qi(e.design)*r*t*t}var WI=150;function jI(e){return J(e,[0,-.5,1])<-1e-9?Q(e,-1):e}function dM(e){let t=e.hardpoints,r=G(t.rockerPivotB,t.rockerPivotA),n=oe(t.rockerPivotA,Q(G(t.rockerToDamper,t.rockerPivotA),.6)),o=jI(te(le(r,G(t.rockerToDamper,t.rockerPivotA))));return{outer:n,inner:oe(n,Q(o,WI)),attach:"rocker"}}function Jt(e,t){let r={};for(let o of wr)r[o]=gt(Qe(e,o));let n={vehicle:e,ctx:r};return t&&(n.kc=Wl(n,t)),n}function UI(e,t,r,n){let o=e.corner.hardpoints,a=va(e.rocker,t.points.rockerAngle),s=i=>Wt(i,r);return{ucaFront:s(o.ucaFront),ucaRear:s(o.ucaRear),lcaFront:s(o.lcaFront),lcaRear:s(o.lcaRear),tieInner:s(io(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:qr(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 nm(e,t,r,n){let o=nt(t,e.vehicle.config),a=o.isFront?o.sideSign*n:0,s;try{s=Lt(we(e.ctx[t],r,a))}catch{return null}if(!s)return null;let i=Qe(e.vehicle,t).config.loadedRadius,c=UI(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 om=.5;function XI(e,t){let r=([i,c,l])=>{let u=te(G(c,i)),m=G(l,i),d=te(G(m,Q(u,J(m,u))));return[u,d,le(u,d)]},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=G(i,e[0]);return oe(t[0],[0,1,2].map(l=>a[l][0]*c[0]+a[l][1]*c[1]+a[l][2]*c[2]))}}}var fM=e=>[(e[2][1]-e[1][2])/2,(e[0][2]-e[2][0])/2,(e[1][0]-e[0][1])/2];function am(e,t,r){let n=nt(t,e.vehicle.config),o=e.ctx[t],a=r.rigid?void 0:{loadedRadius:r.loadedRadius},s=r.state?null:we(o,r.travel,r.steer,void 0,a),i=r.state??St(s),c=we(o,r.travel+om,r.steer,void 0,a),l=we(o,r.travel-om,r.steer,void 0,a),u=(s?s.ok:r.converged)&&c.ok&&l.ok,m=St(c),d=St(l),p=(T,P)=>Wt(T.points[P],n),h=o.inv.strut?"pushrodOuter":"uprightUpper",f=p(i,h),b=p(i,"uprightLower"),g=T=>{let P=G(b,f);return Math.hypot(...le(P,G(p(i,T),f)))/Math.hypot(...P)},y=g("tieOuter")>=g("wheelCenter")?"tieOuter":"wheelCenter",x=[f,b,p(i,y)],k=T=>XI(x,[p(T,h),p(T,"uprightLower"),p(T,y)]),v=k(m),R=k(d),M=fM(v.rot),A=fM(R.rot),F=[NaN,NaN,NaN];return{solved:u,state:i,at:T=>p(i,T),velocity:T=>u?Q(G(v.move(T),R.move(T)),1/(2*om)):F,omega:u?Q(G(M,A),1/(2*om)):F}}function zb(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 hM(e,t,r){let n=am(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 bM(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 gM(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 qI(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 QI=.1*Math.PI/180;function yM(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]))*QI<=o*n}function sm(e,t){return!e.valid||!e.cpLeft||!e.cpRight?!1:yM([e.lateral,e.height],e.cpLeft,e.cpRight,e.sinAngle,t)}function ec(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 ZI=1;function xM(e){let t=ec(e);if(!t||!e.cpLeft||!e.cpRight||Math.abs(t.left-t.right)>ZI)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 ts(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 Ir(e,t,r){let n=r==="front"?"FL":"RL",o=r==="front"?"FR":"RR",a=hM(e,n,t),s=hM(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=bM(a),c=bM(s),l=gM(a,i),u=gM(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 d=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,h=Math.hypot(d[0],d[1]),f=Math.hypot(p[0],p[1]),b=h>0&&f>0?Math.abs(d[0]*p[1]-d[1]*p[0])/(h*f):0,g=zb(a.cp,d,s.cp,p)??qI(a.cp,l,s.cp);if(!g)return{...m,sinAngle:b};let y=s.cp[0]-a.cp[0],x=s.cp[1]-a.cp[1],k=Math.hypot(y,x)||1,v=y/k,R=x/k,M=(a.cp[0]+s.cp[0])/2,A=(a.cp[1]+s.cp[1])/2,F=(g[0]-a.cp[0])*-R+(g[1]-a.cp[1])*v,T=(g[0]-M)*v+(g[1]-A)*R;return{lateral:g[0],height:g[1],heightAboveGround:F,lateralAlongGround:T,valid:!0,icLeft:i,icRight:c,lineLeft:l,lineRight:u,sinAngle:b,cpLeft:a.cp,cpRight:s.cp}}function bn(e,t){return{front:Ir(e,t,"front"),rear:Ir(e,t,"rear")}}function im(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 JI(e,t){return{camber:im(e.travel,e.camber,t),toe:im(e.travel,e.toe,t),motionRatio:im(e.travel,e.motionRatio,t),damperLen:e.damperLen?im(e.travel,e.damperLen,t):0}}var RM=e=>JI(e,0).motionRatio;function Yb(e,t){if(e.kind!=="coil")return null;let r=t??e.motionRatio,n=hn(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 cm(e,t){if(e.kind==="none")return 0;if(e.kind==="tabulated"){let n=a=>e2(e,a);return(n(.5)-n(-.5))/(2*.5)/2}if((e.gap??0)>0)return 0;let r=t??e.motionRatio;return hn(e.rate,0)*r*r/2}function tc(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 e2(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 vM=new WeakMap;function um(e,t){let r=vM.get(e);r||(r=new Map,vM.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=co(e,t);return r.set(n,a),a}var t2=32,rc=new Map,kM=new WeakMap,r2=1;function n2(e){let t=kM.get(e);return t===void 0&&(t=r2++,kM.set(e,t)),t}function jb(e,t){if(!t.linkage)return null;let r=_n(e,t.linkage,t.design.kind),n=`${n2(e)}|${r?"unit":"bar"}|${JSON.stringify(t.linkage)}`,o=rc.get(n);if(o)return o;let a=Fa(e,t.linkage,{kind:t.design.kind});return rc.size>=t2&&rc.delete(rc.keys().next().value),rc.set(n,a),a}function To(e,t,r=0){let n=(o,a)=>{if(!(!o||o.design.kind==="none"))return rm(o.design,jb(a,o),r).wheelRate};return{front:n(t.arbFrontDesign,e.front),rear:n(t.arbRearDesign,e.rear)}}function rs(e,t){let r=(n,o)=>{if(!n||n.design.kind==="none")return;let a=n.linkage?um(o,n.linkage).atDesign:void 0;return cm(n.design,a)};return{front:r(t.heaveFrontDesign,e.front),rear:r(t.heaveRearDesign,e.rear)}}function FM(e,t){let r=(a,s)=>{if(!a||a.design.kind!=="coil")return;let i=a.linkage?um(s,a.linkage).atDesign:void 0;return Yb(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 mm(e,t){let r=(o,a)=>o?tc(o,Ub(o,a)):0,n=(o,a)=>o?Ji(o,Xb(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 Ub=(e,t)=>e.linkage?um(t,e.linkage).atDesign:void 0,Xb=(e,t)=>rm(e.design,jb(t,e),0).motionRatio;function CM(e,t){let r=t.damperSetup,n=t.heaveDamperModel??t.damperModel,o=t.rollDamperModel??t.damperModel,a=(d,p,h)=>{if(!d||!n?.curves.length)return;let f=Ub(d,p);if(tc(d,f)>0)return Kb(n,r?.[h],f??(d.design.kind==="coil"?d.design.motionRatio:1))},s=(d,p,h)=>{if(!d||!o?.curves.length)return;let f=Xb(d,p);if(!(Ji(d,f)>0))return;let b=jb(p,d)!==null;return Hb(o,r?.[h],f,Qi(d.design),b&&f>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 pm(e,t){let r=t.heaveDamperModel??t.damperModel,n=t.rollDamperModel??t.damperModel,o=(i,c)=>Co(i)?{source:"none"}:Xi(i.config.coilover,c),a=(i,c)=>{if(!i)return{source:"none"};let l=tc(i,Ub(i,c))>0;return Xi(i.coilover,l?r:void 0)},s=(i,c)=>{if(!i||i.design.kind!=="coil")return{source:"none"};let l=Ji(i,Xb(i,c))>0;return Xi(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 Co=e=>e.config.actuation==="decoupled",Po="a decoupled axle damps in its heave and roll elements, set below";function PM(e,t,r={}){let n={...t},o=(m,d)=>{let p=n[m];p&&typeof p=="object"&&"value"in p&&(n[m]={...p,value:d})},{front:a,rear:s}=To(e,t);a!==void 0&&o("arb_front",a),s!==void 0&&o("arb_rear",s);for(let[m,d,p]of[[t.heaveFrontDesign,e.front,"heave_spring_front"],[t.heaveRearDesign,e.rear,"heave_spring_rear"]]){if(!m||m.design.kind==="none")continue;let h=m.linkage?um(d,m.linkage).atDesign:void 0;o(p,cm(m.design,h))}let i=a2(e,t,r),c=o2(e,i);n.kinFront=c.kinFront,n.kinRear=c.kinRear;let l=c2(e,i);n.steerFront=c.steerFront,Number.isFinite(l.ackermannPct)&&o("ackermann_pct",l.ackermannPct);let u=m=>Co(m)?0:m.measured?.springRate??m.config.springRate;o("spring_front",u(e.front)),o("spring_rear",u(e.rear));for(let[m,d]of[[e.front,"spring_front"],[e.rear,"spring_rear"]])Co(m)&&(n.readouts={...n.readouts,[d]:"a decoupled axle has no corner spring; its heave and roll elements carry the car"});for(let[m,d]of[[e.front,"damper_front"],[e.rear,"damper_rear"]])Co(m)&&(o(d,0),n.readouts={...n.readouts,[d]:Po});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 o2(e,t){return{kinFront:SM(e.front),kinRear:SM(e.rear),steerFront:e.front.measured?void 0:dm(e.front,t)}}var MM=new WeakMap;function SM(e){let t=MM.get(e);return t||MM.set(e,t=Va(e)),t}function a2(e,t,r={}){return s2(e,t,r.front,r.rear)}function s2(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 fm(a,r,n).front??o}var AM=new WeakMap;function dm(e,t=e.config.loadedRadius){let r=AM.get(e);r||(r=new Map,AM.set(e,r));let n=r.get(t);if(n)return n;let o=t===e.config.loadedRadius?void 0:{loadedRadius:t},a=jf(e,Bt(e.config),void 0,void 0,void 0,void 0,o);return r.size>=4&&r.clear(),r.set(t,a),a}var wM=new WeakMap;function i2(e){return ot(e,{travelMin:-1,travelMax:1,steps:3}).samples[1].metrics.motionRatio??1}var lm=e=>e.measured?RM(e.measured):i2(e);function c2(e,t=e.front.config.loadedRadius){let r=()=>e.front.measured?void 0:dm(e.front,t);return{...l2(e),get steerFront(){return r()},get ackermannPct(){let n=r();return n?Uf(n,Ot(e.front),e.config.wheelbase):Number.NaN}}}function l2(e){let t=wM.get(e);if(t)return t;let r=e.front.measured,n=e.rear.measured,a=!r||!n?bn(Jt(e),{heave:0,pitch:0,roll:0,steer:0}):null,s={wheelbase:e.config.wheelbase,trackFront:r?r.track:Ot(e.front),trackRear:n?n.track:Ot(e.rear),mrFront:lm(e.front),mrRear:lm(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:ts(a.front),rcGainRear:n||!a?0:ts(a.rear),rcFrontValid:r?!0:!!a?.front.valid,rcRearValid:n?!0:!!a?.rear.valid};return wM.set(e,s),s}var Gt={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}},EM=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),_r=(e,t,r,n=1/0)=>typeof e=="number"&&Number.isFinite(e)?Math.min(n,Math.max(r,e)):t;function Lo(e){if(EM(e))switch(e.kind){case"open":case"spool":return{kind:e.kind};case"clutch":{let t=Gt.clutch;return{kind:"clutch",preloadNm:_r(e.preloadNm,t.preloadNm,0),rampDriveDeg:_r(e.rampDriveDeg,t.rampDriveDeg,1,90),rampCoastDeg:_r(e.rampCoastDeg,t.rampCoastDeg,1,90),faces:Math.round(_r(e.faces,t.faces,0)),muClutch:_r(e.muClutch,t.muClutch,0,1),rFrictionMm:_r(e.rFrictionMm,t.rFrictionMm,1),rRampMm:_r(e.rRampMm,t.rRampMm,1)}}case"torsen":{let t=Gt.torsen,r=_r(e.preloadNm,0,0);return{kind:"torsen",tbrDrive:_r(e.tbrDrive,t.tbrDrive,1),tbrCoast:_r(e.tbrCoast,t.tbrCoast,1),...r>0?{preloadNm:r}:{}}}default:return}}function hm(e){if(!EM(e))return;let t=Lo(e.front),r=Lo(e.rear);return t||r?{...t?{front:t}:{},...r?{rear:r}:{}}:void 0}function Do(e){let t=hr(e),r=n=>n>=2?"independent":n===1?"diff":"none";return{front:r(t.front),rear:r(t.rear)}}function nc(e){if(!e.driveline)return;let t=Do(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:_i(i,"drive",r),coast:_i(i,"coast",r),hubs:_i(i,"hubs",r)}},o=n("front"),a=n("rear");return o||a?{...o?{front:o}:{},...a?{rear:a}:{}}:void 0}var u2={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"}},LM=e=>{let t=e==="front"?"Front":"Rear";return Object.fromEntries(Object.entries(u2).map(([r,n])=>[`${e}.${r}`,{section:t,...n}]))},bm={...LM("front"),...LM("rear")},DM=e=>e.motorModel?.kind==="ice"?e.motorPlacement==="front"?"front":"rear":null;function IM(e,t){let r=DM(t);if(!(!r||DM(e)===r||t.driveline?.[r]))return{...t.driveline,[r]:{...Gt.clutch}}}function cr(e,t,r,n){return e>0?!(r>0)||!Number.isFinite(r)?e:Math.max(1,e-t/r):n}function gm(e,t,r){let n=Math.max(0,Math.min(1,r)),o=cr(e.freeRadius,e.staticLoad,e.tyreRate,e.surveyed),a=cr(t.freeRadius,t.staticLoad,t.tyreRate,t.surveyed);return n*o+(1-n)*a}function ns(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 gn(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 oc(e,t){if(!e)return p2(t);let r=t-On(e,0).camber;return r?{...e,camber:e.camber.map(n=>n+r)}:e}function m2(e){return{kinFront:oc(e.kinFront,re(e,"camber_front_deg")),kinRear:oc(e.kinRear,re(e,"camber_rear_deg"))}}function p2(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 _M=9.81,NM=e=>e>1?e/100:e;function Eo(e,t,r){let n=t??e.tireModel??xi(),o=r??e.tireModelRear??n,a={grip:re(e,"grip_scale"),stiffness:re(e,"stiffness_scale")},s=Ru(n,a);return{front:s,rear:o===n?s:Ru(o,a)}}function Nr(e,t,r){let n=Eo(e,t,r),o=_e(n.front);return Dt(n.rear===n.front?o:lu(o,_e(n.rear)))}function qb(e,t,r){let n=NM(e.front_mass_diss.value),o=Eo(e,t,r),a=_e(o.front),s=o.rear===o.front?a:_e(o.rear),i=t??e.tireModel,c=r??e.tireModelRear??i,l=e.m.value*_M*n/2,u=e.m.value*_M*(1-n)/2,m=(i?a.verticalStiffness():0)||re(e,"tire_vertical_rate"),d=(c?s.verticalStiffness():0)||re(e,"tire_vertical_rate"),p=Pr(i)??0,h=Pr(c)??0,f=e.surveyedRadiusFront&&e.surveyedRadiusRear?gm({freeRadius:p,staticLoad:l,tyreRate:m,surveyed:e.surveyedRadiusFront},{freeRadius:h,staticLoad:u,tyreRate:d,surveyed:e.surveyedRadiusRear},n):void 0,b=e.surveyedRadiusFront?cr(p,l,m,e.surveyedRadiusFront):void 0,g=e.surveyedRadiusRear?cr(h,u,d,e.surveyedRadiusRear):void 0;return{ev:a,evR:s,Wf:l,Wr:u,tireRate:m,tireRateRear:d,tyreFreeRadius:p,tyreFreeRadiusRear:h,cgStandingRadius:f,standingFront:b,standingRear:g}}function fm(e,t,r){let n=qb(e,t,r);return{front:n.standingFront,rear:n.standingRear}}function OM(e,t,r){return qb(e,t,r).cgStandingRadius}function It(e,t,r){let n=NM(e.front_mass_diss.value),o=re(e,"mr_front")||1,a=re(e,"mr_rear")||1,{ev:s,evR:i,Wf:c,Wr:l,tireRate:u,tireRateRear:m,tyreFreeRadius:d,tyreFreeRadiusRear:p,cgStandingRadius:h,standingFront:f,standingRear:b}=qb(e,t,r),g=Ei(e),y=nc(e),x=Fo(e.damperModel,e.damperSetup,o,a,e.damperModelRear??e.damperModel),k=e.readouts?.damper_front===Po,v=e.readouts?.damper_rear===Po,R={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,re(e,"cop_long"))),copHeight:re(e,"cop_height"),...e.aeroModel?{model:e.aeroModel}:{},rideHeightFront:re(e,"ride_height_front"),rideHeightRear:re(e,"ride_height_rear")};return{massTotal:e.m.value,frontMassFrac:n,steeringSystem:e.steeringSystem,tv:Qu(e),cgHeight:ns(re(e,"cg_height"),e.cgReference?.standingRadius,h),...h!==void 0?{cgStandingRadius:h}:{},wheelbase:re(e,"wheelbase"),trackFront:re(e,"track_front"),trackRear:re(e,"track_rear"),wheelRateFront:re(e,"spring_front")*o*o,wheelRateRear:re(e,"spring_rear")*a*a,tireRate:u,...m!==u?{tireRateRear:m}:{},tireDamping:re(e,"tire_vertical_damping"),arbFront:re(e,"arb_front"),arbRear:re(e,"arb_rear"),brakeBalanceFront:g.balanceFront,brakes:g,...y?{driveline:y}:{},heaveSpringFront:re(e,"heave_spring_front"),heaveSpringRear:re(e,"heave_spring_rear"),unsprungPerCorner:re(e,"unsprung_mass"),unsprungCgHeight:d2(e,{Wf:c,Wr:l,tireRate:u,tireRateRear:m,tyreFreeRadius:d,tyreFreeRadiusRear:p,standingFront:f,standingRear:b}),tyreFreeRadius:d,...p!==d?{tyreFreeRadiusRear:p}:{},rcHeightFront:gn(re(e,"rc_front"),e.rcRoad?.gainFront,e.rcRoad?.radiusFront,f),rcHeightRear:gn(re(e,"rc_rear"),e.rcRoad?.gainRear,e.rcRoad?.radiusRear,b),corneringStiffnessFront:s.corneringStiffness(c),corneringStiffnessRear:i.corneringStiffness(l),damperFront:x?.front&&!k?x.front.rate:re(e,"damper_front")*o*o,damperRear:x?.rear&&!v?x.rear.rate:re(e,"damper_rear")*a*a,...x?.front&&!k?{damperCurveFront:x.front.curve}:{},...x?.rear&&!v?{damperCurveRear:x.rear.curve}:{},aero:R,ackermannPct:re(e,"ackermann_pct"),toeFrontDeg:re(e,"toe_front_deg"),toeRearDeg:re(e,"toe_rear_deg"),yawInertia:re(e,"I_yaw"),steerFront:e.steerFront,...m2(e)}}function d2(e,t){let r=(a,s,i,c)=>a??(s>0?cr(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 ym={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 VM(e,t=e.batteryModel){if(!t)return e;let r=jr(t),n=(o,a)=>({...o,value:a});return{...e,capacity:n(e.capacity,r.capacityAh),ocv:n(e.ocv,r.voltageAtFull)}}var $M={damper_front:`the damper part sets it: its front curve at ${zn} mm/s`,damper_rear:`the damper part sets it (the rear's own, where the car names one): its rear curve at ${zn} mm/s`};function xm(e){let t=!!(e.damperModelId||e.damperModel),r=t||!!(e.damperModelIdRear||e.damperModelRear);return{...t?{damper_front:$M.damper_front}:{},...r?{damper_rear:$M.damper_rear}:{}}}function GM(e,t=e.damperModel,r=e.damperModelRear??t){if(!t&&!r)return e;let n=re(e,"mr_front")||1,o=re(e,"mr_rear")||1,a=Fo(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!==Po&&(i.damper_front=s(e.damper_front,"damper front",a.front.rate/(n*n))),a.rear&&e.readouts?.damper_rear!==Po&&(i.damper_rear=s(e.damper_rear,"damper rear",a.rear.rate/(o*o))),i}var KM={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 yn(e){return!!e&&typeof e=="object"&&"value"in e&&"label"in e}var g2={Batteriekapazit\u00E4t:"pack capacity",Rollwiderstandsbeiwert:"rolling-resistance coefficient"},zM=e=>g2[e]??e;function Rm(e){let t=[];for(let r of Object.keys(e)){if(r==="motor"||r==="name")continue;let n=e[r];yn(n)&&t.push({key:r,label:zM(n.label),value:n.value,unit:n.unit})}return t}var y2=[{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"]}],x2=.5,HM=e=>e==="infinite"?1/0:typeof e=="number"?e:null,R2=e=>/front/.test(e)?e.replace("front","rear"):/rear/.test(e)?e.replace("rear","front"):null,nQ=(()=>{let e=KM.rows,t=o=>{let a=R2(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>=x2&&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 Qb={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 YM(e){let t=new Map;for(let a of Rm(e))t.set(a.key,a);let r=new Set,n=[];for(let a of y2){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=Rm(e).filter(a=>!r.has(a.key));return o.length&&n.push({title:"Other",rows:o}),n}var Zb={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"},Jb={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"},WM=e=>!!(e.aeroModelId||e.aeroModel);function v2(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 k2=e=>!!(e.batteryModelId||e.batteryModel),jM={capacity:"an engine car has no pack",ocv:"an engine car has no pack",soc:"an engine car has no pack",power_limit_kw:"an engine car has no pack, and the power rule is the electric class\u2019s",endurance_reserve:"an engine car has no pack to finish with a reserve of",I_rotor:"the engine model refers its own crank through each gear"},oQ=Object.keys(jM);function eg(e){if(!(e.motorModelId||e.motorModel))return{};let t=pt(e.motorModel),r={effi_pgb:"the motor model states its own efficiency",...t?jM:{}};return(e.motorCount!=null||t)&&(r.driven_wheels="the motor layout in Powertrain sets which wheels are driven"),r}function M2(e,t){let r={};return t.geometry&&Object.assign(r,Qb,v2(e)),WM(e)&&Object.assign(r,Zb),k2(e)&&Object.assign(r,ym),Object.assign(r,eg(e)),Object.assign(r,xm(e)),Object.assign(r,Iu(e)),e.readouts&&Object.assign(r,e.readouts),r}function UM(e,t){let r=M2(e,t);return WM(e)||Object.assign(r,Jb),r}function tg(e){let t=e.cop_long;return yn(t)?1-t.value:.5}function S2(e,t){let r=e.front_aero_diss,n=e.cop_long;!yn(r)||!yn(n)||(t===r.label?n.value=1-r.value:t===n.label&&(r.value=1-n.value))}function A2(e,t){S2(e,t);let r=e.c_l,n=e.c_w,o=e.l_to_d_ratio;!yn(r)||!yn(n)||(t===r.label||t===n.label?yn(o)&&n.value!==0&&(o.value=r.value/n.value):yn(o)&&t===o.label&&o.value!==0&&(n.value=r.value/o.value))}function vm(e,t,r){let n=!1;for(let o of Object.keys(e)){if(o==="motor"||o==="name")continue;let a=e[o];if(yn(a)&&zM(a.label)===t){a.value=r,n=!0;break}}return n&&A2(e,t),n}function km(e,t,r=0,n,o){let a=()=>({cl:e.c_l.value,cw:e.c_w.value,frontShare:tg(e),A:e.A.value,platform:null});if(!e.aeroModel)return a();let s=Xr(n??It(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:tg(e),A:s.area,platform:s}}var XM=e=>typeof e=="object"&&e!==null&&typeof e.value=="number"&&typeof e.label=="string";function qM(e,t=e.aeroModel){if(!t)return e;let r=Tn(t,{wheelbase:re(e,"wheelbase")}).at(re(e,"ride_height_front"),re(e,"ride_height_rear")),{cl:n,balanceFront:o}=Ud(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(XM(e.cop_long)?e.cop_long:void 0,Er.cop_long,1-o)};return XM(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 ac={dsTarget:.25,accelStep:.25,vTol:.002,scanSteps:24,seamIters:8,fitSpacing:1},w2=32;function QM(e,t,r){let n=Math.round(e/t);return Math.max(1,Math.min(Number.isFinite(n)?n:1,Math.floor(r/w2)||1))}function At(e){let t=ac,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 ZM=Math.PI/180,Mm=.02,JM=new WeakMap;function sc(e){let t=JM.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)*ZM,l=(e.bank?.[i]??0)*ZM,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 JM.set(e,s),s}function Sm(e,t,r){return e.n0[t]+e.k[t]*r*r}function eS(e,t){return e.k[t]<0?Math.sqrt(Math.max(0,e.n0[t])/-e.k[t]):1/0}function tS(e,t){if(!e)return null;let r=1/0,n=-1/0;for(let o=0;o<e.n0.length;o++){let a=Sm(e,o,t[o]??0);a<r&&(r=a),a>n&&(n=a)}return r>=1-Mm&&n<=1+Mm?null:{lo:r,hi:n}}var os=[.1,.25,.5,.75,1,1.25,1.5,2,2.5];function rS(e){let t=e.lo>=1-Mm?1:1-1.25*(1-e.lo)-.05,r=e.hi<=1+Mm?1:1+1.25*(e.hi-1)+.05,n=[...os].reverse().find(a=>a<=t)??os[0],o=os.find(a=>a>=r)??os[os.length-1];return os.filter(a=>a>=n&&a<=o)}function rg(e,t,r){return r<1?Math.max(e,t):Math.min(e,t)}function nS(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,d,p=1,h=1)=>s.axAccel(m,d,p,h)+t.axAccel(u(m),m,d,p,h)-r.axAccel(m,d,p,h),axDecel:(m,d,p=1,h=1)=>{let f=b=>s.axDecel(m,d,p,b)+t.axDecel(u(m),m,d,p,b)-r.axDecel(m,d,p,b);return h===1?f(1):rg(f(h),f(1),h)},ay:(m,d,p=1)=>Math.max(0,s.ay(m,d,p)+t.ay(u(m),m,d,p)-r.ay(m,d,p)),scrub:(m,d,p=1)=>(s.scrub?.(m,d,p)??0)+t.scrub(u(m),m,d,p)-(r.scrub?.(m,d,p)??0)}:{vMax:s.vMax,axAccel:(m,d,p=1,h=1)=>t.axAccel(u(m),m,d,p,h),axDecel:(m,d,p=1,h=1)=>t.axDecel(u(m),m,d,p,h),ay:(m,d,p=1)=>t.ay(u(m),m,d,p),scrub:(m,d,p=1)=>t.scrub(u(m),m,d,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}=F2(e,t,r),u=new Array(a),m=new Array(a),d=new Array(a),p=new Array(a).fill(0),h=0,f=0,b=0,g=Math.max(0,Math.min(1,n.kept)),y=g>=1?0:n.up,x=g>=1?0:n.down,k=4*y*(1-g),v=A=>{let{v:F,gear:T,tau:P,target:S}=A;h=0,f=0,b=0;for(let w=0;w<s;w++){let C=i(w),L=e[C];for(let O=0;P<=0&&O<n.count;O++){let I=T;if(F<L-1e-9?n.best(F)>T&&(n.rpm(F,T)>=n.limitRpm||c[w]>=F*k)?I=T+1:T>0&&F<n.vIdle(T)&&(I=T-1):L<F-1e-9&&T>0&&n.best(l[w])<T&&n.rpm(F,T-1)<=n.limitRpm&&(I=T-1),I===T)break;S=I,I>T?h++:f++,P=I>T?y:x,P<=0&&(T=S)}u[w]=F,m[w]=T+1,d[w]=n.rpm(F,T);let E=P>0;p[w]=E?1:0;let _=L;if(!E)F<L&&(_=Math.min(L,Math.sqrt(Math.max(0,F*F+2*o(w,F,n.share(F,T))*t[w]))));else if(F<L){let O=o(w,F,g>0?g*n.share(F,T):0),I=Math.min(L,Math.sqrt(Math.max(0,F*F+2*O*t[w]))),z=F+I>0?2*t[w]/(F+I):1/0;if(z<=P)_=I,b+=z,P-=z;else{let B=Math.min(L,Math.max(0,F+O*P)),V=Math.max(0,t[w]-(F+B)*.5*P);b+=P,P=0,T=S,_=Math.min(L,Math.sqrt(Math.max(0,B*B+2*o(w,B,n.share(B,T))*V)))}}else{let O=F+_>0?2*t[w]/(F+_):0;b+=Math.min(O,P),P-=O,P<=0&&(T=S)}F=_}return{v:F,gear:T,tau:P,target:S}},R=n.best(e[0]),M={v:e[0],gear:R,tau:0,target:R};if(r)for(let A=0;A<6;A++){let F=v(M),T=Math.abs(F.v-M.v)<=1e-9&&F.gear===M.gear&&F.target===M.target&&Math.abs(F.tau-M.tau)<=1e-12;if(M=F,T)break}else{let A=v(M);u[a-1]=A.v,m[a-1]=A.gear+1,d[a-1]=n.rpm(A.v,A.gear),p[a-1]=A.tau>0?1:0}return{v:u,gear:m,rpm:d,shifting:p,upshifts:h,downshifts:f,gapTime:b}}function F2(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,d=e[m]<e[u]-1e-9;s=d?0:s+t[u],i=d?Math.min(i,e[m]):e[u],l<n&&(o[u]=s,a[u]=i)}return{brakeAhead:o,apexAhead:a}}var ng=.001,og=9.81,ic=(e,t)=>wm(e?.gradient?.[t]??0);function wm(e){return e===0?0:-og*Math.sin(e*Math.PI/180)}function as(e,t){let r=new Array(t);for(let n=0;n<t;n++)r[n]=wm(e?.[n]??0);return r}function Fm(e,t){let r=e?.[t];return r!=null&&r>0?r:1}var Yn=(e,t)=>Fm(e?.mu,t),Io=(e,t)=>e?.bank?.[t]??0;function C2(e,t,r,n,o,a){let s=e.ay(t,r,Yn(o,a)),i=Io(o,a);if(!i)return s;let c=i*Math.PI/180,l=n===0?0:-Math.sign(n)*og*Math.sin(c);return Math.max(0,(s+l)/Math.cos(c))}function at(e,t){if(!t)return e;let r=t*Math.PI/180;return e*Math.cos(r)+og*Math.sin(r)}function ag(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 _o=(e,t,r)=>t?t(r):e,T2=1e-4;function ss(e,t,r,n,o,a,s){let i=At(r),c=[];for(let l=0;l<t.length;l++){let u=t[l],m=Math.abs(u),d=_o(e,o,l),p=a!==void 0&&a>0?Math.min(d.vMax,a):d.vMax,h=s?Math.min(p,s(l)):p,f=m<=0?h:ag(b=>b*b*m-C2(d,b,0,u,n,l),ng,h,i.scanSteps,Math.min(i.vTol,T2));c.push({v:f,ax:0,ay:f*f*u})}return c}function P2(e,t,r,n,o,a,s=1,i=0,c=0,l){if(r.v<=t.v)return 0;let u=p=>{let h=at(p*p*n,c),f=(l?e.axDecel(p,Math.abs(h),s,l(p)):e.axDecel(p,Math.abs(h),s))+i;return Math.sqrt(Math.max(0,p*p+2*f*o))},m=r.v;r.v=ag(p=>u(p)-t.v,ng,r.v,a.scanSteps,a.vTol),r.ay=r.v*r.v*n;let d=Math.abs(at(r.ay,c));return r.ax=(l?e.axDecel(r.v,d,s,l(r.v)):e.axDecel(r.v,d,s))+i,m-r.v}function L2(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(at(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 oS(e,t,r,n,o,a){let s=At(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 d=(m+1)%i;u=Math.max(u,P2(_o(e,o,m),t[d],t[m],r.curvature[m],r.ds[m],s,Yn(r,m),ic(r,m),Io(r,m),a?p=>a(m,p):void 0))}if(u<=s.vTol)break}return c}function aS(e,t,r,n,o,a){let s=At(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 d=(m+1)%i;u=Math.max(u,L2(_o(e,o,m),t[d],t[m],r.curvature[m],r.ds[m],Yn(r,m),ic(r,m),Io(r,m),a?a[m]:1))}if(u<=s.vTol)break}return c}function D2(e,t,r){let n=r.load?sc(t):null;if(!n||!r.load)return{pick:r.envelope};let o=t.npts;return{pick:nS(n,r.load,e,r.envelope),cap:a=>eS(n,a%o),n:(a,s)=>Sm(n,a,s)}}function sS(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 _o(e,t,i).axAccel(c,Math.abs(at(u,Io(r,i))),Yn(r,i),s?l*s[i]:l)+ic(r,i)})}function iS(e,t){return{gear:e.gear.slice(0,t),engineRpm:e.rpm.slice(0,t),shifting:e.shifting.slice(0,t)}}function cS(e,t,r,n){if(!e.scrub)return{};let o=!1,a=n.map((s,i)=>{let c=_o(e,t,i),l=at(s*s*r.curvature[i],Io(r,i)),u=c.scrub?c.scrub(s,Math.abs(l),Yn(r,i)):0;return u!==0&&(o=!0),u});return o?{axScrub:a}:{}}function Kt(e,t,r,n={}){let o=At(r),a=t.npts,s=t.closed&&!n.standingStart,{pick:i,cap:c,n:l}=D2(e,t,n),u=n.driveDerate,m=n.brakeFade;if(!s)return E2(e,t,o,n.standingStart===!0,i,u,n.vCeiling,m,c,l,n.shifts);let d=ss(e,t.curvature,o,t,i,n.vCeiling,c),p=oS(e,d,t,o,i,m),h=aS(e,d,t,o,i,u),f=n.shifts?sS(e,i,t,d.map(k=>k.v),!0,n.shifts,u):void 0;if(f)for(let k=0;k<a;k++)d[k].v=f.v[k];for(let k=0;k<a;k++){let v=d[k];v.ay=v.v*v.v*t.curvature[k];let R=d[(k+1)%a].v;v.ax=(R*R-v.v*v.v)/(2*t.ds[k])}let b=d.map(k=>k.v),g=d.map(k=>k.ax),y=d.map(k=>k.ay),x=0;for(let k=0;k<a;k++){let v=b[k]+b[(k+1)%a];v>0&&(x+=2*t.ds[k]/v)}return{states:d,v:b,ax:g,ay:y,laptime:x,sweeps:{backward:p,forward:h},...l?{loadFactor:b.map((k,v)=>l(v,k))}:{},...cS(e,i,t,b),...f?iS(f,a):{}}}function E2(e,t,r,n,o,a,s,i,c,l,u){let m=t.npts,d=t.closed?m:m-1,p=d+1,h=new Array(p);for(let x=0;x<p;x++)h[x]=t.curvature[x%m];let f=ss(e,h,r,t,o,s,c);n&&(f[0].v=0);for(let x=d-1;x>=0;x--){let k=f[x],v=f[x+1];if(k.v<=v.v)continue;let R=_o(e,o,x),M=F=>{let T=at(F*F*t.curvature[x],Io(t,x)),P=(i?R.axDecel(F,Math.abs(T),Yn(t,x),i(x,F)):R.axDecel(F,Math.abs(T),Yn(t,x)))+ic(t,x);return Math.sqrt(Math.max(0,F*F+2*P*t.ds[x]))},A=n&&x===0?k.v:ng;k.v=ag(F=>M(F)-v.v,A,k.v,r.scanSteps,r.vTol)}for(let x=0;x<d;x++){let k=f[x],v=f[x+1];k.ay=k.v*k.v*t.curvature[x];let R=at(k.ay,Io(t,x));k.ax=_o(e,o,x).axAccel(k.v,Math.abs(R),Yn(t,x),a?a[x]:1)+ic(t,x),v.v=Math.min(v.v,Math.sqrt(Math.max(0,k.v*k.v+2*k.ax*t.ds[x])))}let b=u?sS(e,o,t,f.map(x=>x.v),!1,u,a):void 0;if(b)for(let x=0;x<p;x++)f[x].v=b.v[x];let g=0;for(let x=0;x<d;x++){let k=f[x].v+f[x+1].v;k>0&&(g+=2*t.ds[x]/k)}let y=f.slice(0,m);for(let x=0;x<m;x++){let k=y[x];k.ay=k.v*k.v*t.curvature[x];let v=x<d?f[x+1].v:k.v;k.ax=t.ds[x]>0?(v*v-k.v*k.v)/(2*t.ds[x]):0}return{states:y,v:y.map(x=>x.v),ax:y.map(x=>x.ax),ay:y.map(x=>x.ay),laptime:g,sweeps:{backward:1,forward:1},...l?{loadFactor:y.map((x,k)=>l(k,x.v))}:{},...cS(e,o,t,y.map(x=>x.v)),...b?iS(b,m):{}}}var lS=(e,t)=>{let r=e[t]?.value;return Number.isFinite(r)&&r>0?r:0};function No(e,t,r){let n=e.m.value,o=e.r_dyn?.value??0,a=lS(e,"I_wheel"),s=e.motorModel?.kind==="ice"?0:lS(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,d=u*a/c,p=n+m+d;return{mass:n,driven:m,undriven:d,effective:p,powerFactor:n/p,tractionFactor:n/(n+d)}}function Oo(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 cc=36e5,dS=Math.PI*2,sg=e=>Math.max(0,Math.min(1,e));function ig(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=Sl(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/dS),l=Math.max(0,i*o/(n*a)),u=r.efficiency(c,l);return u>.01?u:.5}}var uS=new WeakMap;function is(e){if(e.batteryModel)return e.batteryModel;let t=e.capacity.value,r=e.ocv.value,n=uS.get(e);if(n&&n.capacityAh===t&&n.ocv===r)return n.model;let o=Od(t,r);return uS.set(e,{capacityAh:t,ocv:r,model:o}),o}function cg(e){let t=e.params,r=ub(t,_u(e));if(pt(t.motorModel)||Et(t).mode!=="hydraulic")return r;let n;return(o,a,s,i=0)=>{if(!(o>0))return 0;n??=I2(e);let c=Ku(n.inp,n.ev,o,a,i);return c?Math.min(o,c.regenFront+c.regenRear):r(o,a,s)}}var mS=new WeakMap;function I2(e){let t=e.params,r=mS.get(t);if(!r){let n=cn(t);r={inp:It(n.regen?t:{...t,energy:{...n,regen:!0}}),ev:Nr(t)},mS.set(t,r)}return r}var lc=e=>e.airTempC??Ut;function Cm(e,t){return e.thermal?e.thermal.startC??t:ha}function pS(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 fS=()=>({windingC:[],derate:[],lossW:[],torqueNm:[],ampsRms:[]});function _2(e){let t=e.motorModel;if(pt(t))return;let r=t?Sl(t).maxTorque:s=>Ue(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/dS),peak:r,torque:(s,i,c)=>{let l=Math.min(Math.abs(s)*o/(n*a),c*r(i));return s<0?-l:l}}}function N2(e,t){let r=e.motorModel?.thermal;if(!r||!t)return;let n=r.torqueConstant;return{...t,th:Vd(r),amps:o=>n>0?Math.abs(o)/n:0}}function O2(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),d=u?c/l:1,p=r*d;return{dq:m*p,lossJ:m*m*e.resistance(n,o)*p,energyJ:l*p,short:c>i,cutoff:u,seconds:p}}function V2(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 B2(e){let{drivenFront:t,drivenRear:r}=Oo(e);return No(e.params,t,r)}function cs(e,t,r,n,o=sn,a,s,i,c,l,u){let m=e.params,d=m.rho.value,p=m.fr_0.value,h=m.m.value,f=e.FG,b=m.aeroModel?It(m):void 0,g=ig(m),y=jr(is(m)),x=y.chargeC,k=m.motorModel?.kind==="ice",v=sg(a??(k?1:m.soc.value)),R=lc(m),M=s??Cm(y,R),A=M,F=0,T=0,P=0,S=0,w=-1,C=-1,L=-1,E=i||m.motorModel?.thermal?_2(m):void 0,_=N2(m,E),O=_?_.th.startC:0,I=O,z=0,B=1,V=-1,j=0,q=0,K=cg(e),D=u?.scrub,N=B2(e),Y=D?h/N.tractionFactor:0,H=N.effective-h,W=Math.min(t.length,r.length);for(let X=0;X<W;X++){let ne=r[X],Z=ne*ne,xe=n[X]-(c?.[X]??0),{cl:de,cw:be,A:U}=km(m,ne,xe/9.81,b),ee=.5*d*de*U*Z,se=.5*d*be*U*Z,ie=(f+ee)*-p,Re=D?-Y*(D[X]??0):0,pe=ie+se+Re+h*xe;H>0&&(pe+=H*n[X]);let ce=pe*t[X];l?.driveN?.push(pe>0?pe:0);let Pe=X+1<r.length?r[X+1]:ne,ke=.5*(ne+Pe),ae=ke>0?t[X]/ke:0,ge=0,fe=v,Ce=M,Ae=0,Ge=0,Ne=ae;if(k){pe>0&&(Ge=ce/g(ne,pe),F+=Ge/cc),l?.netKwh.push(F-T),l?.powerKw?.push(ae>0?Ge/ae/1e3:0);continue}if(pe>0){let Te=ce/g(ne,pe),ye=O2(y,Te,ae,v,M);ye.short&&w<0&&(w=X),ye.cutoff&&C<0&&(C=X);let me=v*x,Me=Math.min(ye.dq,me),Xe=ye.dq>0?Me/ye.dq:1;Me>=me&&L<0&&(L=X),F+=ye.energyJ*Xe/cc,Ge=ye.energyJ*Xe,Ne=ye.seconds,P+=ye.lossJ*Xe,S+=Me,ae>0&&(Ae=Me/ye.seconds),v=sg(v-Me/x),M=pS(y,M,ye.dq>0&&ae>0?Me/ae:0,ye.lossJ*Xe,ae,R),M>A&&(A=M),ge=pe}else if(o.regen){let Te=u?at(u.ay[X],u.bank?.[X]??0)/9.81:0,ye=K(-pe,ne,xe/9.81,Te),me=o.regenEfficiency*ye*t[X],Me=V2(y,me,ae,v,M),Xe=(1-v)*x,Ye=Math.min(Me.dq,Xe),Le=Me.dq>0?Ye/Me.dq:1;T+=Me.energyJ*Le/cc,Ge=-Me.energyJ*Le,P+=Me.lossJ*Le,S-=Ye,ae>0&&(Ae=-Ye/ae),v=sg(v+Ye/x),M=pS(y,M,Ye>0&&ae>0?-Ye/ae:0,Me.lossJ*Le,ae,R),M>A&&(A=M),ge=-ye*Le}if(l?.netKwh.push(F-T),l?.powerKw?.push(ae>0?Ge/Ne/1e3:0),l?.pack){let Te=l.pack;Te.soc.push(fe),Te.amps.push(Ae),Te.volts.push(y.ocv(fe)-Ae*y.resistance(fe,Ce)),Te.cellC.push(Ce)}if(_){let Te=_.rpm(ne),ye=_.th.derate(Te,O,_.peak(Te));ye<B&&(B=ye),ye<1&&V<0&&(V=X),q+=ae,ye<1&&(j+=ae);let me=_.torque(ge,Te,ye),Me=_.th.lossW(Te,me,O);z+=Me*ae,i&&(i.windingC.push(O),i.derate.push(ye),i.lossW.push(Me),i.torqueNm.push(me),i.ampsRms.push(_.amps(me))),O=_.th.step(O,Me,ae),O>I&&(I=O)}else E&&i&&i.torqueNm.push(E.torque(ge,E.rpm(ne),1))}return{drive:F,regen:T,net:F-T,chargeAh:S/3600,loss:P/cc,socEnd:v,shortAt:w,cutoffAt:C,emptyAt:L,tempEndC:M,tempMaxC:A,..._?{motorTempEndC:O,motorTempMaxC:I,motorLossKwh:z/cc,motorDerateMin:B,motorDerateAt:V,motorDerateTimeFrac:q>0?j/q:0}:{}}}var $2=.5,G2=.02,K2=6;function hS(e,t,r,n,o,a,s,i){let c=n(),l=1,u=h=>{let f=fS(),b=cs(e,t,h.v,h.ax,r,o,a,f,s,void 0,{ay:h.ay,bank:i,...h.axScrub?{scrub:h.axScrub}:{}});return{trace:f,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 d=m.trace.derate.slice(),p=!1;for(let h=0;h<K2;h++){let f=n(d);l++;let b=Math.abs(f.laptime-c.laptime);if(c=f,m=u(c),b<G2){p=!0;break}let g=m.trace.derate,y=new Array(d.length);for(let x=0;x<d.length;x++)y[x]=d[x]+$2*((g[x]??1)-d[x]);d=y}return{lap:c,derate:d,solves:l,converged:p,peakWindingC:m.peak,derateTimeFrac:m.frac}}var H2=.1;function bS(e){if(e.motorModel?.kind==="ice")return 0;let t=e.power_limit_kw?.value??0;return t>0?t*1e3:0}function lg(e,t,r){return e.motorModel?.kind==="ice"?1/0:jr(is(e)).maxPower(t??e.soc.value,r,bS(e)).watts}function Tm(e,t,r,n){let o=lg(e,r,n);if(!Number.isFinite(o))return 1/0;if(o<=0)return 0;let a=Math.max(H2,t),s=ig(e),i=o*.9/a;return o*s(t,i)/a}var z2=180/Math.PI;function Pm(e,t,r,n){let o=e*t,a=e*(1-t);return o/r-a/n}var Lm=e=>e*9.81*z2;var zQ=Math.PI/180;function Dm(e,t,r,n=0){let o=$e(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?Pm(e.massTotal,e.frontMassFrac,2*i,2*c):0,u=Lm(l),m=u>.15?"understeer":u<-.15?"oversteer":"neutral";return{gradient:u,balance:m,cAlphaFront:i,cAlphaRear:c}}var ZQ=Math.PI/180,JQ=180/Math.PI;var gS=2220446049250313e-31;function j2(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 d=0;d<t;d++)e[a][d]*=m;for(let d=0;d<t;d++)e[d][a]*=l}}}}}function U2(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 X2(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])<=gS*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 d=.5*(u-l),p=d*d+m,h=Math.sqrt(Math.abs(p));l+=s,p>=0?(h=d+(d>=0?Math.abs(h):-Math.abs(h)),r[a-1]=r[a]=l+h,h!==0&&(r[a]=l-m/h),n[a-1]=n[a]=0):(r[a-1]=r[a]=l+d,n[a]=h,n[a-1]=-h),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 d=a-2,p=0,h=0,f=0;for(;d>=c;d--){let b=e[d][d],g=l-b,y=u-b;p=(g*y-m)/e[d+1][d]+e[d][d+1],h=e[d+1][d+1]-b-g-y,f=e[d+2][d+1];let x=Math.abs(p)+Math.abs(h)+Math.abs(f);if(p/=x,h/=x,f/=x,d===c)break;let k=Math.abs(e[d][d-1])*(Math.abs(h)+Math.abs(f)),v=Math.abs(p)*(Math.abs(e[d-1][d-1])+Math.abs(b)+Math.abs(e[d+1][d+1]));if(k<=gS*v)break}for(let b=d+2;b<=a;b++)e[b][b-2]=0,b!==d+2&&(e[b][b-3]=0);for(let b=d;b<=a-1;b++){b!==d&&(p=e[b][b-1],h=e[b+1][b-1],f=b!==a-1?e[b+2][b-1]:0,l=Math.abs(p)+Math.abs(h)+Math.abs(f),l!==0&&(p/=l,h/=l,f/=l));let g=Math.sqrt(p*p+h*h+f*f),y=p>=0?g:-g;if(y!==0){b===d?c!==d&&(e[b][b-1]=-e[b][b-1]):e[b][b-1]=-y*l,p+=y,l=p/y,u=h/y;let x=f/y;h/=p,f/=p;for(let v=b;v<=a;v++){let R=e[b][v]+h*e[b+1][v];b!==a-1&&(R+=f*e[b+2][v],e[b+2][v]-=R*x),e[b+1][v]-=R*u,e[b][v]-=R*l}let k=a<b+3?a:b+3;for(let v=c;v<=k;v++){let R=l*e[v][b]+u*e[v][b+1];b!==a-1&&(R+=x*e[v][b+2],e[v][b+2]-=R*f),e[v][b+1]-=R*h,e[v][b]-=R}}}}}}while(c<a-1&&a>=0)}return r.map((i,c)=>({re:i,im:n[c]}))}function yS(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 j2(r),U2(r),X2(r)}function xS(e){let t=[],r=new Array(e.length).fill(!1),n=yS(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 ug(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 f=c;f<r;f++)for(let b=c;b<r;b++){let g=e[f][b]*e[f][b]+t[f][b]*t[f][b];g>m&&(m=g,l=f,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 f=0;f<r;f++)[e[f][c],e[f][u]]=[e[f][u],e[f][c]],[t[f][c],t[f][u]]=[t[f][u],t[f][c]];[n[c],n[u]]=[n[u],n[c]]}let d=e[c][c],p=t[c][c],h=d*d+p*p;for(let f=c+1;f<r;f++){let b=(e[f][c]*d+t[f][c]*p)/h,g=(t[f][c]*d-e[f][c]*p)/h;if(!(b===0&&g===0))for(let y=c;y<r;y++)e[f][y]-=b*e[c][y]-g*t[c][y],t[f][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 d=0,p=0;for(let h=c+1;h<r;h++)d+=e[c][h]*o[h]-t[c][h]*a[h],p+=e[c][h]*a[h]+t[c][h]*o[h];o[c]=-(d*l+p*u)/m,a[c]=-(p*l-d*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 q2(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 ug(r,n)}function Em(e,t=r=>q2(e,r)){return xS(e).map(r=>({...r,vector:t(r.eigenvalue)}))}function ls(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 RS(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 ls(Em(i),c,0)}function vS(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=RS({sprungMass:o,unsprungMass:e.unsprungCornerMass??e.unsprungPerCorner,springRate:s,damperRate:n,tireRate:lt(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 Im(e,t,r){let n=Be(e);return{front:vS(e,n,"front",t??n.rideDampingFront),rear:vS(e,n,"rear",r??n.rideDampingRear)}}var pZ=180/Math.PI;var mg=["FL","FR","RL","RR"],he={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},us=20,kS=[he.zFL,he.zFR,he.zRL,he.zRR],MS=[he.vzFL,he.vzFR,he.vzRL,he.vzRR],xn={fzFL:0,fzFR:1,fzRL:2,fzRR:3,fzBody:4,myBody:5,mxBody:6,fx:7,fy:8,mz:9},pg=10;function _m(e){let t=Array.from({length:us},()=>new Array(us).fill(0)),r=Array.from({length:us},()=>new Array(pg).fill(0));t[he.zFL][he.vzFL]=1,t[he.zFR][he.vzFR]=1,t[he.zRL][he.vzRL]=1,t[he.zRR][he.vzRR]=1,t[he.zBody][he.vzBody]=1,t[he.pitch][he.pitchRate]=1,t[he.roll][he.rollRate]=1,t[he.x][he.vx]=1,t[he.y][he.vy]=1,t[he.yaw][he.yawRate]=1;let{inertia:n}=e,o=[1,0,3,2],a=(s,i,c,l)=>{s[kS[i]]-=c,s[MS[i]]-=l,s[he.zBody]+=c,s[he.vzBody]+=l,s[he.pitch]-=c*e.leverX[i],s[he.pitchRate]-=l*e.leverX[i],s[he.roll]+=c*e.leverY[i],s[he.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),d=e.damperRate[s]+c(e.rollDamper),p=(l+u)/2,h=(l-u)/2,f=(m+d)/2,b=(m-d)/2,g=new Array(us).fill(0);a(g,s,p,f),(h!==0||b!==0)&&a(g,o[s],h,b);let y=e.wheelMass[s],x=e.leverX[s],k=e.leverY[s],v=kS[s],R=MS[s];for(let M=0;M<us;M++){let A=g[M];A!==0&&(t[R][M]+=A/y,t[he.vzBody][M]-=A/e.bodyMass,t[he.pitchRate][M]+=x*A/n.yy,t[he.rollRate][M]-=k*A/n.xx)}t[R][v]-=e.tyreRate[s]/y,t[R][R]-=e.tyreDamping[s]/y,r[R][xn.fzFL+s]=1/y}return r[he.vzBody][xn.fzBody]=1/e.bodyMass,r[he.pitchRate][xn.myBody]=1/n.yy,r[he.rollRate][xn.mxBody]=1/n.xx,r[he.vx][xn.fx]=1/e.totalMass,r[he.vy][xn.fy]=1/e.totalMass,r[he.yawRate][xn.mz]=1/n.zz,{A:t,B:r,params:e}}function dg(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,d=lt(e,"front")*1e3,p=lt(e,"rear")*1e3,h=(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:[d,d,p,p],tyreDamping:[h,h,h,h],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 SS=he.rollRate+1;function AS(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,SS).map(i=>i.slice(0,SS));if(!n.every(i=>i.every(Number.isFinite)))return{};let a=Em(n,i=>{let c=i.re*i.re-i.im*i.im,l=2*i.re*i.im,u=r.map((d,p)=>r.map((h,f)=>(p===f?c:0)-i.re*n[2*p+1][2*f+1]-n[2*p+1][2*f])),m=r.map((d,p)=>r.map((h,f)=>(p===f?l:0)-i.im*n[2*p+1][2*f+1]));return ug(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:ls(a,s,1),pitch:ls(a,s,2),roll:ls(a,s,3)}}function wS(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 Nm(e){let t=Be(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=AS(_m(dg(e)));return{roll:wS(m.roll,a,s),pitch:wS(m.pitch,l,u)}}var Om=9.81,Rn=Math.PI/180;function FS(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 ms(e,t,r,n,o){let{wb:a,lf:s,lr:i,m:c}=FS(e),l=0;for(let x=0;x<16;x++){let k=l/r,v=o-n-s*k/r,R=-n+i*k/r,M=$e(e,l/Om,0,r),A=Math.max(0,M.FL+M.FR),F=Math.max(0,M.RL+M.RR),T=t(v,A),P=t(R,F),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,d=-n+i*u/r,p=$e(e,l/Om,0,r),h=Math.max(0,p.FL+p.FR),f=Math.max(0,p.RL+p.RR),b=t(m,h),g=t(d,f),y=s*b*Math.cos(o)-i*g;return{ay:l/Om,cn:y/(c*Om*a)}}function fg(e,t,r,n={}){let o=Math.max(8,r),a=(n.betaMaxDeg??10)*Rn,s=(n.deltaMaxDeg??10)*Rn,i=n.nLines??9,c=n.nPts??21,l=(g,y,x,k)=>x===1?g:g+(y-g)*k/(x-1),u=[],m={ay:[],cn:[]},d=0;for(let g=0;g<i;g++){let y=l(-s,s,i,g),x=[],k=[],v=[],R=[];for(let M=0;M<c;M++){let A=l(-a,a,c,M),F=ms(e,t,o,A,y);x.push(F.ay),k.push(F.cn),v.push(A/Rn),R.push(y/Rn),Math.abs(F.ay)>d&&(d=Math.abs(F.ay))}u.push({label:`\u03B4 ${(y/Rn).toFixed(0)}\xB0`,ay:x,cn:k,betaDeg:v,deltaDeg:R});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(x[M-1]+A*(x[M]-x[M-1])),m.cn.push(0);break}}let p=[];for(let g=0;g<i;g++){let y=l(-a,a,i,g),x=[],k=[],v=[],R=[];for(let M=0;M<c;M++){let A=l(-s,s,c,M),F=ms(e,t,o,y,A);x.push(F.ay),k.push(F.cn),v.push(y/Rn),R.push(A/Rn)}p.push({label:`\u03B2 ${(y/Rn).toFixed(0)}\xB0`,ay:x,cn:k,betaDeg:v,deltaDeg:R})}let h=.5*Rn,f=(ms(e,t,o,h,0).cn-ms(e,t,o,-h,0).cn)/(2*h),b=(ms(e,t,o,0,h).cn-ms(e,t,o,0,-h).cn)/(2*h);return{isoBeta:p,isoDelta:u,trim:m,maxAy:d,stability:f,control:b,speed:o}}function Q2(e){return!e.corneringStiffnessFront||!e.corneringStiffnessRear?null:{Cf:2*e.corneringStiffnessFront,Cr:2*e.corneringStiffnessRear}}function uc(e,t){let r=Q2(e);if(!r)return null;let{Cf:n,Cr:o}=r,{wb:a,lf:s,lr:i,m:c}=FS(e),l=e.yawInertia??c*1*1,u=Math.max(3,t),m=-(n+o)/(c*u),d=(-s*n+i*o)/(c*u)-u,p=(-s*n+i*o)/(l*u),h=-(s*s*n+i*i*o)/(l*u),f=m+h,b=m*h-d*p,g=f*f-4*b,y,x,k;if(g<0)y=f/2,x=Math.sqrt(Math.max(0,b)),k=x>0?-f/(2*x):1;else{let C=Math.sqrt(g);y=Math.max((f+C)/2,(f-C)/2),x=Math.sqrt(Math.abs(b)),k=x>0?-f/(2*x):1}let v=f<0&&b>0,R=Pm(c,e.frontMassFrac,n,o),M=Lm(R),A=M>.15?"understeer":M<-.15?"oversteer":"neutral",F=s*n-i*o,T=C=>C*3.6,P=null,S=null;F>1e-6?S=T(Math.sqrt(n*o*a*a/(c*F))):F<-1e-6&&(P=T(Math.sqrt(n*o*a*a/(c*-F))));let w=u/(a+R*u*u);return{stable:v,yawFreq:x/(2*Math.PI),dampingRatio:k,eigReal:y,understeerGradient:M,balance:A,characteristicSpeed:P,criticalSpeed:S,yawRateGain:w}}var Z2={envelopeTrim:{name:"Grip envelope, trim",code:"`solvePoint` in src/core/dynamics/twoTrack.ts (`twoTrackLimitState`, `twoTrackStateAtAy`)"},envelopeLimits:{name:"Grip envelope, limits",code:"`calcGGV` in src/core/laptime/ggv.ts"},qssLap:{name:"QSS lap",code:"`solveLap` in src/core/laptime/solver.ts, with its energy (`energyOverPath`)"},tyreReadouts:{name:"Tyre readouts",code:"`lapReserves` in src/core/dynamics/lapReserve.ts"},transientPlant:{name:"Transient plant",code:"`dynamicReplay` in src/core/dynamics/dynamicReplay.ts"},plannerRequest:{name:"Optimal, the request",code:"`planCarFrom` in src/core/plan/request.ts"},ymd:{name:"Yaw moment diagram",code:"`twoTrackYMD` in src/core/dynamics/twoTrack.ts"},stepSteer:{name:"Step steer",code:"`steerRun` in src/core/dynamics/steerRun.ts"},drive:{name:"Drive",code:"`liveCar` in src/core/drive/liveCar.ts"}},hg=Object.keys(Z2),Vm=["envelopeTrim","envelopeLimits","qssLap","tyreReadouts","ymd"];var J2="the longitudinal condition is set directly; what a motor could deliver is the lap solver\u2019s question",e_="no tractive force is applied at a constant speed",bg="runs a torque-vectoring controller only when the caller hands one in (`DynamicReplayOptions.vectoring`, `SteerRunOptions.vectoring`), as the app does (`lapVectoringFor`, `steerVectoringFor` in src/app/dynamics/tvCore.ts)",gg="Drive runs no torque vectoring: its aids are ABS and traction control",CS="the readouts split the drive by room or through the diff, never by a controller",t_=[{key:"damper_front",tools:["ymd"],why:"dampers act on velocity; every point here is at constant attitude"},{key:"damper_rear",tools:["ymd"],why:"dampers act on velocity; every point here is at constant attitude"},{key:"tire_vertical_damping",tools:Vm,why:"tyre damping acts on velocity; every point here is at constant attitude"},{key:"tire_vertical_damping",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic (reduced planner model)"},{key:"I_yaw",tools:["envelopeTrim","envelopeLimits","tyreReadouts","ymd"],why:"inertia resists change; a steady corner has none"},{key:"I_yaw",tools:["qssLap"],why:"inertia resists change; a steady corner has none. The quasi-transient option charges it (`calcGgvFamily`)",onCar:"quasi-transient off, as in the templates"},{key:"I_roll",tools:Vm,why:"inertia resists change; a steady corner has none"},{key:"I_roll",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no roll dynamics (reduced planner model)"},{key:"I_pitch",tools:Vm,why:"inertia resists change; a steady corner has none"},{key:"I_pitch",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no pitch dynamics (reduced planner model)"},...["capacity","ocv","soc"].flatMap(e=>[{key:e,tools:["ymd"],why:"energy does not enter a single steady-state point"},{key:e,tools:hg.filter(t=>t!=="ymd"&&t!=="qssLap"),why:"the charge reaches the forces only through a battery model\u2019s power ceiling (`packPowerW`); without one it is counted by the QSS lap\u2019s energy account, and drawn on nowhere",onCar:"no battery model"}]),{key:"tv_kp",tools:Vm,why:"the feedback gain multiplies a yaw error, and a trimmed point has none \u2014 the feedforward does move this diagram"},{key:"tv_kp",tools:["transientPlant","stepSteer"],why:bg},{key:"tv_kp",tools:["plannerRequest"],why:"the planner reads only whether torque vectoring is on, for its allocation (`longitudinalAllocation`)"},{key:"tv_kp",tools:["drive"],why:gg},{key:"tv_enabled",tools:["transientPlant","stepSteer"],why:bg},{key:"tv_enabled",tools:["drive"],why:gg},{key:"tv_enabled",tools:["tyreReadouts"],why:CS,gap:"the envelope corners with the feedforward, the readouts split the same lap without it (rule 3)"},...["tv_ff_low","tv_ff_high","tv_v_low","tv_v_high"].flatMap(e=>[{key:e,tools:["transientPlant","stepSteer"],why:bg},{key:e,tools:["drive"],why:gg},{key:e,tools:["tyreReadouts"],why:CS,gap:"the envelope corners with the feedforward, the readouts split the same lap without it (rule 3)"},{key:e,tools:["plannerRequest"],why:"the planner allocates by capacity when vectoring is on, with no feedforward schedule (reduced planner model)"}]),{key:"brake_balance",tools:["ymd"],why:"no braking: the diagram is drawn at constant speed",ymd:{driving:"the diagram is drawn under acceleration, not braking",liveBraking:!0}},{key:"brake_balance",tools:["stepSteer"],why:"the speed is held by the drive; the test never brakes"},...["gear_ratio","power_scale","power_limit_kw","driven_wheels","effi_pgb"].map(e=>({key:e,tools:["ymd"],why:e_,ymd:{moving:J2}})),...["gear_ratio","power_scale","power_limit_kw"].flatMap(e=>[{key:e,tools:["envelopeTrim"],why:"the trim imposes the tyres\u2019 push (`axG`); what a motor could deliver is the envelope limits\u2019 question"},{key:e,tools:["tyreReadouts"],why:"the lap\u2019s motion carries the drive the powertrain made; the readouts only split it"},{key:e,tools:["stepSteer"],why:"the speed is held by a force (a PI loop on the drive), not through the powertrain"}]),{key:"power_scale",tools:["plannerRequest"],why:"the planner\u2019s drive is the motor model\u2019s axle force (`planDriveOf`), which `power_scale` does not scale",gap:"the envelope scales its drive by `power_scale` (`calcGGV`), the planner does not: two cars (rule 1)"},{key:"power_limit_kw",tools:["plannerRequest"],why:"the planner has no pack limit (reduced planner model)"},...["I_wheel","I_rotor"].flatMap(e=>[{key:e,tools:["ymd"],why:"rotating inertia only acts where the car changes speed",ymd:{moving:"rotating inertia is longitudinal, and `ax` is set here rather than solved \u2014 nothing in this picture spins a wheel up"}},{key:e,tools:["envelopeTrim"],why:"the trim imposes the tyres\u2019 push; rotating inertia acts where the speed changes (`rotatingInertia.ts`)"},{key:e,tools:["tyreReadouts"],why:"the lap\u2019s motion carries what the inertia cost; the readouts only split the force"},{key:e,tools:["stepSteer"],why:"no wheel rotation, and the speed is held"},{key:e,tools:["plannerRequest"],why:"the planner has no rotating inertia (reduced planner model)"}]),{key:"v_limit_endurance",tools:["ymd"],why:"a limiter constrains a lap\u2019s speed profile; this diagram is drawn at one imposed speed"},{key:"v_limit_endurance",tools:hg.filter(e=>e!=="ymd"),why:"a limiter constrains a distance event\u2019s speed profile (`runTrackLap`), and is live there (`wiring.test.ts`, LAP_KEYS)"},{key:"endurance_reserve",tools:["ymd"],why:"an energy budget sets the long event\u2019s speed ceiling; this diagram is drawn at one imposed speed"},{key:"endurance_reserve",tools:hg.filter(e=>e!=="ymd"),why:"an energy budget solves a distance event\u2019s speed ceiling (`runTrackLap`), and is live there (`wiring.test.ts`, LAP_KEYS)"},{key:"fr_0",tools:["ymd"],why:"rolling resistance is longitudinal",ymd:{moving:"rolling resistance is a drag term; `ax` is what the car does, not what the tyres are handed"}},{key:"fr_0",tools:["envelopeTrim"],why:"the trim takes the tyres\u2019 push as given; rolling resistance is a drag, not a tyre force"},{key:"fr_0",tools:["tyreReadouts"],why:"the lap\u2019s motion carries the drag (`LapMotion.axDrag`), rolling resistance in it"},{key:"fr_0",tools:["stepSteer"],why:"step steer\u2019s plant has no rolling resistance (`twoTrackSimFrom` without `rollingCoeff`), and its speed is held"},{key:"r_dyn",tools:["ymd"],why:"the rolling radius only matters where a wheel is driven or braked",ymd:{moving:"the force each tyre carries is set here in newtons; a radius would only convert it to a torque"}}];function TS(e=0){let t=[],r=new Set;for(let n of t_){if(!n.tools.includes("ymd")||n.onCar||r.has(n.key)||e<0&&n.ymd?.liveBraking)continue;r.add(n.key);let o=e>0?n.ymd?.driving??n.ymd?.moving??n.why:e<0?n.ymd?.moving??n.why:n.why;t.push({key:n.key,why:o})}return t}var PS=Math.PI/180;function ES(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 LS(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 IS(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,d]of[[s,1-c],[Math.min(o-1,s+1),c]])if(!(d<=0))for(let[p,h]of[[i,1-l],[Math.min(a-1,i+1),l]])h<=0||(u+=d*h*n(e.isoDelta[m],p,m));return u}function _S(e,t,r){let n=e.isoDelta[0],o=(n.betaDeg[1]-n.betaDeg[0])*PS||1,a=e.isoDelta.length>1?(e.isoDelta[1].deltaDeg[0]-e.isoDelta[0].deltaDeg[0])*PS:1,s=R=>IS(e,t,r,R),i=s((R,M)=>R.ay[M]),c=s((R,M)=>R.cn[M]),l=s((R,M)=>R.betaDeg[M]),u=s((R,M)=>R.deltaDeg[M]),m=s((R,M)=>LS(R.cn,M,o)),d=s((R,M,A)=>LS(e.isoDelta.map(F=>F.cn[M]),A,a||1)),p=Math.max(1e-6,e.maxAy),h=Math.abs(i)/p,f=Math.max(1e-6,...e.isoDelta.flatMap(R=>R.cn.filter(Number.isFinite).map(Math.abs))),b=Math.abs(c)/f,g=i===0?c:c*Math.sign(i),y=[];y.push(`${ES(l,i)}.`),b<.03?y.push("On the trim line: yaw moments balance, so this is a steady corner the car can actually hold. Only points on this line are real cornering states \u2014 everywhere else the car is still rotating."):g>0?y.push(`Not a steady state: there is a surplus yaw moment turning the car further into the corner, so it would keep rotating from here. To hold ${Math.abs(i).toFixed(2)} g the driver would have to wind ${u>=0?"off":"on"} steer until the point reaches the trim line.`):y.push("Not a steady state: the yaw moment is straightening the car out, so it would run wide from here. The car needs more steer, or more front grip, to reach the trim line at this slip angle.");let x=Math.abs(e.stability)>1e-9?m/e.stability:1;x<.15?y.push("Yaw stiffness has collapsed here: the moment resisting a change in body slip is essentially gone, so the car will not gather itself up if it steps out. Both axles are close to saturation."):x<.85?y.push(`Yaw stiffness is down to about ${(100*x).toFixed(0)} % of its straight-ahead value \u2014 the car resists a change in body slip less firmly here than it does in the linear range.`):y.push(`Yaw stiffness is near its straight-ahead value (${(100*x).toFixed(0)} %), so the car still opposes a change in body slip about as firmly as it does in a straight line.`);let k=Math.abs(e.control),v=k>1e-9?Math.abs(d)/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.`),h>.97?y.push(`At the edge of the diagram: ${Math.abs(i).toFixed(2)} g is essentially all this car has at this speed.`):h<.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:d,gripUsed:h,notes:y}}var DS=1e-4;function yg(e){let t=null,r=d=>{if(!t)return!0;let p=Math.abs(d),h=Math.abs(t.ay);return p>h*(1+DS)?!0:p<h*(1-DS)?!1:d>0&&t.ay<0};for(let d=0;d<e.isoDelta.length;d++){let p=e.isoDelta[d];for(let h=1;h<p.cn.length;h++){if(!(p.cn[h-1]===0||p.cn[h-1]<0!=p.cn[h]<0))continue;let b=p.cn[h-1]===p.cn[h]?0:p.cn[h-1]/(p.cn[h-1]-p.cn[h]),g=p.ay[h-1]+b*(p.ay[h]-p.ay[h-1]);r(g)&&(t={ay:g,d,b:b<.5?h-1:h})}}if(!t)return null;let n=_S(e,t.d,t.b),o=Math.abs(e.control)>1e-9?Math.abs(n.control/e.control):1,a=Math.abs(e.stability)>1e-9?n.stability/e.stability:1,s=o<.35,i=a<.35,c=s&&i?"both":s?"front":i?"rear":o<a?"front":"rear",l=e.isoDelta[t.d].betaDeg.length,u=t.b===0||t.b===l-1||t.d===0||t.d===e.isoDelta.length-1,m=t.ay<0?-1:1;return{ay:Math.abs(t.ay),turn:m,betaDeg:e.isoDelta[t.d].betaDeg[t.b]*m,deltaDeg:e.isoDelta[t.d].deltaDeg[t.b]*m,d:t.d,b:t.b,limitedBy:c,controlFrac:o,stiffnessFrac:a,onGridEdge:u}}function NS(e=0){return TS(e)}var r_=NS(0);function OS(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 n_=OS(0);var o_=9.81;function a_(e){let t=e.wheelbase/1e3;return{lf:t*(1-e.frontMassFrac),lr:t*e.frontMassFrac}}function mc(e,t,r,n){let o=t.tire;if(!o)return null;let s=(r==="limit"?Nb(e,o,t.speed):Hn(e,o,t.speed,t.ayG)).wheels;return Jr(n??So(o,e.massTotal*o_*1.2),{FL:s.FL,FR:s.FR,RL:s.RL,RR:s.RR},a_(e))}function s_(e){if(!e.tire)return e.cornerStiffness;let t=Fe(e.tire,"front"),r=Fe(e.tire,"rear");return{front:n=>t.corneringStiffness(n),rear:n=>r.corneringStiffness(n)}}var VS=[{key:"understeer",label:"Understeer gradient",unit:"\xB0/g",compute:(e,t)=>Dm(e,t.ayG,s_(t),t.speed).gradient},{key:"rollGradient",label:"Roll gradient",unit:"\xB0/g",compute:e=>Be(e).rollGradient},{key:"pitchGradient",label:"Pitch gradient",unit:"\xB0/g",compute:e=>Be(e).pitchGradient},{key:"tlltdFront",label:"TLLTD front",unit:"%",compute:e=>100*qf(e)},{key:"rollStiffFront",label:"Front roll-stiffness",unit:"%",compute:e=>100*Be(e).frontRollStiffFrac},{key:"rideFreqFront",label:"Ride freq front",unit:"Hz",compute:e=>Be(e).rideFreqFront},{key:"rideFreqRear",label:"Ride freq rear",unit:"Hz",compute:e=>Be(e).rideFreqRear},{key:"rollFreq",label:"Roll-mode freq",unit:"Hz",compute:e=>Nm(e).roll.freq},{key:"pitchFreq",label:"Pitch-mode freq",unit:"Hz",compute:e=>Nm(e).pitch.freq},{key:"zetaFront",label:"Damping \u03B6 front",unit:"-",compute:e=>Im(e).front.dampingRatio},{key:"zetaRear",label:"Damping \u03B6 rear",unit:"-",compute:e=>Im(e).rear.dampingRatio},{key:"yawFreq",label:"Yaw natural freq",unit:"Hz",compute:(e,t)=>uc(e,t.speed)?.yawFreq??NaN},{key:"yawZeta",label:"Yaw damping \u03B6",unit:"-",compute:(e,t)=>uc(e,t.speed)?.dampingRatio??NaN},{key:"stabilitySpeed",label:"Char./critical speed",unit:"km/h",compute:(e,t)=>{let r=uc(e,t.speed);return r?r.criticalSpeed??r.characteristicSpeed??NaN:NaN}},{key:"maxAy",label:"Max lateral accel",unit:"g",compute:(e,t)=>t.fyAxle?fg(e,t.fyAxle,t.speed,{betaMaxDeg:12,deltaMaxDeg:12}).maxAy:NaN},{key:"yawReserveRear",label:"Yaw stability reserve",unit:"N\xB7m",compute:(e,t)=>mc(e,t,"operating")?.stabil??NaN},{key:"yawReserveFront",label:"Yaw agility reserve",unit:"N\xB7m",compute:(e,t)=>mc(e,t,"operating")?.agil??NaN},{key:"limitBalance",label:"Limit balance (+US / \u2212OS)",unit:"-",compute:(e,t)=>mc(e,t,"limit")?.rel??NaN},{key:"yawStiffness",label:"Yaw stiffness N_\u03B2",unit:"N\xB7m/rad",compute:(e,t)=>t.tire?_b(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorque",label:"Steering holding torque",unit:"N\xB7m",compute:(e,t)=>t.tire?Eb(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorqueGradient",label:"Steering feedback gradient",unit:"N\xB7m/g",compute:(e,t)=>t.tire?Ib(e,t.tire,t.speed,t.ayG):NaN}],xg=Object.fromEntries(VS.map(e=>[e.key,e]));var Or=9.81;function i_(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 c_={front:!1,rear:!0};function ps(e,t,r,n){let o=e.muX(t)*t,a=e.muY(t)*t;if(!(o>0))return 0;let s=a>0?Math.min(1,r/a):1;return n&&t>0?o*eh(n,t,s):o*Math.sqrt(1-s*s)}function BS(e,t,r,n,o,a,s,i){let c=e[t]+e[r];if(!(c>0))return;let l=ps(n,o[t],a[t],i),u=ps(n,o[r],a[r],i),m=!(l+u>0);if(m&&(l=n.muX(o[t])*o[t],u=n.muX(o[r])*o[r]),!(l+u>0))return;let d=s?.[t],p=s?.[r];if(d===void 0&&p===void 0){e[t]=c*(l/(l+u)),e[r]=c-e[t];return}let h=[Math.min(l,d??1/0),Math.min(u,p??1/0)],f=m?void 0:$S(n,o,a,t,r,l,u,s,i);if(f&&c>h[0]+h[1]){let b=Math.min(c-f.capC,f.xMax),g=Math.min(a[f.o],f.fyO(b));a[f.c]+=a[f.o]-g,a[f.o]=g,e[f.o]=b,e[f.c]=c-b;return}e[t]=GS(c,h,[l,u])[0],e[r]=c-e[t]}function $S(e,t,r,n,o,a,s,i,c){let l=i[n]??1/0,u=i[o]??1/0,m,d,p;if(l<a&&!(u<s))[m,d,p]=[n,o,s];else if(u<s&&!(l<a))[m,d,p]=[o,n,a];else return;let h=i[m],f=i[d]??1/0,b=e.muX(t[d])*t[d],g=e.muY(t[d])*t[d],y=e.muX(t[m])*t[m],x=e.muY(t[m])*t[m];if(!(b>0&&g>0&&y>0&&x>0))return;let k=(P,S)=>c?Pv(c,P,S):Math.sqrt(Math.max(0,1-S*S)),v=(P,S)=>c?eh(c,P,S):Math.sqrt(Math.max(0,1-S*S)),R=P=>g*k(t[d],P/b),M=x*k(t[m],h/y),A=r[m]+r[d]-M,F=Math.min(f,b*v(t[d],0)),T=A<=0?F:Math.max(p,Math.min(F,A<g?b*v(t[d],A/g):0));return{c:m,o:d,capC:h,xMax:T,fyO:R}}function GS(e,t,r){let n=t.reduce((a,s)=>a+s,0),o=r.reduce((a,s)=>a+s,0);return n>0&&e<=n?t.map(a=>e*a/n):o>n&&e<=o?t.map((a,s)=>a+(e-n)*(r[s]-a)/(o-n)):r.map(a=>e*a/o)}function KS(e,t,r,n,o,a={},s="open",i,c){if(!e.rear)return 1;if(!e.front)return 0;let l=(b,g,y)=>y?Ii(b,g,y):s==="own"?b+g:2*Math.min(b,g),u={FL:ps(n,t.FL,r.FL,c?.front),FR:ps(n,t.FR,r.FR,c?.front),RL:ps(o,t.RL,r.RL,c?.rear),RR:ps(o,t.RR,r.RR,c?.rear)},m=(b,g)=>u[g],d=l(u.FL,u.FR,a.front),p=l(u.RL,u.RR,a.rear);if(i&&i.total>0&&d+p>0){let b=(R,M)=>Math.min(m(R,M),i.caps[M]??1/0),g=(R,M,A,F,T)=>{let P=M==="FL"?c?.front:c?.rear,S=F||s!=="own"?void 0:$S(R,t,r,M,A,m(R,M),m(R,A),i.caps,P),w=S?S.capC+S.xMax:l(b(R,M),b(R,A),F);return[w,Math.max(T,w)]},[y,x]=g(n,"FL","FR",a.front,d),[k,v]=g(o,"RL","RR",a.rear,p);return GS(i.total,[y,k],[x,v])[0]/i.total}if(d+p>0)return d/(d+p);let h=n.muX(t.FL)*t.FL+n.muX(t.FR)*t.FR,f=o.muX(t.RL)*t.RL+o.muX(t.RR)*t.RR;return h+f>0?h/(h+f):.5}function Rg(e,t,r,n){return{car:t?YS(t,r.loadFactor[n]):e,ayTyre:at(r.ay[n],r.bank?.[n]??0),axCar:r.ax[n]-(r.axGrade?.[n]??0)}}function HS(e,t){if(!e.aero?.model)return 0;let r=Math.min(t.v.length,t.ax.length,t.ay.length),n=t.loadFactor?$m(e):void 0,o=0,a=0;for(let s=0;s<r;s++){let i=t.ds?.[s]??1,c=Rg(e,n,t,s);o+=i,Xf(c.car,t.v[s],c.axCar/Or,c.ayTyre/Or)&&(a+=i)}return o>0?a/o:0}function zS(e,t,r){let n=fr(Fe(t,"front")),o=fr(Fe(t,"rear")),a=Math.min(r.v.length,r.ax.length,r.ay.length),s=r.loadFactor?$m(e):void 0,i=0,c=0;for(let l=0;l<a;l++){let u=r.ds?.[l]??1,m=Rg(e,s,r,l);i+=u;let d=$e(m.car,m.ayTyre/Or,m.axCar/Or,r.v[l]);(d.FL>n||d.FR>n||d.RL>o||d.RR>o)&&(c+=u)}return i>0?c/i:0}function Bm(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=Qa(t,e.massTotal*Or*1.2),l=Ba(c,"front"),u=Ba(c,"rear"),m={mu:1},d=K=>({muX:D=>m.mu*K.muX(D),muY:D=>m.mu*K.muY(D)}),p=r.mu?d(l):l,h=r.mu?u===l?p:d(u):u,f=r.mu?{front:p,rear:h}:c,b=Dt(Fe(t,"front")),g=Dt(Fe(t,"rear")),y=th(b,l),x=g===b?y:th(g,u),k={front:y,rear:x},v=n.driven??c_,R={front:qt(e,"front",1),rear:qt(e,"rear",1)},M={front:0,rear:0},A=new Array(o),F=new Array(o),T=new Array(o),P=1/0,S=0,w=0,C=fr(b),L=fr(g),E=0,_=0,O=0,I=0,z=0,B=0,V=["FL","FR","RL","RR"],j=n.perWheel?Object.fromEntries(V.map(K=>[K,{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,q=r.loadFactor?$m(e):void 0;for(let K=0;K<o;K++){let D=Rg(e,q,r,K),{ayTyre:N,axCar:Y}=D,H=N/Or,W=$e(D.car,H,Y/Or,r.v[K]),X=r.mu?Fm(r.mu,K):1;m.mu=X;let ne=e.massTotal*N,Z=ne*i/a,xe=ne*s/a,de=di(b,Z/X,W.FL,W.FR,z),be=di(g,xe/X,W.RL,W.RR,B);z=de,B=be;let U={FL:X*Math.abs(b.Fy(de,W.FL,0)),FR:X*Math.abs(b.Fy(de,W.FR,0)),RL:X*Math.abs(g.Fy(be,W.RL,0)),RR:X*Math.abs(g.Fy(be,W.RR,0))},ee=(Y-(r.axDrag?.[K]??0)-(r.axScrub?.[K]??0))/Or,se=r.wheelMotor,ie=se?Object.fromEntries(V.flatMap(Ae=>se[Ae]?[[Ae,se[Ae][K]*e.massTotal]]:[])):void 0,Re=ie?{total:ee*Or*e.massTotal,caps:ie}:void 0,pe=ee>0&&v.front?KS(v,W,U,p,h,R,"own",Re,k):0,ce=r.v[K]*r.v[K],Pe=e.driveline?{Fz:W,alpha:{front:de,rear:be},curvature:ce>1?r.ay[K]/ce:0,seed:M,...X!==1?{grip:X}:{}}:void 0,ke={...Lb(e,ee,r.v[K],t,H,pe,Pe,X)};ee>0&&(R.front||BS(ke,"FL","FR",p,W,U,ie,y),R.rear||BS(ke,"RL","RR",h,W,U,ie,x));let ae=!1,ge=!1;for(let Ae of["FL","FR","RL","RR"]){let Ge=(Ae==="FL"||Ae==="FR"?p:h).muX(W[Ae])*W[Ae];Math.abs(ke[Ae])>Ge&&(ae=!0),W[Ae]>(Ae==="FL"||Ae==="FR"?C:L)&&(ge=!0)}ge&&(w+=r.ds?.[K]??1);let fe=Jr(f,{FL:{Fz:W.FL,Fy:U.FL,Fx:ke.FL},FR:{Fz:W.FR,Fy:U.FR,Fx:ke.FR},RL:{Fz:W.RL,Fy:U.RL,Fx:ke.RL},RR:{Fz:W.RR,Fy:U.RR,Fx:ke.RR}},{lf:s,lr:i});if(A[K]=fe.stabil,F[K]=fe.agil,T[K]=fe.rel,j){let Ae=.5*(W.FL+W.FR),Ge=.5*(W.RL+W.RR),Ne=p.muX(Ae)*Ae,Te=h.muX(Ge)*Ge;for(let ye of V){let me=W[ye],Me=ye==="FL"||ye==="FR",Xe=Me?p:h,Ye=Xe.muY(me)*me,Le=Xe.muX(me)*me,Ke=j[ye],vt=Me?de:be;Ke.Fz[K]=me,Ke.alpha[K]=vt,Ke.Fy[K]=U[ye],Ke.Fx[K]=ke[ye],Ke.Mz[K]=me>0?X*(Me?b:g).Mz(vt,me,0):0,Ke.FxCap[K]=Le,Ke.FyCap[K]=Ye;let Nt=Ye>0?Math.min(1,Math.abs(U[ye])/Ye):0,Sr=i_(ke[ye],Le,Me?Ne:Te),wn=Me?y:x,mt=wn&&me>0?wn.reach(me,Math.sign(ke[ye])*Sr,Nt):1;Ke.used[K]=Math.hypot(Nt,Sr)/mt}}fe.stabil<P&&(P=fe.stabil,S=K);let Ce=r.ds?.[K]??1;I+=Ce,fe.diff>0&&(E+=Ce),ae&&(_+=Ce),Xf(D.car,r.v[K],Y/Or,H)&&(O+=Ce)}return{stabil:A,agil:F,rel:T,minStabil:Number.isFinite(P)?P:0,minStabilAt:S,pastTurnoverFrac:I>0?w/I:0,understeerFrac:I>0?E/I:0,beyondFrac:I>0?_/I:0,aeroOutsideFrac:I>0?O/I:0,wheels:j}}function $m(e){return Object.create(e,{loadFactor:{value:1,writable:!0,enumerable:!0}})}function YS(e,t){return e.loadFactor=t,e}var vg=9.81;function kg(e,t,r,n={}){let o=r.v.length,a=e.massTotal,s=un(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),d=m-(r.axDrag?.[l]??0)-(r.axScrub?.[l]??0),p=-a*d;if(!(p>0))continue;let h=at(r.ay[l],r.bank?.[l]??0)/vg,f=Math.min(.99,Math.max(.01,ja(e,d/vg,u,t,h)));c.front[l]=p*f,c.rear[l]=p*(1-f);let b=i?Ku(e,t,p,u,h):void 0;if(c.regen&&n.regen&&(c.regen[l]=b?Math.min(p,b.regenFront+b.regenRear):n.regen(p,u,m/vg)),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 SJ=Math.PI/180;var AJ=mg.map(Hi);var wJ=[he.zFL,he.zFR,he.zRL,he.zRR];var FJ=Array.from({length:he.rollRate+1},(e,t)=>t);var v_=9.81,k_=.001,M_=.6,S_=2,XS=4;function qS(e,t,r,n=XS){let o=Math.min(e.v.length,t.npts),{ds:a,closed:s}=t,i=r.massTotal*v_*r.wheelbase,c=A_(e.ay.slice(0,o).map((m,d)=>m/Math.max(k_,e.v[d])),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 d=m===0?s?o-1:-1:m-1,p=m===o-1?s?0:-1:m+1;if(d<0||p<0)continue;let h=a[d]+a[m];if(!(h>0))continue;u[m]=e.v[m]*(c[p]-c[d])/h;let f=Math.sign(c[m]);l[m]=f===0?0:f*r.yawInertia*u[m]/i}return{demand:l,rdot:u}}function A_(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,d=0;for(let p=1;p<=s&&!(!r&&c+p>=o||(d+=t[(c+p-1)%o],!(d<l)));p++){let h=1-d/l;u+=h*e[(c+p)%o],m+=h}d=0;for(let p=1;p<=s&&!(!r&&c-p<0);p++){let h=(c-p+o)%o;if(d+=t[h],!(d<l))break;let f=1-d/l;u+=f*e[h],m+=f}i[c]=u/m}return i}function QS(e,t,r,n,o={}){let a=o.maxIter??20,s=o.tol??.001,i=Math.min(1,Math.max(.001,o.relax??M_)),c=o.smoothM??XS,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=Kt(e.steady,t,n,l),m=[u.laptime],d=new Array(t.npts).fill(0),p=d.slice(),h=u,f=0,b=!1,g=0;for(let k=0;k<a;k++){f=k+1;let v=qS(h,t,r,c);d=v.demand.map((A,F)=>d[F]+i*(A-d[F])),p=v.rdot;let R=Kt(e.steady,t,n,{...l,envelope:A=>e.at(d[A]??0)});m.push(R.laptime);let M=Math.abs(R.laptime-h.laptime);if(h=R,g=M<=s?g+1:0,g>=S_){b=!0;break}}let y=0,x=0;for(let k=0;k<t.npts;k++)x+=t.ds[k],e.clamps(d[k]??0)&&(y+=t.ds[k]);return{...h,steady:u,demand:d,rdot:p,history:m,iterations:f,converged:b,clampedFrac:x>0?y/x:0}}var NJ=Math.PI/180;var vee=180/Math.PI;function vn(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=d=>{let p=e[d];return i*(r-s)*(r-p)/((a-s)*(a-p))+c*(r-a)*(r-p)/((s-a)*(s-p))+t[d]*(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 JS(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(f=>f.v),ayMax:p.map(f=>f.ayMax),radius:p.map(f=>Math.max(f.v,t)**2/f.ayMax),accel:p[0].axAccelN.map((f,b)=>p.map(g=>g.axAccelN[b])),decel:p[0].axDecelN.map((f,b)=>p.map(g=>g.axDecelN[b])),scrub:p[0].axScrubN.map((f,b)=>p.map(g=>g.axScrubN[b])),motors:p.every(f=>f.motorTyreN&&f.motorLoss)?{tyreN:p[0].motorTyreN.map((f,b)=>f.map((g,y)=>p.map(x=>x.motorTyreN[b][y]))),loss:p[0].motorLoss.map((f,b)=>p.map(g=>g.motorLoss[b])),gain:p.every(f=>f.motorGain)?p[0].motorGain.map((f,b)=>f.map((g,y)=>p.map(x=>x.motorGain[b][y]))):void 0}:void 0}),s=(p,h)=>({axAccelN:p.accel.map(f=>vn(p.vs,f,h)),axDecelN:p.decel.map(f=>vn(p.vs,f,h)),axScrubN:p.scrub.map(f=>vn(p.vs,f,h)),...p.motors?{motorTyreN:p.motors.tyreN.map(f=>f.map(b=>vn(p.vs,b,h))),motorLoss:p.motors.loss.map(f=>vn(p.vs,f,h)),...p.motors.gain?{motorGain:p.motors.gain.map(f=>f.map(b=>vn(p.vs,b,h)))}:{}}:{}});if(!o){let p=a(e);return h=>({ayMax:vn(p.vs,p.ayMax,h),...s(p,h)})}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/vn(i.vs,i.radius,p),d=p=>p>=u||c.vs.length<2?vn(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:d(p),...s(c,p)};let h=m(p),f=d(p);return h<f?{ayMax:h,...s(i,p)}:{ayMax:f,...s(c,p)}}}function K_(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 eA(e,t,r,n,o){let a=r>t?Math.max(2,Math.min(5,Math.floor(n))):1,s=[];for(let d=0;d<a;d++)s.push(e(a===1?t:t+(r-t)*d/(a-1)));let i=JS(s,t),c=[],l=a,u=(d,p)=>{let h=.5*(d+p),f=e(h);l++;let b=K_(i(h),f);s.splice(s.findIndex(g=>g.v>h),0,f),i=JS(s,t),b>o&&c.push({lo:d,hi:h,misfit:b},{lo:h,hi:p,misfit:b})},m=s.map(d=>d.v);for(let d=0;d+1<m.length&&l<n;d++)m[d+1]-m[d]>=1&&u(m[d],m[d+1]);if(m.length>1){let d=.5*(m[0]+m[1]);if(s.some(p=>p.v===d))for(let[p,h]of[[m[0],d],[d,m[1]]]){if(l>=n||h-p<1)break;let f=c.findIndex(b=>b.lo===p&&b.hi===h);f>=0&&c.splice(f,1),u(p,h)}}for(;l<n&&c.length>0;){let d=0;for(let b=1;b<c.length;b++)c[b].misfit>c[d].misfit&&(d=b);let{lo:p,hi:h,misfit:f}=c.splice(d,1)[0];if(f<=o)break;h-p<1||u(p,h)}return{anchors:s,at:i}}var H_=2,z_=.5,pc=Math.PI/180,tA=21,Y_={nCoarse:11,nSteer:13,nNorm:41,nAngle:45},W_={nCoarse:11,nSteer:13,nNorm:41,nAngle:61},j_=.005,U_=.05,Mg=e=>e<0?0:e>1?1:e;function X_(e,t,r,n){let o=e.massTotal,a=n.nSteer??7,s=(n.drivenFront?2:0)+(n.drivenRear?2:0),i=$e(e,0,0,r),c=Math.max(1,(i.FL+i.FR+i.RL+i.RR)/4),l=8*pc,u=0,m=(b,g,y)=>{for(let x=b;x<=g;x+=y){let k=Math.abs(t.Fy(x*pc,c,0));k>u&&(u=k,l=x*pc)}};m(1,45,1),m(Math.max(.1,l/pc-1),l/pc+1,.1);let d=[],p=[],h=[],f=[];for(let b=0;b<a;b++){let g=b/(a-1),y=l*(g+Math.sin(Math.PI/2*g))/2,x=Math.abs(t.Fy(y,c,0));d.push(4*x/o),p.push(s*jt(t,c,x,!1)/o),h.push(4*jt(t,c,x,!0)/o),f.push(-4*x*Math.sin(y)/o)}return d[0]=0,{ayMax:4*u/o,ay:d,axAccel:p,axDecel:h,axScrub:f,rollover:!1}}function q_(e,t,r){if(e.engine)return;let n=Do(e.params),o=hr(e.params),a=[];for(let s of["front","rear"]){if(!(s==="front"?t:r))continue;let[i,c]=s==="front"?["FL","FR"]:["RL","RR"];if(n[s]==="independent")a.push({wheels:[i],axle:s,motors:o[s]/2},{wheels:[c],axle:s,motors:o[s]/2});else if(n[s]==="diff")a.push({wheels:[i,c],axle:s,motors:o[s]});else return}return a.length>1?a:void 0}var Q_=.001;function rA(e,t){let r=e.flatMap((n,o)=>n===void 0?[]:[o]);return r.length===0?e.map(()=>t):e.map((n,o)=>{if(n!==void 0)return n;let a=r[0];for(let s of r)Math.abs(s-o)<Math.abs(a-o)&&(a=s);return e[a]})}var Z_=.01,J_=.05;function nA(e,t,r,n){let o=0,a=0;for(let s of e.motors){let i=r*s.tyreN[t]*e.axAccelN[t],c=s.share>0?s.share*n:0;i>c&&(o+=i-c,a+=c)}return{short:o,theirs:a}}function dc(e,t,r,n){let o=e.motors;if(!o)return 1/0;let a=n>=1?e.axDrive:n*e.axDrive,s=r*e.axAccelN[t],{short:i,theirs:c}=nA(e,t,r,a);if(!(i>0))return s;let l=e.motorLoss?.[t]??1;if(r===1&&n>=1||!o.every(h=>h.gain)){let h=r>=1?l:l/(r+l*(1-r));return Math.max(c,s-h*i)}let u=Math.min(s,oA(e,t,r,a)),m=nA(e,t,1,e.axDrive);if(!(m.short>0))return Math.max(c,u);let p=Math.max(m.theirs,e.axAccelN[t]-l*m.short)-Math.min(e.axAccelN[t],oA(e,t,1,e.axDrive));return Math.max(c,Math.min(s,u+p*(i/m.short)))}function oA(e,t,r,n){let o=e.motors,a=r*e.axAccelN[t],s=a;for(let i=0;i<=o.length+1;i++){let c=0,l=0,u=0;for(let d of o){let p=r*d.gain[t],h=r*d.tyreN[t]*e.axAccelN[t],f=d.share>0?d.share*n:0,b=h+p*(s-a);u+=Math.min(f,b),(p>0?b<=f:b<f)?(l+=p,c+=h-p*a):c+=f}if(!(u<s))return s;if(!(l<1))return 0;let m=c/(1-l);if(!(m<s))return s;s=m}return s}function Sg(e,t,r,n,o){if(!e.motors)return 1/0;let a=t.length-1;if(!(r<t[a]))return dc(e,a,n,o);let s=0,i=a;for(;i-s>1;){let u=s+i>>1;t[u]<=r?s=u:i=u}let c=(r-t[s])/(t[i]-t[s]),l=dc(e,s,n,o);return c===0?l:l+c*(dc(e,i,n,o)-l)}function Vr(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?W_:Y_),{nCoarse:c,nSteer:l,nAngle:u}=i,m=ln(0,1,i.nNorm).map(D=>Math.sin(Math.PI/2*D)),d=e.params,p=d.m.value,h=d.rho.value,f=d.fr_0.value,b=d.driven_wheels.value,g=d.power_scale.value,y=e.FG,x=It(d);s!==1&&(x.loadFactor=s);let k=Nr(d),v=tk(0,n?.vRes??(e.engine?z_:H_),e.vMax);v[v.length-1]<e.vMax&&v.push(e.vMax);let R=e.fRad.map(D=>D*b),M=e.fAxle,{drivenFront:A,drivenRear:F}=Oo(e),T=No(d,A,F),P=(D,N)=>{let Y=M?ht(M.vVehicle,D,N):NaN;return Number.isFinite(Y)?Y:1/0},S=r==="fast"?void 0:q_(e,A,F),w=hr(d),C=(D,N)=>{if(M){let H=P(M.fFront,N),W=P(M.fRear,N),X=D.map(Z=>(Z.axle==="front"?H:W)*(Z.motors/w[Z.axle])),ne=X.reduce((Z,xe)=>Z+xe,0);if(Number.isFinite(ne)&&ne>0)return X.map(Z=>Z/ne)}let Y=D.reduce((H,W)=>H+W.motors,0);return D.map(H=>H.motors/Y)},L=D=>{let N=D*D,{cl:Y,cw:H,A:W}=km(d,D,0,x),X=.5*h*-H*W*N,ne=.5*h*-Y*W*N,Z=f*(-ne+y);return X+Z},E=D=>{let N=L(D)/p*T.powerFactor,Y=L(D)/p*T.tractionFactor,H;if(e.engine){let X=L(D);H=Ya(e.engine,D,T.effective,X,g).accel-N}else if(M){let X=0;A&&(X+=P(M.fFront,D)),F&&(X+=P(M.fRear,D)),H=g*X/p*T.powerFactor}else{let X=ht(e.vVehicle,R,D),ne=g*X/p*T.powerFactor;H=Number.isFinite(ne)?ne:1/0}let W=Tm(d,D,o)/p*T.powerFactor;return{axDrag:N,axDragTyre:Y,axDrive:H,axPackCap:W,axPower:Math.min(H,W)}},_=v.map(E),O=e.vMax;for(let D=1;D<v.length;D++){let N=_[D].axDrive+_[D].axDrag;if(N>0)continue;let Y=_[D-1].axDrive+_[D-1].axDrag;O=Y>0?v[D-1]+(v[D]-v[D-1])*Y/(Y-N):v[D-1];break}let I=Math.min(e.vMax,(1+U_)*O),z=r==="fast"?X_:Vb,B=D=>{let N=S?E(D).axDrive:1/0,Y=S&&Number.isFinite(N)?C(S,D).map((ie,Re)=>({wheels:S[Re].wheels,cap:ie*N*p/T.tractionFactor})):void 0,H=z(x,k,D,{drivenFront:A,drivenRear:F,nSteer:l,yawDemandCn:a,axDrag:L(D)/p,...d.diffYaw?{diffYaw:!0}:{},...Y?{motorCaps:Y}:{}}),W=H.ay[0],X=H.ay[H.ay.length-1],ne=ie=>Math.min(Math.max(ie*H.ayMax,W),X),Z=m.map(ie=>Eu(H.ay,H.axAccel,ne(ie))*T.tractionFactor),xe=m.map(ie=>Eu(H.ay,H.axDecel,ne(ie))),de=m.map(ie=>Eu(H.ay,H.axScrub,ne(ie))*T.tractionFactor),be=H.axAccelWheels,U=H.axAccelHeld,ee=H.axAccelWheelsHeld,se=S&&Y&&be&&U?(()=>{let ie=S.map(ke=>H.ay.map((ae,ge)=>ke.wheels.reduce((fe,Ce)=>fe+be[ge][Ce],0))),Re=ie.map(ke=>{let ae=ke.map((ge,fe)=>ge/Math.max(H.axAccel[fe],Q_));return m.map(ge=>ht(H.ay,ae,ne(ge)))}),pe=H.ay.map((ke,ae)=>{let ge=ie.reduce((fe,Ce,Ae)=>fe+Math.max(0,Ce[ae]-Y[Ae].cap/p),0);return ge>Z_?Math.max(0,H.axAccel[ae]-U[ae])/ge:void 0}),ce=m.map(ke=>ht(H.ay,rA(pe,1),ne(ke))),Pe=ee?S.map((ke,ae)=>{let ge=H.ay.map((fe,Ce)=>{let Ae=ee[Ce],Ge=H.axAccel[Ce]-U[Ce];if(!(!Ae||!(Ge>J_)))return(ie[ae][Ce]-ke.wheels.reduce((Ne,Te)=>Ne+Ae[Te],0))/Ge});return m.map(fe=>ht(H.ay,rA(ge,0),ne(fe)))}):void 0;return{motorTyreN:Re,motorLoss:ce,...Pe?{motorGain:Pe}:{}}})():void 0;return{v:D,ayMax:H.ayMax,axAccelN:Z,axDecelN:xe,axScrubN:de,...se??{},atLock:H.atLock===!0}},V=r==="fast"?0:Math.min(qu,I),j=eA(B,V,I,c,i.anchorTol??j_),q=[],K=[];for(let D=0;D<v.length;D++){let N=v[D],{axDrag:Y,axDragTyre:H,axDrive:W,axPackCap:X,axPower:ne}=_[D],{ayMax:Z,axAccelN:xe,axDecelN:de,axScrubN:be,motorTyreN:U,motorLoss:ee,motorGain:se}=j.at(N),ie=S&&U&&ee?C(S,N):void 0,Re=S&&U&&ie?S.map((ae,ge)=>({wheels:ae.wheels,share:ie[ge],tyreN:U[ge],...se?{gain:se[ge]}:{}})):void 0,pe={v:N,ayMax:Z,axTyreAcc:xe[0],axTyreDec:de[0],axDrive:W,axPackCap:X,axPower:ne,axDrag:Y,axDragTyre:H,axAccelN:xe,axDecelN:de,axScrubN:be,...Re&&ee?{motors:Re,motorLoss:ee}:{}};q.push(pe);let ce=[],Pe=[];for(let ae=0;ae<u;ae++){let ge=Math.PI*ae/(u-1),fe=Z*Math.cos(ge),Ce=Mg(Math.abs(Math.cos(ge))),Ae=Math.min(ht(m,xe,Ce)+H,ne+Y,Sg(pe,m,Ce,1,1)+Y);ce.push({ax:Ae+ht(m,be,Ce),ay:fe,v:N})}for(let ae=u-1;ae>=0;ae--){let ge=Math.PI*ae/(u-1),fe=Z*Math.cos(ge),Ce=Mg(Math.abs(Math.cos(ge)));Pe.push({ax:ht(m,de,Ce)+Y+ht(m,be,Ce),ay:fe,v:N})}let ke=(ae,ge,fe)=>Array.from({length:tA},(Ce,Ae)=>({ax:ge+(fe-ge)*(Ae+1)/(tA+1),ay:ae,v:N}));K.push([...ce,...ke(-Z,ce[ce.length-1].ax,Pe[0].ax),...Pe,...ke(Z,Pe[Pe.length-1].ax,ce[0].ax)])}return{...cA(q,m),rows:q,norm:m,surf:K}}function ds(e,t){return e?.length?t.map(r=>Km(e,r)):t.map(()=>0)}function sA(e,t){let r=e?.[0]?.motors;if(!e||!r)return;let n={};return r.forEach((o,a)=>{o.wheels.length===1&&(n[o.wheels[0]]=t.map(s=>iA(e,s,i=>i.motors&&i.motors[a].share>0?i.motors[a].share*i.axDrive:0)))}),Object.keys(n).length?n:void 0}function Km(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 iA(e,t,r){let n=e.length-1;if(!(t>e[0].v))return r(e[0]);if(t>=e[n].v)return r(e[n]);let o=0,a=n;for(;a-o>1;){let l=o+a>>1;e[l].v<=t?o=l:a=l}let s=r(e[o]),i=r(e[a]);if(!Number.isFinite(s)||!Number.isFinite(i))return Math.max(s,i);let c=(t-e[o].v)/(e[a].v-e[o].v);return s+c*(i-s)}function cA(e,t){let r=e[e.length-1].v,n=f=>{if(f<=e[0].v)return{i0:0,i1:0,t:0};if(f>=r)return{i0:e.length-1,i1:e.length-1,t:0};let b=0,g=e.length-1;for(;g-b>1;){let y=b+g>>1;e[y].v<=f?b=y:g=y}return{i0:b,i1:g,t:(f-e[b].v)/(e[g].v-e[b].v)}},o=f=>{let{i0:b,i1:g,t:y}=n(f);return{a:e[b],b:e[g],t:b===g?0:y}},a=(f,b,g)=>f===0||b===g?b:b+f*(g-b),s=(f,b,g,y)=>f===0?ht(t,b,y):a(f,ht(t,b,y),ht(t,g,y)),i=(f,b)=>b>=1?f.axPower:Math.min(b*f.axDrive,f.axPackCap),c=({a:f,b,t:g},y,x)=>f.axScrubN?x*s(g,f.axScrubN,b.axScrubN,y):0,l=f=>f.axDragTyre??f.axDrag,u=({a:f,b,t:g},y,x)=>{let k=x*a(g,f.ayMax,b.ayMax);return k>0?Mg(y/k):1},m=({a:f,b,t:g},y,x,k)=>a(g,Sg(f,t,y,x,k),g===0?0:Sg(b,t,y,x,k))+a(g,f.axDrag,b.axDrag),d=(f,b,g=1,y=1)=>{let{a:x,b:k,t:v}=f,R=u(f,b,g),M=g*s(v,x.axAccelN,k.axAccelN,R)+a(v,l(x),l(k)),A=a(v,i(x,y),v===0?0:i(k,y))+a(v,x.axDrag,k.axDrag);return x.motors?Math.min(M,A,m(f,R,g,y))+c(f,R,g):Math.min(M,A)+c(f,R,g)},p=(f,b,g=1,y=1)=>{let{a:x,b:k,t:v}=f,R=u(f,b,g),M=s(v,x.axDecelN,k.axDecelN,R);return(y===1||M>0?g*M:y*g*M)+a(v,x.axDrag,k.axDrag)+c(f,R,g)},h=({a:f,b,t:g},y,x=1)=>{let k=t.length-1,v=f.axAccelN,R=b.axAccelN,M=f.axDecelN,A=b.axDecelN,F=f.axScrubN,T=b.axScrubN,P=I=>v[I]+g*(R[I]-v[I]),S=I=>M[I]+g*(A[I]-M[I]),w=I=>F?x*(F[I]+g*(T[I]-F[I])):0,C=a(g,f.ayMax,b.ayMax),L=a(g,f.axDrag,b.axDrag),E=a(g,l(f),l(b)),_=a(g,f.axPower,b.axPower),O=f.motors?I=>a(g,dc(f,I,x,1),g===0?0:dc(b,I,x,1)):null;for(let I=k;I>=0;I--){let z=O?Math.min(x*P(I)+E,_+L,O(I)+L)+w(I):Math.min(x*P(I)+E,_+L)+w(I),B=x*S(I)+L+w(I);if(!(y<=z+1e-6&&y>=B-1e-6))continue;if(I===k)return t[I]*x*C;let V=(D,N,Y)=>{if(Y(N))return 1;let H=(D-y)/(D-N);return H>0?Math.min(H,1):0},j=D=>y<=D+1e-6,q=D=>y>=D-1e-6,K=Math.min(V(x*P(I)+E+w(I),x*P(I+1)+E+w(I+1),j),V(_+L+w(I),_+L+w(I+1),j),V(x*S(I)+L+w(I),x*S(I+1)+L+w(I+1),q),O?V(O(I)+L+w(I),O(I+1)+L+w(I+1),j):1);return(t[I]+K*(t[I+1]-t[I]))*x*C}return 0};return{vMax:r,axAccel:(f,b,g=1,y=1)=>d(o(f),b,g,y),axDecel:(f,b,g=1,y=1)=>p(o(f),b,g,y),ay:(f,b,g=1)=>h(o(f),b,g),scrub:(f,b,g=1)=>{let y=o(f);return c(y,u(y,b,g),g)},power:(f,b,g=1)=>{let y=o(f),{a:x,b:k,t:v}=y,M=(Number.isFinite(x.axPower)&&Number.isFinite(k.axPower)?a(v,x.axPower,k.axPower):Math.max(x.axPower,k.axPower))+a(v,x.axDrag,k.axDrag);return x.motors?Math.min(M,m(y,u(y,b,g),g,1)):M}}}function eN(e,t,r){let n=e.params,o=n.m.value,{drivenFront:a,drivenRear:s}=Oo(e),i=No(n,a,s);return c=>Tm(n,c,t,r)/o*i.powerFactor}function fc(e,t,r,n){let o=eN(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{...cA(a,e.norm),rows:a,norm:e.norm}}var tN=[-.2,-.08,0,.06,.12,.2,.3];function lA(e,t=!1,r="twoTrack",n,o,a=tN){let s=[...new Set([...a,0])].sort((h,f)=>h-f),i=s.map(h=>Vr(e,t,r,n,o,h)),c=i[s.indexOf(0)],l=s[0],u=s[s.length-1],m=h=>{if(h<=l)return{i:0,t:0};if(h>=u)return{i:s.length-1,t:0};let f=0;for(;f<s.length-2&&s[f+1]<=h;)f++;return{i:f,t:(h-s[f])/(s[f+1]-s[f])}},d=h=>{let f=b=>{let{i:g,t:y}=m(b);return{a:h[g],b:h[Math.min(h.length-1,g+1)],t:y}};return b=>{let{a:g,b:y,t:x}=f(b);if(x===0)return g;let k=(v,R)=>v+x*(R-v);return{vMax:g.vMax,axAccel:(v,R,M=1,A=1)=>k(g.axAccel(v,R,M,A),y.axAccel(v,R,M,A)),axDecel:(v,R,M=1,A=1)=>k(g.axDecel(v,R,M,A),y.axDecel(v,R,M,A)),ay:(v,R,M=1)=>k(g.ay(v,R,M),y.ay(v,R,M)),scrub:(v,R,M=1)=>k(g.scrub?.(v,R,M)??0,y.scrub?.(v,R,M)??0)}}},p=h=>h<l||h>u;return{anchors:s,steady:c,clamps:p,at:d(i),atSoc(h,f,b){let g=i.map(y=>fc(y,h,f,b));return{anchors:s,steady:g[s.indexOf(0)],clamps:p,at:d(g)}}}}function uA(e,t,r,n="twoTrack",o){let a=[...new Set([...t,1])].sort((i,c)=>i-c),s=a.map(i=>i===1?r:Vr(e,!1,n,o,void 0,0,i));return{...aA(a,s),atSoc:(i,c,l)=>aA(a,s.map(u=>fc(u,i,c,l)))}}function aA(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 h=0;for(;h<r-1&&e[h+1]<=p;)h++;if(o=h,p===e[h])return;a=h+1;let f=e[h],b=e[h+1];if(r<2){n=2,c=(p-f)/(b-f),i=1-c;return}s=h===0?2:h+1===r||p-e[h-1]<e[h+2]-p?h-1:h+2;let g=e[s];n=3,i=(p-b)*(p-g)/((f-b)*(f-g)),c=(p-f)*(p-g)/((b-f)*(b-g)),l=(p-f)*(p-b)/((g-f)*(g-b))},m=p=>{let h=p(t[o]);if(n===1)return h;let f=p(t[a]);if(n===2)return i*h+c*f;let b=i*h+c*f+l*p(t[s]);return Math.min(Math.max(h,f),Math.max(Math.min(h,f),b))},d=(p,h,f,b,g)=>{if(u(p),n===1||f===0)return m(k=>g(k,f));let y=m(k=>k.ay(h,0,b));if(!(y>0))return m(k=>g(k,f));let x=f/y;return m(k=>g(k,x*k.ay(h,0,b)))};return{anchors:e,axAccel:(p,h,f,b=1,g=1)=>d(p,h,f,b,(y,x)=>y.axAccel(h,x,b,g)),axDecel:(p,h,f,b=1,g=1)=>{let y=x=>d(p,h,f,b,(k,v)=>k.axDecel(h,v,b,x));return g===1?y(1):rg(y(g),y(1),g)},scrub:(p,h,f,b=1)=>d(p,h,f,b,(g,y)=>g.scrub?.(h,y,b)??0),ay:(p,h,f,b=1)=>{if(u(p),n===1||f===0)return m(k=>k.ay(h,f,b));let g=k=>f>0?k.axAccel(h,0,b):-k.axDecel(h,0,b),y=m(g);if(!(y>0))return m(k=>k.ay(h,f,b));let x=f/y;return m(k=>k.ay(h,x*g(k),b))}}}var mA=new WeakMap;function Ag(e,t){let r=mA.get(e);if(!r){let n=cn(e).regen?cg(t??Xt(e)):void 0;r={inp:It(e),ev:Nr(e),...n?{regen:n}:{}},mA.set(e,r)}return r}function wg(e,t,r){let n=Ag(e,r);return kg(n.inp,n.ev,t,n.regen?{regen:n.regen}:{})}function Fg(e){let t=Et(e);if(t.mode!=="hydraulic")return null;let r=a=>a.heat?{heat:Bh(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 rN(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 Cg(e,t,r,n,o,a=Ut){if(!e)return null;let s=rN(t);return{...e.front?{front:Cu(e.front.heat,e.front.discs,s.front,r,n,o.front,a)}:{},...e.rear?{rear:Cu(e.rear.heat,e.rear.discs,s.rear,r,n,o.rear,a)}:{}}}var nN=.5,oN=.02,aN=6,Hm=9,pA=1e-9,sN={FL:0,FR:0,RL:0,RR:0};function Tg(e){return e?[...new Set([...e.padCurve.factor,1])].sort((t,r)=>t-r):[1]}function iN(e,t,r){let n=Dr(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 dA(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 fA(e,t,r,n,o=()=>0){let a=Array.from({length:Hm},(m,d)=>r*d/(Hm-1)),s=Bi(),{front:i,rear:c}=n,l=a.map(m=>{let d=o(m),p=f=>mn(f,t,m,s).limitAt(0,0,sN,d).ax,h=p(e);return i.map(f=>c.map(b=>{if(f===1&&b===1)return 1;let g=h<0?p(iN(e,f,b))/h:1;return Math.abs(g-1)<pA?1:g}))}),u=a[1]-a[0];return{share(m,d,p){if(d===1&&p===1)return 1;let h=u>0?Math.min(Hm-2,Math.max(0,Math.floor(m/u))):0,f=u>0?Math.min(1,Math.max(0,(m-a[h])/u)):0,b=dA(i,d),g=dA(c,p),y=k=>{let v=l[k],R=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]),F=v[R][g.i]+g.t*(v[R][M]-v[R][g.i]);return A+b.t*(F-A)},x=y(h)+f*(y(Math.min(Hm-1,h+1))-y(h));return Math.abs(x-1)<pA?1:x}}}function cN(e,t){let{front:r,rear:n}=t;return(o,a)=>e.share(a,r?.[o]??1,n?.[o]??1)}var lN=e=>(e.front??[]).every(t=>t===1)&&(e.rear??[]).every(t=>t===1);function hA(e,t,r){let n=e(),o=1,a=t(n);if(lN(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<aN;c++){let l=e(cN(r,s));o++;let u=Math.abs(l.laptime-n.laptime);if(n=l,u<oN){i=!0;break}a=t(n);let m=(h,f)=>h&&f?h.map((b,g)=>b+nN*((f[g]??1)-b)):h,d=m(s.front,a.front),p=m(s.rear,a.rear);s={...d?{front:d}:{},...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}=Oo(e),s=No(n,o,a).effective,i=n.power_scale.value,{up:c,down:l}=eb(r.engine.gearbox),u=r.engine.idleRpm,m=(d,p,h)=>(i*r.force(d,p)+h)/(s+r.inertiaMass(d,p));return{count:r.gears.length,up:c,down:l,kept:tb(r.engine.gearbox),limitRpm:r.engine.limitRpm,best:d=>Ya(r,d,s,Km(t,d)*s,i).gear,share:(d,p)=>{let h=Km(t,d),f=h*s,b=Ya(r,d,s,f,i);if(p===b.gear)return 1;let g=b.accel-h;return g>0?Math.min(1,Math.max(0,(m(d,p,f)-h)/g)):0},rpm:(d,p)=>r.slipping(d,p)?u:r.rpm(d,p),vIdle:d=>r.gears[d]?.vIdle??0}}var bA=new WeakMap;function Lg(e){let t=bA.get(e.ggv);return t===void 0&&(t=Wn(e.vehicle,e.ggv.rows)??null,bA.set(e.ggv,t)),t??void 0}function uN(e){return e.gear&&e.engineRpm&&e.shifting?{gear:e.gear,rpm:e.engineRpm,shifting:e.shifting}:{}}function mN(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}:{},...uN(t)}}var Ym=class extends Error{constructor(t){super(t),this.name="EventError"}};function pN(e,t){let{ggv:r}=t,n=At(t.numerics),o=n.accelStep,a=Math.max(1,Math.round(e.distance/o)),s=ss(r,new Array(a+1).fill(0),n);s[0].v=e.vStart??0;for(let h=0;h<s.length-1;h++){let f=s[h],b=s[h+1];f.v>=b.v||(f.ax=r.axAccel(f.v,0),b.v=Math.min(r.vMax,Math.sqrt(Math.max(0,f.v*f.v+2*f.ax*o))))}let i=Lg(t),c=i?Am(s.map(h=>h.v),new Array(a).fill(o),!1,i,(h,f,b)=>r.axAccel(f,0,1,b)):void 0;if(c){for(let h=0;h<=a;h++)s[h].v=c.v[h];for(let h=0;h<a;h++)s[h].ax=(s[h+1].v*s[h+1].v-s[h].v*s[h].v)/(2*o)}let l=0;for(let h=0;h<a;h++){let f=s[h].v+s[h+1].v;f>0&&(l+=2*o/f)}let u=s.slice(0,a).map(h=>h.v),m=s.slice(0,a).map(h=>h.ax),d=new Array(a).fill(o),p=d.map((h,f)=>f*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:AA(t,d,[...u,s[a].v],m,1)}}function dN(e,t){let r=Math.max(1,Math.round(e.laps??1)),[n]=ss(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=AA(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 Wm(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 fN(e,t){let r=e.distance!=null?t.v_limit_endurance?.value??0:0;return r>0?r/3.6:void 0}function hN(e,t){if(e.distance==null||pt(t.motorModel))return 0;let r=t.endurance_reserve?.value??0;return r>0?Math.min(r,95)/100:0}var gA=1;function kA(e,t,r,n){return{v:r.v,ax:r.ax,ay:r.ay,ds:t.ds,axDrag:ds(e.ggv.rows,r.v),...r.axScrub?{axScrub:r.axScrub}:{},axGrade:n,...t.bank?{bank:t.bank}:{}}}var yA=new WeakMap;function MA(e){let t=e.vehicle.params;if(!t.brakeFade)return null;let r=yA.get(t);if(r===void 0){let n=Fg(t),o=n?Et(t):null;if(!n||!o||o.mode!=="hydraulic")r=null;else{let a=Ag(t,e.vehicle),s=e.ggv.rows,i=fA(a.inp,a.ev,e.vehicle.vMax,{front:Tg(o.hydraulic.front.heat),rear:Tg(o.hydraulic.rear.heat)},c=>ds(s,[c])[0]);r={discs:n,table:i}}yA.set(t,r)}return r}function bN(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?QS(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}:{}}):Kt(fc(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=as(t.gradient,t.npts),d=g=>n.motorThermal?hS(e.vehicle,t.ds,e.energyOpts??sn,y=>u(y,g),o,a,m,t.bank).lap:u(void 0,g),p=MA(e);if(!p)return d();let h=lc(n),f=r.discC??{front:h,rear:h};return hA(d,g=>{let y=Cg(p.discs,wg(n,kA(e,t,g,m),e.vehicle),g.v,t.ds,f,h);return{...y?.front?{front:y.front.padFactor}:{},...y?.rear?{rear:y.rear.padFactor}:{}}},p.table).lap}function gN(e,t){let r=fN(e,t.vehicle.params),n=hN(e,t.vehicle.params);return n>0?RN(e,t,n,r):hc(e,t,r)}function zm(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 xA=5,yN=.1,xN=.005,RA=12;function RN(e,t,r,n){let o=hc(e,t,n),a=1,s=(h,f,b)=>({...h,energyTarget:{reserve:r,capKmh:f===void 0?null:f*3.6,met:b,solves:a}}),i=zm(o,r);if(i>=0)return s(o,n,!0);let c=Math.min(n??1/0,t.ggv.vMax),l=c/2,u=hc(e,t,l);a++;let m=zm(u,r);for(;m<0&&l>xA&&a<RA;)c=l,i=m,l=Math.max(xA,l/2),u=hc(e,t,l),a++,m=zm(u,r);if(m<0)return s(u,l,!1);let p=vN(h=>{let f=hc(e,t,h);return{run:f,margin:zm(f,r)}},{lo:l,hi:c,atLo:{run:u,margin:m},fHi:i},RA-a);return a+=p.solves,s(p.run,p.cap,!0)}function vN(e,t,r){let{lo:n,hi:o}=t,a=t.atLo,s=a.margin,i=t.fHi,c=0,l=0;for(;l<r&&o-n>yN&&a.margin>xN;){let u=o-n,m=Math.min(o-.05*u,Math.max(n+.05*u,n+s*u/(s-i))),d=e(m);l++,d.margin>=0?(n=m,a=d,s=d.margin,c===1&&(i/=2),c=1):(o=m,i=d.margin,c===-1&&(s/=2),c=-1)}return{cap:n,run:a.run,solves:l}}function SA(e,t,r){return r===0?e:e&&!t}function hc(e,t,r){let n=t.track;if(!n)throw new Ym(`Event "${e.id}" needs a track.`);let o=Wm(e,n),a=e.standingStart??t.standingStart??!1,s=D=>SA(a,n.closed,D),i=t.vehicle.params,c=jr(is(i)),l=c.capacityAh,u=pt(i.motorModel)?1:i.soc.value,m=lc(i),d=Cm(c,m),p=0,h=0,f=0,b=0,g=[],y=!1,x=-1/0,k=0,v=0,R=!1,M=-1/0,A=0,F=0,T=-1/0,P=(D,N,Y=1)=>{D.tempMaxC>T&&(T=D.tempMaxC),D.motorTempMaxC!==void 0&&(y=!0,R=!0,D.motorTempMaxC>x&&(x=D.motorTempMaxC),D.motorTempMaxC>M&&(M=D.motorTempMaxC),k+=(D.motorDerateTimeFrac??0)*N,A+=(D.motorDerateTimeFrac??0)*N,v+=(D.motorLossKwh??0)/Y,F+=(D.motorLossKwh??0)/Y)},S=null,w,C=Fg(i),L={front:m,rear:m},E=null,_=MA(t)!==null,O=(D,N)=>_&&(Math.abs(D.front-N.front)>gA||Math.abs(D.rear-N.rear)>gA),I=(D,N,Y)=>{let H=lg(i,D,N);if(E&&E.launch===Y&&!SN(H,E.pw)&&!O(L,E.discC))return E.lap;let W=bN(t,n,{soc:D,packTempC:N,launched:Y,...r?{vCeiling:r}:{},..._?{discC:L}:{}});return E={pw:H,launch:Y,discC:L,lap:W},W},z=as(n.gradient,n.npts),B=(D,N,Y)=>cs(t.vehicle,n.ds,D.v,D.ax,t.energyOpts,N,Y,void 0,z,void 0,{ay:D.ay,bank:n.bank,...D.axScrub?{scrub:D.axScrub}:{}}),V=new WeakMap,j=(D,N)=>{let Y=V.get(D);return Y||(Y=wg(i,kA(t,n,D,z),t.vehicle),V.set(D,Y)),Cg(C,Y,D.v,n.ds,N,m)},q=(D,N,Y)=>{let H=`${(100*Y/n.npts).toFixed(0)} % of the way through lap ${D+1}`,W=N.cutoffAt>=0&&N.cutoffAt<=N.emptyAt;return{lapsCompleted:D,lapsAsked:o,why:W?`the pack reached its ${c.voltageFloor.toFixed(0)} V cut-off ${H}`:`the pack ran out ${H}`}};for(let D=0;D<o;D++){if(u<=0){w={lapsCompleted:D,lapsAsked:o,why:"the pack was empty"};break}let N=s(D),Y=u,H=d;R=!1,M=-1/0,A=0,F=0,T=-1/0;let W=I(u,d,N),X=B(W,u,d);if(X.emptyAt>=0){w=q(D,X,X.emptyAt);break}let Z=I(X.socEnd,X.tempEndC,N).laptime-W.laptime,xe,de,be,U,ee=d,se=-1,ie=null,Re=1;if(Z<=Pg)xe=W.laptime,de=X.net,be=X.loss,U=X.chargeAh,ee=X.tempEndC,P(X,xe),Re=1;else{let ce=Math.min(kN,Math.max(2,Math.ceil(Z/(2*Pg))));Re=ce;let Pe=u,ke=d;xe=0,de=0,be=0,U=0;for(let ae=0;ae<ce;ae++){let ge=I(Pe,ke,N),fe=B(ge,Pe,ke),Ce=fe.emptyAt>=0?fe.emptyAt/n.npts:1;if(Ce*ce<1){se=Math.round(n.npts*(ae/ce+Ce)),ie=fe;break}if(xe+=ge.laptime/ce,P(fe,ge.laptime/ce,ce),de+=fe.net/ce/Ce,be+=fe.loss/ce/Ce,U+=fe.chargeAh/ce/Ce,Pe-=fe.chargeAh/ce/Ce/l,ke+=(fe.tempEndC-ke)/ce,Pe<=0){se=Math.round(n.npts*(ae+1)/ce),ie=fe;break}}if(ee=ke,se>=0&&ie){w=q(D,ie,se);break}u=Pe}p+=xe,h+=de,f+=be,b+=U,Z<=Pg&&(u=X.socEnd),d=ee;let pe=C?j(W,L):null;pe&&(L={front:pe.front?.endC??L.front,rear:pe.rear?.endC??L.rear}),g.push({lap:D+1,time:xe,elapsed:p,entryTime:W.laptime,socStart:Y,socEnd:u,packTempStartC:H,packTempEndC:d,packTempMaxC:Number.isFinite(T)?T:H,energyKwh:de,lossKwh:be,chargeAh:U,launched:N,substeps:Re,...r?{vCeiling:r}:{},...R?{motor:{peakWindingC:M,derateTimeFrac:xe>0?A/xe:0,lossKwh:F}}:{},...pe?{brakes:{...pe.front?{front:vA(pe.front)}:{},...pe.rear?{rear:vA(pe.rear)}:{}}}:{}}),S=W}if(!S){let D=Lg(t);S=Kt(fc(t.ggv,t.vehicle,u),n,t.numerics,{standingStart:a,...t.load?{load:t.load.atSoc(t.vehicle,u)}:{},...D?{shifts:D}:{}}),w=w??{lapsCompleted:0,lapsAsked:o,why:"the pack was empty"}}let K=g.length;return{id:e.id,label:e.label,kind:e.kind,time:p,distance:n.length*K,laps:K,lapTime:S.laptime,trace:mN(n,S),energy:{consumed:h,loss:f,...pt(i.motorModel)?{}:{native:{value:b,unit:"Ah"}},remainingFraction:pt(i.motorModel)?1:u,...y?{motor:{peakWindingC:x,derateTimeFrac:p>0?k/p:0,lossKwh:v}}:{}},lapLog:g,...w?{incomplete:w}:{}}}var Pg=.05;function vA(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 kN=4,MN=.001;function SN(e,t){return e===t?!1:!Number.isFinite(e)||!Number.isFinite(t)?!0:Math.abs(e-t)>MN*Math.max(1,Math.abs(t))}function AA(e,t,r,n,o,a){return AN(e,t,o,()=>({v:r,ax:n,...a?{lateral:a}:{}}))}function AN(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=cs(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 pt(e.vehicle.params.motorModel)?{consumed:s,loss:i,remainingFraction:1}:{consumed:s,loss:i,native:{value:c,unit:"Ah"},remainingFraction:a}}function wA(e,t){switch(e.kind){case"straightLineAccel":return pN(e,t);case"constantRadius":return dN(e,t);case"trackLap":return gN(e,t)}}function Dg(e,t){let r={};for(let n of e)r[n.id]=wA(n,t);return r}function FA(e,t){if(e.kind!=="trackLap")return e;let{distance:r,...n}=e;return{...n,laps:Math.max(1,Math.round(t))}}function Vo(e,t,r,n,o="twoTrack",a){let s=1/0,i=-1/0;for(let d of r){let p=sc(d);if(!p)continue;let h=tS(p,Kt(t,d,n).v);h&&(s=Math.min(s,h.lo),i=Math.max(i,h.hi))}if(!(i>=s))return;let c=rS({lo:s,hi:i}),l=c.join(","),u=a?.get(l);if(u)return u;let m=uA(e,c,t,o);return a?.set(l,m),m}var bc=e=>e.distance/Math.max(1,e.laps);function gc(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 wN=e=>e.v.map(t=>t*3.6),FN=e=>e.ax.map(t=>t/9.81),CN=e=>e.ay.map(t=>t/9.81),TN=e=>e.ay.map((t,r)=>e.v[r]>1e-6?t/(e.v[r]*e.v[r]):0),jm=(e,t,r)=>e?.slice()??new Array(t.s.length).fill(r),PN=e=>jm(e.z,e,0),LN=e=>e.gradient?e.gradient.map(t=>100*Math.tan(t*Math.PI/180)):jm(void 0,e,0),DN=e=>jm(e.bank,e,0),EN=e=>jm(e.mu,e,1);function IN(e){let t=e.s.length,r=gc(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 Eg=[{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 CA(e){let t=gc(e);return{ds:t,vars:{s:e.s,ds:t,t:IN(e),v:e.v,speed:wN(e),ax:e.ax,ay:e.ay,axg:FN(e),ayg:CN(e),curv:TN(e),z:PN(e),grade:LN(e),bank:DN(e),grip:EN(e)}}}function Um(e){let t=e.rows?sA(e.rows,e.v):void 0;return{v:e.v,ax:e.ax,ay:e.ay,ds:e.ds,...e.rows?{axDrag:ds(e.rows,e.v)}:{},...e.axScrub?{axScrub:e.axScrub}:{},axGrade:as(e.gradient,e.v.length),...e.bank?{bank:e.bank}:{},...e.loadFactor?{loadFactor:e.loadFactor}:{},...e.mu?.some(r=>r!==1)?{mu:e.mu}:{},...t?{wheelMotor:t}:{}}}function TA(e,t){return Um({v:e.v,ax:e.ax,ay:e.ay,ds:gc({s:e.s,length:t}),gradient:e.gradient,bank:e.bank,loadFactor:e.loadFactor})}function PA(e,t){let r=It(e);return{pastTurnover:zS(r,Nr(e),t),...e.aeroModel?{aeroOutside:HS(r,t)}:{}}}var Xm="Flying lap";function Ig(e,t){return e.kind!=="trackLap"||e.label!==Xm?e.label:e.standingStart??t?"Run":e.label}function _N(e){let t=It(e);return{yawInertia:t.yawInertia??0,massTotal:t.massTotal,wheelbase:t.wheelbase/1e3}}function NN(e,t,r){let n=e.params,o=n.ggvMode??"twoTrack",a=n.quasiTransient?lA(e,!1,o):null,s=a?a.steady:Vr(e,!1,o),i=t?Vo(e,s,[t],r,o):void 0;return{ggv:s,...a?{yaw:{family:a,car:_N(n)}}:{},...i?{load:i}:{}}}function ON(e,t){let r=t.lapCounts,n=t.standingStart??!1,o=!1,a=e.events.map(s=>{let i=r?.[s.id]!=null?FA(s,r[s.id]):s,c=Ig(i,n),l=c===i.label?i:{...i,label:c};return l!==s&&(o=!0),l});return o?a:e.events}function VN(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=Wm(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 BN(e,t){for(let[r,n]of Object.entries(e))n.trace&&(e[r]={...n,...PA(t,TA(n.trace,bc(n)))})}function yc(e,t,r={}){let n=Xt(e),o=NN(n,r.track,r.numerics),{ggv:a}=o,s=Dg(ON(t,r),{vehicle:n,...o,track:r.track,energyOpts:cn(e,r.energyOpts),numerics:r.numerics,standingStart:r.standingStart});return VN(s,t,r),BN(s,n.params),{name:e.name,rulesetId:t.id,events:s,ggv:a}}function _g(e){return{...e,ggv:{rows:e.ggv.rows,vMax:e.ggv.vMax,surf:e.ggv.surf}}}var Ng=["<","<=",">",">=","==","!="],Je=class extends Error{at;constructor(t,r){super(t),this.name="ExprError",this.at=r}},xc=e=>e>="0"&&e<="9",LA=e=>/[A-Za-z_]/.test(e),$N=e=>/[A-Za-z0-9_]/.test(e);function GN(e){let t=[],r=0;for(;r<e.length;){let n=e[r];if(n===" "||n===" "||n===`
|
|
224
|
+
`||n==="\r"){r++;continue}if(xc(n)||n==="."&&xc(e[r+1]??"")){let o=r;for(;r<e.length&&(xc(e[r])||e[r]===".");)r++;if(e[r]==="e"||e[r]==="E"){let i=r;if(r++,(e[r]==="+"||e[r]==="-")&&r++,xc(e[r]??""))for(;r<e.length&&xc(e[r]);)r++;else r=i}let a=e.slice(o,r),s=Number(a);if(!Number.isFinite(s))throw new Je(`"${a}" is not a number`,o);t.push({t:"num",value:s,at:o});continue}if(LA(n)){let o=r;for(;;){for(;r<e.length&&$N(e[r]);)r++;if(e[r]==="."&&LA(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(Ng.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 Je(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 Je(`"${n}" is not something this expression can contain`,r)}return t.push({t:"end",at:e.length}),t}function Og(e){let t=GN(e),r=0,n=()=>t[r],o=f=>{let b=n();return b.t==="op"&&b.value===f},a=f=>o(f)?(r++,!0):!1,s=(f,b)=>{if(!a(f))throw new Je(`Expected ${b} here`,n().at)};function i(){let f=c(),b=n();if(b.t!=="op"||!Ng.includes(b.value))return f;r++;let g={kind:"binary",op:b.value,left:f,right:c(),at:b.at},y=n();if(y.t==="op"&&Ng.includes(y.value))throw new Je("Comparisons do not chain \u2014 write and(a < b, b < c)",y.at);return g}function c(){let f=l();for(;;){let b=n().at;if(a("+"))f={kind:"binary",op:"+",left:f,right:l(),at:b};else if(a("-"))f={kind:"binary",op:"-",left:f,right:l(),at:b};else return f}}function l(){let f=u();for(;;){let b=n().at;if(a("*"))f={kind:"binary",op:"*",left:f,right:u(),at:b};else if(a("/"))f={kind:"binary",op:"/",left:f,right:u(),at:b};else return f}}function u(){return a("-")?{kind:"unary",op:"-",arg:u()}:a("+")?u():m()}function m(){let f=d(),b=n().at;return a("^")?{kind:"binary",op:"^",left:f,right:u(),at:b}:f}function d(){let f=n();if(f.t==="num")return r++,{kind:"num",value:f.value};if(f.t==="name"){if(r++,a("(")){let b=[];if(!o(")"))do b.push(i());while(a(","));return s(")","a closing bracket"),{kind:"call",name:f.value,args:b,at:f.at}}return{kind:"var",name:f.value,at:f.at}}if(a("(")){let b=i();return s(")","a closing bracket"),b}throw f.t==="end"?new Je("The expression ends before it is finished",f.at):new Je(`"${f.value}" cannot start a value`,f.at)}let p=i(),h=n();if(h.t!=="end")throw new Je(`"${h.value}" is left over \u2014 check for a missing operator`,h.at);return p}function Vg(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 KN(e){let t=1;for(let r of e)Array.isArray(r)&&(t=Math.max(t,r.length));return t}function er(e,t){if(e.every(a=>typeof a=="number"))return t(...e);let r=KN(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 et=(e,t)=>({arity:e,call:r=>er(r,t)}),Bo=e=>e!==0&&!Number.isNaN(e),Br=e=>e?1:0;function DA(e,t,r){let n=EA(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 EA(e,t,r){if(!e.ds||e.ds.length===0)throw new Je(`${r}() needs to know the sample spacing, and this context has none`,t);return e.ds}var qm={abs:et(1,Math.abs),sqrt:et(1,Math.sqrt),sign:et(1,Math.sign),floor:et(1,Math.floor),ceil:et(1,Math.ceil),round:et(1,Math.round),exp:et(1,Math.exp),log:et(1,Math.log),sin:et(1,Math.sin),cos:et(1,Math.cos),tan:et(1,Math.tan),atan:et(1,Math.atan),atan2:et(2,Math.atan2),hypot:et(2,Math.hypot),min:et(2,Math.min),max:et(2,Math.max),clamp:et(3,(e,t,r)=>Math.min(r,Math.max(t,e))),if:et(3,(e,t,r)=>Bo(e)?t:r),and:et(2,(e,t)=>Br(Bo(e)&&Bo(t))),or:et(2,(e,t)=>Br(Bo(e)||Bo(t))),not:et(1,e=>Br(!Bo(e))),finite:et(1,e=>Br(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=DA(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)=>DA(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=EA(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}}},fs={g:9.81,pi:Math.PI,e:Math.E,nan:NaN,inf:1/0},vc={fleetmin:"min",fleetmax:"max"};function $o(e){switch(e.kind){case"call":return Object.hasOwn(vc,e.name)||e.args.some($o);case"unary":return $o(e.arg);case"binary":return $o(e.left)||$o(e.right);default:return!1}}var HN=e=>typeof e=="number"?`${e}`:`between ${e[0]} and ${e[1]}`;function zN(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 YN(e,t){let r=t.map(c=>({k:c,d:zN(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 $r(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(fs,e.name))return fs[e.name];let r=[...Object.keys(t.vars),...Object.keys(fs)].sort();throw new Je(YN(e.name,r),e.at)}case"unary":return er([$r(e.arg,t)],r=>-r);case"binary":{let r=$r(e.left,t),n=$r(e.right,t);switch(e.op){case"+":return er([r,n],(o,a)=>o+a);case"-":return er([r,n],(o,a)=>o-a);case"*":return er([r,n],(o,a)=>o*a);case"/":return er([r,n],(o,a)=>a===0?0:o/a);case"^":return er([r,n],(o,a)=>o**a);case"<":return er([r,n],(o,a)=>Br(o<a));case"<=":return er([r,n],(o,a)=>Br(o<=a));case">":return er([r,n],(o,a)=>Br(o>a));case">=":return er([r,n],(o,a)=>Br(o>=a));case"==":return er([r,n],(o,a)=>Br(o===a));case"!=":return er([r,n],(o,a)=>Br(o!==a))}break}case"call":{let r=Object.hasOwn(vc,e.name)?vc[e.name]:void 0;if(r){if(!t.fleet)throw new Je(`${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 Je(`${e.name}() takes 1 argument, not ${e.args.length}`,e.at);return t.fleet(e.args[0],r,e.at)}let n=Object.hasOwn(qm,e.name)?qm[e.name]:void 0;if(!n){let s=[...Object.keys(qm),...t.fleet?Object.keys(vc):[]];throw new Je(`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 Je(`${e.name}() takes ${HN(n.arity)} argument${o===1&&a===1?"":"s"}, not ${e.args.length}`,e.at);return n.call(e.args.map(s=>$r(s,t)),t)}}throw new Je("Unreachable node",0)}var hs=e=>Number.isFinite(e)?e:NaN,Bg=[{name:"time",unit:"s",what:"the whole event, every lap",read:e=>hs(e?.time)},{name:"lapTime",unit:"s",what:"one lap \u2014 the last one completed",read:e=>hs(e?.lapTime)},{name:"distance",unit:"m",what:"distance covered",read:e=>hs(e?.distance)},{name:"laps",unit:"-",what:"laps completed",read:e=>hs(e?.laps)},{name:"energy",unit:"kWh",what:"energy drawn over the event",read:e=>hs(e?.energy?.consumed)},{name:"remaining",unit:"-",what:"share of the pack or tank left afterwards",read:e=>hs(e?.energy?.remainingFraction)},{name:"finished",unit:"-",what:"1 when the car ran the whole event, else 0",read:e=>e&&!e.incomplete?1:0}],IA=/^[A-Za-z_][A-Za-z0-9_]*$/,WN=new Set([...Object.keys(fs),...Eg.map(e=>e.name)]);function Qm(e,t,r=[]){let n=[],o=new Set(r),a=t.map(b=>b.id),s=new Set;for(let b of a)IA.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(!IA.test(b.key)){n.push({key:b.key,message:`"${b.key}" must be one word \u2014 letters, digits and _`});continue}if(WN.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,Og(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,[...Vg(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=jN(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 d=(b,g,y)=>{throw new Je("fleetmin() and fleetmax() cannot sit inside one another",y)},p=new Set,h={};for(let b of a)for(let g of Bg)h[`${b}.${g.name}`]=1;for(let b of o)h[b]=1;for(let b of i.keys())h[b]=1;let f={};for(let b of Eg)f[b.name]=[1,1];for(let b of m){let g=i.get(b),y=c.get(b);($o(y)||l.get(b).some(R=>p.has(R)))&&p.add(b);let x=g.over!=null?{...h,...f}:h,k=g.over!=null?[1,1]:void 0,v=(R,M,A)=>{let F=$r(R,{vars:x,ds:k,fleet:d});if(Array.isArray(F))throw new Je("fleetmin() and fleetmax() compare one number per car \u2014 reduce the channel first, e.g. peak(v)",A);return F};try{let R=$r(y,{vars:x,ds:k,fleet:v});Array.isArray(R)&&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(R){let M=R;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 jN(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 UN(e,t,r={}){let n={...r};for(let o of e.eventIds){let a=t.events[o];for(let s of Bg)n[`${o}.${s.name}`]=s.read(a)}return{vars:n,laps:new Map,events:t.events}}function _A(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?CA({...n.trace,length:bc(n)}):null,e.laps.set(t.over,r)}return r?{vars:{...e.vars,...r.vars},ds:r.ds}:null}var NA=e=>Array.isArray(e)?NaN:e;function OA(e,t,r,n={}){let o=Object.keys(t),a=o.map(i=>UN(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 d of a)d.vars[i.key]=NaN;continue}let u=new Map,m=(d,p)=>{let h=u.get(d);if(h!==void 0)return h;let f=NaN;for(let b of a){let g=_A(b,i);if(!g)continue;let y=NA($r(d,g));Number.isFinite(y)&&(Number.isNaN(f)||(p==="min"?y<f:y>f))&&(f=y)}return u.set(d,f),f};for(let d of a){let p=_A(d,i);d.vars[i.key]=p?NA($r(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 kc(e,t,r){return OA(e,t,!0,r)}function $g(e,t,r){return OA(e,{car:t},!1,r?{car:r}:void 0).car}var Zm=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}},Mc=e=>typeof e=="number"&&Number.isFinite(e),kc=e=>Mc(e)&&e>0,tr=(e,t)=>e===void 0||t(e);function jN(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":kc(a.distance)||r(`${s} needs a distance above zero, in metres`),tr(a.vStart,i=>Mc(i)&&i>=0)||r(`${s}'s entry speed must be zero or more`);break;case"constantRadius":kc(a.radius)||r(`${s} needs a radius above zero, in metres`),tr(a.laps,i=>Mc(i)&&i>=1)||r(`${s} runs at least one lap`);break;case"trackLap":tr(a.laps,i=>Mc(i)&&i>=1)||r(`${s} runs at least one lap`),tr(a.distance,kc)||r(`${s}'s distance must be above zero, in metres`),tr(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),tr(a.unit,i=>typeof i=="string")||r("Its unit is text",s),tr(a.over,i=>typeof i=="string")||r("Names its event by id",s),tr(a.format,i=>i==="time"||i==="points")||r("Is shown as a time, as points, or as a number",s),tr(a.max,Mc)||r("Its maximum is a number",s),tr(a.lowerBetter,i=>typeof i=="boolean")||r("Lower is better, or it is not",s),tr(a.hidden,i=>typeof i=="boolean")||r("Is hidden, or it is not",s)}tr(e.track?.minTurnRadius,kc)||r("The tightest turn the rules allow is a radius above zero");let n=e.battery;for(let o of["packVoltageMax","segmentVoltageMax","powerLimitKw"])tr(n?.[o],kc)||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 NA(e){let t=jN(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}=Qm(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 Jm(e){return NA(e).problems}var Bg=e=>Number.isFinite(e)?e:NaN;function UN(e){return e.unit&&e.format!=="time"?`${e.label} (${e.unit})`:e.label}function jn(e){let t=structuredClone(e),{plan:r,problems:n}=NA(t);if(!r)throw new Zm(t.id,n);let o=new WeakMap,a=p=>{let h=o.get(p);return h||(h=Vg(r,p),o.set(p,h)),h},s=new Map(t.kpis.map(p=>[p.key,p])),i=new Map;for(let[p,h]of Object.entries(t.score?.parts??{}))i.has(h)||i.set(h,p);let c=p=>(h,f)=>{if(!f)return NaN;let b=f.kpis?.[p];if(b!==void 0)return Bg(b);let g=f,y=i.get(p);return y!==void 0?Bg(g.parts?.[y]):p===t.score?.total?Bg(g.total):NaN},l=t.kpis.filter(p=>!p.hidden).map(p=>{let h=r.field.has(p.key);return{key:p.key,label:UN(p),lowerBetter:p.lowerBetter??!1,...p.format?{format:p.format}:{},...h?{field:!0}:{},value:h?c(p.key):f=>a(f)[p.key]}}),u=t.score,m=u?p=>{let h=vc(r,p),f={};for(let[b,g]of Object.entries(h)){let y={},x={};for(let[k,v]of Object.entries(u.parts)){y[k]=g[v];let R=s.get(v)?.max;R!=null&&(x[k]=R)}f[b]={total:g[u.total],parts:y,...Object.keys(x).length?{maxima:x}:{},kpis:Object.fromEntries(t.kpis.map(k=>[k.key,g[k.key]]))}}return f}:void 0,d=m||(r.field.size>0?p=>{let h=vc(r,p),f={};for(let[b,g]of Object.entries(h))f[b]={kpis:Object.fromEntries(t.kpis.map(y=>[y.key,g[y.key]]))};return f}: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}:{},...d?{field:d}:{},definition:t}}var gr={accel:"accel",skidpad:"skidpad",autocross:"autocross",endurance:"endurance"},OA=[{kind:"straightLineAccel",id:gr.accel,label:"Acceleration (75 m)",distance:75},{kind:"constantRadius",id:gr.skidpad,label:"Skidpad",radius:8.375},{kind:"trackLap",id:gr.autocross,label:"Autocross (1 lap)",laps:1},{kind:"trackLap",id:gr.endurance,label:"Endurance (22 km)",distance:22e3}],VA=[{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"}],BA={total:"overall",parts:{[gr.accel]:"accelPts",[gr.skidpad]:"skidpadPts",[gr.autocross]:"autocrossPts",[gr.endurance]:"endurancePts",efficiency:"efficiencyPts"}},$A={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:OA,kpis:VA,score:BA,track:{minTurnRadius:4.5},battery:_x,traceEventId:gr.autocross},GA={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:OA,kpis:VA,score:BA,track:{minTurnRadius:4.5},traceEventId:gr.autocross},Sc=jn($A),$g=jn(GA);var Gg="lap",XN=[{kind:"trackLap",id:Gg,label:Xm,laps:1}],KA={id:"trackday",label:"Track day",description:"One flying lap of the selected track. Times and traces only \u2014 no scoring.",events:XN,kpis:[{key:"lap",label:"Lap time",format:"time",lowerBetter:!0,expr:"lap.time"},{key:"topSpeed",label:"Top speed",unit:"km/h",over:Gg,expr:"peak(speed)"},{key:"energy",label:"Energy / lap",unit:"kWh",lowerBetter:!0,expr:"lap.energy"}],traceEventId:Gg},Kg=jn(KA);function Un(e){if(e===null||typeof e!="object")return JSON.stringify(e)??"null";if(Array.isArray(e))return`[${e.map(Un).join(",")}]`;let t=e,r=Object.keys(t).sort(),n=[];for(let o of r)t[o]!==void 0&&n.push(`${JSON.stringify(o)}:${Un(t[o])}`);return`{${n.join(",")}}`}function Go(e){let t=Un(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 fs=[Sc,$g,Kg],Ko=Sc.id,hs=e=>fs.some(t=>t.id===e),HA=new WeakMap,Ac=new Map,qN=64;function ep(e){let t=HA.get(e);if(t!==void 0)return t;let r=Un(e),n=Ac.get(r);return n===void 0&&(n=Jm(e).length?null:jn(e),Ac.size>=qN&&Ac.delete(Ac.keys().next().value),Ac.set(r,n)),HA.set(e,n),n}function tp(e,t=[]){if(e==null)return;if(typeof e!="string")return ep(e)??void 0;let r=fs.find(o=>o.id===e);if(r)return r;let n=t.find(o=>o.id===e);return n?ep(n)??void 0:void 0}function Ho(e,t=[]){return tp(e,t)??Sc}function Hg(e=[]){let t=e.filter(r=>!hs(r.id)).map(r=>ep(r)).filter(r=>r!==null);return[...fs,...t]}var wc=e=>e.definition??e.id;function rp(e,t,r){let n=e.length,o=new Array(n);for(let h=0;h<n;h++){let f=h+1<n?e[h+1]:r;o[h]=f-e[h]}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 h=0;h<n;h++){let f=o[(h-1+n)%n],b=o[h];a[h]=f,s[h]=2*(f+b),i[h]=b;let g=t[(h+1)%n],y=t[(h-1+n)%n];c[h]=6*((g-t[h])/b-(t[h]-y)/f)}let l=QN(a,s,i,c),u=new Array(n),m=new Array(n),d=new Array(n),p=new Array(n);for(let h=0;h<n;h++){let f=o[h],b=l[h],g=l[(h+1)%n],y=t[h],x=t[(h+1)%n];u[h]=y,d[h]=b/2,p[h]=(g-b)/(6*f),m[h]=(x-y)/f-f*(2*b+g)/6}return{n,eval:(h,f)=>u[h]+f*(m[h]+f*(d[h]+f*p[h])),d1:(h,f)=>m[h]+f*(2*d[h]+f*3*p[h]),d2:(h,f)=>2*d[h]+f*6*p[h]}}function Yg(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),d=new Array(u).fill(0),p=new Array(u).fill(0),h=new Array(u).fill(0);for(let g=0;g<u;g++){let y=g+1;m[g]=o[y-1],d[g]=2*(o[y-1]+o[y]),p[g]=o[y],h[g]=6*((t[y+1]-t[y])/o[y]-(t[y]-t[y-1])/o[y-1])}let f=n>=3;if(f){let g=o[0]/o[1];d[0]+=o[0]*(1+g),p[0]-=o[0]*g;let y=o[n-1]/o[n-2];d[u-1]+=o[n-1]*(1+y),m[u-1]-=o[n-1]*y}let b=zg(m,d,p,h);for(let g=0;g<u;g++)a[g+1]=b[g];f&&(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 QN(e,t,r,n){let o=t.length;if(o===1)return[n[0]/(t[0]+e[0]+r[0])];if(o===2){let h=t[0],f=r[0]+e[0],b=e[1]+r[1],g=t[1],y=h*g-f*b;return[(n[0]*g-f*n[1])/y,(h*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=zg(e,c,r,n),u=new Array(o).fill(0);u[0]=i,u[o-1]=s;let m=zg(e,c,r,u),d=(l[0]+a*l[o-1]/i)/(1+m[0]+a*m[o-1]/i),p=new Array(o);for(let h=0;h<o;h++)p[h]=l[h]-d*m[h];return p}function zg(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 Fc(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 zA(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 YA(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 d=r*i-o*o,p=n*o-r*s,h=r*a-n*n;return[(c*t[0]+l*t[1]+u*t[2])/m,(l*t[0]+d*t[1]+p*t[2])/m,(u*t[0]+p*t[1]+h*t[2])/m]}function WA(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(f=>e.closed?(f+t)%t:f);if(s.some(f=>f<0||f>=t))continue;let i=s.map(f=>zA(e,a,f)),c=Math.max(...i.map(Math.abs));if(!(c>0))continue;let l=i.map(f=>f/c),u=[0,0,0,0,0];for(let f of l)for(let b=0;b<5;b++)u[b]+=f**b;let m=YA([u[0],u[1],u[2],u[2],u[3],u[4]],[1,0,0]);if(!m)continue;let d=l.map(f=>m[0]+m[1]*f+m[2]*f*f),p=0,h=1;d.forEach((f,b)=>{p+=f*e.z[s[b]],h+=f*f}),r.push(Math.abs(e.z[a]-p)/Math.sqrt(h))}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 ZN(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=zA(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 JN(e,t,r){let{j:n,t:o}=ZN(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 d=0;d<5;d++)i[d]+=m,m*=l});let c=YA([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 Wg(e,t){return t>0?e.z.map((r,n)=>{let o=JN(e,n,t/2);return o?o.value.reduce((a,s,i)=>a+s*e.z[o.j[i]],0):r}):[...e.z]}function eO(e,t){if(!(e>0)||!(t>0))return 0;let r=(22.5*t*e*e/1e-4**2)**.2;return Math.min(100/2,r)}function np(e){let t=Fc(e);if(!t)return 0;let r=WA(t);return r>1e-6?Math.max(10,eO(r,tO(t))):0}function tO(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 Gr(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 ap(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 jA(e,t){let r=new Array(e).fill(0),n=new Array(e).fill(0),o=new Array(e).fill(0);for(let a=0;a<e;a++){a>=2&&(o[a]=r[a-2]!==0?t(a,a-2)/r[a-2]:0),a>=1&&(n[a]=r[a-1]!==0?(t(a,a-1)-o[a]*n[a-1])/r[a-1]:0);let s=t(a,a)-n[a]*n[a]-o[a]*o[a];if(!(s>0)||!Number.isFinite(s))return null;r[a]=Math.sqrt(s)}return{d:r,l1:n,l2:o}}function op(e,t){let r=t.length,n=new Array(r).fill(0);for(let a=0;a<r;a++){let s=t[a];a>=1&&(s-=e.l1[a]*n[a-1]),a>=2&&(s-=e.l2[a]*n[a-2]),n[a]=s/e.d[a]}let o=new Array(r).fill(0);for(let a=r-1;a>=0;a--){let s=n[a];a+1<r&&(s-=e.l1[a+1]*o[a+1]),a+2<r&&(s-=e.l2[a+2]*o[a+2]),o[a]=s/e.d[a]}return o}function rO(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 jg(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=jA(r,(y,x)=>Gr(e,y,x));if(!b)return null;let g=op(b,t);return g.every(Number.isFinite)?g:null}let n=r-2,a=jA(n,(b,g)=>Gr(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]=Gr(e,b,r-2),i[b]=Gr(e,b,r-1);let c=op(a,t.slice(0,n)),l=op(a,s),u=op(a,i),m=(b,g)=>{let y=0;for(let x=0;x<b.length;x++)y+=b[x]*g[x];return y},d=[[Gr(e,r-2,r-2)-m(s,l),Gr(e,r-2,r-1)-m(s,u)],[Gr(e,r-1,r-2)-m(i,l),Gr(e,r-1,r-1)-m(i,u)]],p=[t[r-2]-m(s,c),t[r-1]-m(i,c)],h=rO(d,p);if(!h)return null;let f=new Array(r).fill(0);for(let b=0;b<n;b++)f[b]=c[b]-l[b]*h[0]-u[b]*h[1];return f[r-2]=h[0],f[r-1]=h[1],f.every(Number.isFinite)?f:null}function UA(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=jg(i,t);if(c){let l=ap(i,c).map((m,d)=>m-t[d]);if(Math.sqrt(l.reduce((m,d)=>m+d*d,0))<=1e-6*Math.max(a,1e-12))return c}o=o===0?n*1e-12:o*10}return null}var XA=4,nO=8,Ug=.001;function oO(e,t,r){let n=[];for(let c=1;c<e.length;c++){let l=e[c]-e[c-1];l>=Ug&&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/XM(r,s,i)))}function aO(e,t){let r=e.closed!==!1,n=[],o=[],a=(A,F)=>{let T=n.length-1;T>=0&&Math.hypot(A-n[T],F-o[T])<Ug||(n.push(A),o.push(F))},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 F=(A+1)%s;c[A+1]=c[A]+Math.hypot(e.x[F]-e.x[A],e.y[F]-e.y[A])}let l=c[i],u=e.fit==="interpolate",m=u?s:oO(c,r,t),d=r?m:m-1,p=0;for(let A=0;A<=d&&!(r&&A===d);A++){if(u){a(e.x[A],e.y[A]);continue}let F=A*l/d;for(;p<i-1&&c[p+1]<F;)p++;let T=c[p+1]-c[p],P=T>0?(F-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])<Ug;)n.pop(),o.pop();let h=n.length,f=r?h:h-1,b=new Array(f+1);b[0]=0;for(let A=1;A<=f;A++){let F=A%h,T=n[F]-n[A-1],P=o[F]-o[A-1],S=Math.sqrt(Math.hypot(T,P))||1e-9;b[A]=b[A-1]+S}let g=r?rp(b.slice(0,h),n,b[h]):Yg(b,n),y=r?rp(b.slice(0,h),o,b[h]):Yg(b,o),x=new Array(f);for(let A=0;A<f;A++)x[A]=b[A+1]-b[A];let k=[0],v=[0],R=[0],M=0;for(let A=0;A<f;A++){let F=x[A]/XA;for(let T=0;T<XA;T++){let P=T*F;M+=qh(S=>Math.hypot(g.d1(A,S),y.d1(A,S)),P,P+F),k.push(M),v.push(A),R.push(P+F)}}return{closed:r,sx:g,sy:y,h:x,sTable:k,segTable:v,uTable:R,length:M,rawCum:c,rawLength:l}}function Cc(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 d=i*n.rawLength,p=0,h=a;for(;p<h;){let b=p+h+1>>1;n.rawCum[b]<=d?p=b:h=b-1}let f=p<a?n.rawCum[p+1]-n.rawCum[p]:0;c=p+(f>0?(d-n.rawCum[p])/f: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 sO=.01,iO=3,qA=10;function cO(e,t,r,n=qA){let o={step:0,uncertainty:1/0},a=e.length;if(a<8||!(r>0))return o;let s=Math.max(qA,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=[],d=[],p=(x,k,v)=>{let R=x/s;m.push([1,R,R*R,R*R*R,k]),d.push(v)};for(let x=0;x<u;x++)p(t[x]+i,1,e[x]);for(let x=0;x<u;x++)p(t[a-1-x]-r+i,0,e[a-1-x]);let h=Array.from({length:5},()=>new Array(5).fill(0)),f=new Array(5).fill(0);m.forEach((x,k)=>{for(let v=0;v<5;v++){f[v]+=x[v]*d[k];for(let R=0;R<5;R++)h[v][R]+=x[v]*x[R]}});let b=Ar(h,f),g=Ar(h,[0,0,0,0,1]);if(b.singular||g.singular)return o;let y=0;return m.forEach((x,k)=>{let v=0;for(let R=0;R<5;R++)v+=x[R]*b.x[R];y+=(d[k]-v)**2}),{step:b.x[4],uncertainty:Math.sqrt(y/(m.length-5)*g.x[4])}}function lO(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 uO(e,t,r){let{pos:n,loop:o}=lO(e.length,t),{step:a,uncertainty:s}=cO(e,n,o,r);return Math.abs(a)>Math.max(sO,iO*s)?{z:e.map((i,c)=>i+a*n[c]/o),drift:-a}:{z:e,drift:0}}function mO(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],d=r[u+1],p=n[u+1],h=o[u+1],f=n[u]===p?o[u]:0,b=d-m,g=b>0?f+(t-m)/b*(h-f):f;for(let y=0;y<2;y++){let x=m+qh(v=>Math.hypot(s.d1(p,v),i.d1(p,v)),f,g),k=Math.hypot(s.d1(p,g),i.d1(p,g));if(k<1e-12)break;g-=(x-t)/k}return{seg:p,du:Math.min(Math.max(g,0),a[p])}}var pO=3,Xg=5;function dO(e,t,r,n=Xg){return ip(e,t,r,n)}function ip(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 d of[0,a-1])i[d]+=m,u[d]*=1+m}return jg({n:a,diag:i,off1:c,off2:l,closed:r},u)??[...e]}function wt(e,t){let r=At(t),n=aO(e,r.fitSpacing),o=n.length,a=Math.max(nO,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 d=new Array(s),p=new Array(s),h=new Array(s);for(let T=0;T<s;T++){let P=T*i,{seg:S,du:w}=mO(n,P);c[T]=n.sx.eval(S,w),l[T]=n.sy.eval(S,w),u[T]=P;let C=n.sx.d1(S,w),L=n.sy.d1(S,w),E=n.sx.d2(S,w),_=n.sy.d2(S,w),O=Math.hypot(C,L),I=Math.pow(C*C+L*L,1.5);d[T]=I>0?(C*_-L*E)/I:0,p[T]=O>0?-L/O:0,h[T]=O>0?C/O:0}let f=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?uO(e.z,n.rawCum,g):null,x=y?y.z:e.z,k=g>0?Fc(e):null,v=k?Wg({...k,z:x},g):x,R=Cc(v,0,f,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),w=n.closed?(P-1+s)%s:Math.max(P-1,0),C=n.closed?2:S-w,L=R[S]-R[w];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,w=R[S]-R[P];m[P]=Math.hypot(i,w)}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,F;if(b){F=new Array(s).fill(0);let T=Math.max(pO,e.zReach??np(e)),P=Math.max(2,Math.round(T/i));if(n.closed?s>2*P:s>2*P+1){let S=0,w=0;for(let E=-P;E<=P;E++)S+=E*E,w+=E*E*E*E;let C=2*P+1,L=w-S*S/C;for(let E=0;E<s;E++){let _=n.closed?E:Math.min(Math.max(E,P),s-1-P),O=0,I=0;for(let V=-P;V<=P;V++){let j=R[n.closed?(_+V+s)%s:_+V];O+=(V*V-S/C)*j,I+=V*j}let z=2*O/L/(i*i),B=I/S/i;F[E]=z/Math.pow(1+B*B,1.5)}}}return{name:e.name,closed:n.closed,x:c,y:l,s:u,ds:m,curvature:e.turnReach?dO(d,i,n.closed,e.turnReach):d,npts:s,length:A,nx:p,ny:h,z:R,gradient:M,...F?{verticalCurvature:F}:{},widthLeft:Cc(e.widthLeft,1.5,f,n),widthRight:Cc(e.widthRight,1.5,f,n),bank:Cc(e.bank,0,f,n),mu:Cc(e.mu,1,f,n),...y?.drift?{elevationDrift:y.drift}:{}}}function QA(e,t,r){let n=ap(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 fO(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 d=s(l,m);d!=null&&(i[d]-=Gr(e,d,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 UA(c,i)}var hO=1e-4;function ZA(e,t,r,n,o={}){let a=e.n,s=o.maxIter??60,i=o.tol??1e-9,c=o.bounds,l=(h,f)=>Math.min(n[f],Math.max(r[f],h)),u=r.map((h,f)=>c?.[f]==="hi"?n[f]:c?.[f]==="lo"?r[f]:l(0,f)),m=QA(e,t,u),d=new Array(a).fill("free"),p=!1;for(let h=0;h<s;h++){let f=ap(e,u).map((x,k)=>x-t[k]),b=!1;for(let x=0;x<a;x++){let k=u[x]<=r[x]+i&&f[x]>=-i?"lo":u[x]>=n[x]-i&&f[x]<=i?"hi":"free";k!==d[x]&&(d[x]=k,b=!0)}if(p&&!b)return{x:u,iterations:h+1,converged:!0,bounds:d};let g=fO(e,t,d,x=>u[x]);if(!g)return{x:u,iterations:h+1,converged:!1,bounds:d};let y=!1;for(let x=1;x>1e-12;x*=.5){let k=!1,v=u.map((A,F)=>{if(d[F]!=="free")return A;let T=A+x*(g[F]-A),P=l(T,F);return P!==T&&(k=!0),P}),R=QA(e,t,v),M=0;for(let A=0;A<a;A++)M+=f[A]*(v[A]-u[A]);if(x===1&&!k||R<m&&R<=m+hO*M){u=v,m=R,p=x===1&&!k,y=!0;break}}if(!y)return{x:u,iterations:h+1,converged:!1,bounds:d}}return{x:u,iterations:s,converged:!1,bounds:d}}var qg={lineStep:2,carHalfWidth:.75,margin:.1,foldMargin:.25,referenceReach:5,passes:40,iterations:400},bO=[1,.5,.25,.125,.0625,.03125,.015625,.0078125,.00390625,.001953125,.0009765625],gO=e=>Math.sqrt(e.reduce((t,r)=>t+r*r,0)/(e.length||1));function Tc(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],d=e[i]-e[s],p=t[i]-t[s],h=Math.hypot(c,l),f=Math.hypot(u,m),b=Math.hypot(d,p),g=h*f*b;o[a]=g>1e-12?2*(c*m-l*u)/g:0}return o}var yO=Math.PI/180,JA=20;function xO(e,t){let r=e.npts,n=e.closed,o=e.x.map((p,h)=>p+t[h]*e.nx[h]),a=e.y.map((p,h)=>p+t[h]*e.ny[h]),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 h=0;h<r;h++)l.push(s[h]+p*i),u.push(h+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 d=p=>{let h=0,f=l.length-1;for(;f-h>1;){let g=h+f>>1;l[g]<=p?h=g:f=g}let b=l[f]>l[h]?(p-l[h])/(l[f]-l[h]):0;return m[h]+(l[f]-l[h])*b*(u[h]+.5*b*(u[f]-u[h]))};return s.map((p,h)=>{let f=n?JA:Math.min(JA,p,i-p);if(!(f>0))return e.z[h];let b=(d(p+f)-d(p-f))/(2*f),g=n?(b%r+r)%r:Math.min(Math.max(b,0),r-1),y=Math.min(Math.floor(g),r-1),x=n?(y+1)%r:Math.min(y+1,r-1);return e.z[y]+(g-y)*(e.z[x]-e.z[y])})}function RO(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?xO(t,r):t.z;return{...n||o?{z:s.map((i,c)=>i+r[c]*Math.tan(t.bank[c]*yO))}:{},...n?{zReach:e.zReach??np(e)}:{},...o?{bank:[...t.bank]}:{},...a?{mu:[...t.mu]}:{}}}function ew(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 vO(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,d)=>l*d-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,d=e[l]-e[u],p=t[l]-t[u],h=e[m]-e[l],f=t[m]-t[l],b=e[m]-e[u],g=t[m]-t[u],y=Math.hypot(d,p),x=Math.hypot(h,f),k=Math.hypot(b,g),v=y*x*k;if(!(v>1e-12))continue;let R=2*c(d,p,h,f)/v,M=Math.sqrt(.5*(y+x)),A=R/(2*M),F=(d*r[u]+p*n[u])/y,T=(b*r[u]+g*n[u])/k,P=(d*r[l]+p*n[l])/y,S=(h*r[l]+f*n[l])/x,w=(h*r[m]+f*n[m])/x,C=(b*r[m]+g*n[m])/k,L=-2*c(r[u],n[u],h,f)/v+R*(F/y+T/k),E=2*c(r[l],n[l],b,g)/v-R*(P/y-S/x),_=2*c(d,p,r[m],n[m])/v-R*(w/x+C/k);s[l]=R*M,i.l[l]=M*L-A*.5*F,i.d[l]=M*E+A*.5*(P-S),i.r[l]=M*_+A*.5*w}return{res:s,jac:i}}function kO(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=(f,b)=>o?f[(b+a)%a]:b>=0&&b<a?f[b]:0,m=new Array(a),d=new Array(a),p=new Array(a),h=new Array(a);for(let f=0;f<a;f++){let b=u(c,f-1),g=u(s,f+1);m[f]=b*b+i[f]*i[f]+g*g,d[f]=i[f]*c[f]+g*u(i,f+1),p[f]=g*u(c,f+1),h[f]=-(b*u(l,f-1)+i[f]*l[f]+g*u(l,f+1))}return{M:{n:a,closed:o,diag:m,off1:d,off2:p},b:h}}function MO(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 d=0;d<o;d++){let p=(d+1)%r;a+=Math.hypot(e.x[p]-e.x[d],e.y[p]-e.y[d])}let s=a/o,i=ip(e.x,s,n,t,!0),c=ip(e.y,s,n,t,!0),l=new Array(r),u=new Array(r);for(let d=0;d<r;d++){let p=n?(d-1+r)%r:Math.max(d-1,0),h=n?(d+1)%r:Math.min(d+1,r-1),f=i[h]-i[p],b=c[h]-c[p],g=Math.hypot(f,b)||1;l[d]=-b/g,u[d]=f/g}let m=Tc(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 SO=6;function AO(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]),d=Math.hypot(e.x[u]-e.x[l],e.y[u]-e.y[l]);s[l]=d>1e-9?m/d:0}let i=Math.max(0,Math.round(SO/(e.ds[0]||1))),c=1-n;for(let l=0;l<o;l++){let u=0,m=0;for(let d=-i-1;d<=i;d++){let p=e.closed?((l+d)%o+o)%o:l+d;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 Qg(e,t={}){let r={...qg,...t},n=wt(e,{dsTarget:r.lineStep}),o=MO(n,r.referenceReach),a=o.npts,s=P=>({x:o.x.map((S,w)=>S+o.nx[w]*P[w]),y:o.y.map((S,w)=>S+o.ny[w]*P[w])}),i=P=>{let S=Tc(P.x,P.y,o.closed),w=ew(P.x,P.y,o.closed),C=0;for(let L=0;L<S.length;L++)C+=S[L]*S[L]*w[L];return C},c=gO(n.curvature),l=ew(n.x,n.y,n.closed).reduce((P,S)=>P+S,0),u=new Array(a).fill(0),m=r.carHalfWidth+r.margin,d=new Array(a),p=new Array(a),h=0;for(let P=0;P<a;P++){let S=o.widthLeft[P]-m,w=-(o.widthRight[P]-m);if(S<w){h++;let C=(o.widthLeft[P]-o.widthRight[P])/2;d[P]=C,p[P]=C}else d[P]=S,p[P]=w}let f=[...d],b=[...p];AO(o,d,p,r.foldMargin);let g=P=>{let S=s(P),w=RO(e,o,P),C={name:`${e.name} \u2014 racing line`,x:S.x,y:S.y,closed:o.closed,widthLeft:f.map((B,V)=>Math.max(0,B-P[V])),widthRight:b.map((B,V)=>Math.max(0,P[V]-B)),...w,fit:"interpolate",turnReach:Xg},L=1e-6,E=P.filter((B,V)=>B>=d[V]-L||B<=p[V]+L).length,_=Tc(S.x,S.y,o.closed),O=B=>1/Math.max(...B.map(Math.abs),1e-9),I=0,z=o.closed?S.x.length:S.x.length-1;for(let B=0;B<z;B++){let V=(B+1)%S.x.length,j=S.x[V]-S.x[B],q=S.y[V]-S.y[B];I+=w.z?Math.hypot(j,q,w.z[V]-w.z[B]):Math.hypot(j,q)}return{offset:P,s:[...o.s],asset:C,curvatureRms:{centreLine:c,racingLine:Math.sqrt(i(S)/(l||1))},infeasibleSamples:h,atBoundary:a?E/a:0,length:{centreLine:n.length,racingLine:I},worstRadius:{centreLine:O(n.curvature),racingLine:O(_)}}},y=o.closed?0:1,x=o.closed?a-1:a-2,k=x-y+1,v=new Array(k),R=new Array(k);for(let P=0;P<k;P++)v[P]=p[y+P],R[P]=d[y+P];if(!o.closed&&k>0){let P=(S,w)=>{if(v[S]=Math.max(v[S],p[w]),R[S]=Math.min(R[S],d[w]),v[S]>R[S]){let C=.5*(v[S]+R[S]);v[S]=C,R[S]=C}};P(0,0),P(k-1,a-1),v[0]=R[0]=Math.min(R[0],Math.max(v[0],0))}if(k<7)return g(u);let M=P=>{let S=s(P),C=[...Tc(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],F=M(u),T;for(let P=0;P<r.passes;P++){let S=s(A),{res:w,jac:C}=vO(S.x,S.y,o.nx,o.ny,o.closed),{M:L,b:E}=kO(C,w,y,x,o.closed),_=ZA(L,E,v.map((z,B)=>z-A[y+B]),R.map((z,B)=>z-A[y+B]),{maxIter:r.iterations,bounds:T});T=_.bounds;let O=new Array(a).fill(0);for(let z=0;z<k;z++)O[y+z]=_.x[z];o.closed||(O[0]=O[1],O[a-1]=O[a-2]);let I=!1;for(let z of bO){let B=A.map((j,q)=>j+z*O[q]),V=M(B);if(V.integral<F.integral*(1-1e-6)){A=B,F=V,I=!0;break}}if(!I)break}return g(A)}function Zg(e){let t=Math.max(re(e,"track_front"),re(e,"track_rear"));return(t>0?t/2e3:.6)+.1}function cp(e,t,r={}){if(!r.racingLine)return{asset:e,numerics:t,line:null};let n=r.params?Zg(r.params):void 0,o=Qg(e,{...r.line,...n?{carHalfWidth:n}:{}});return{asset:o.asset,numerics:{...t,fitSpacing:0},line:o}}function Pc(e,t,r={}){let n=cp(e,t,r);return{track:wt(n.asset,n.numerics),line:n.line}}function Jg(e=4,t=Pc){let r=new WeakMap;return(n,o,a={})=>{let s=a.racingLine===!0,i=s?[a.params?Zg(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 tw={racingLine:!1,standingStart:!1},lp=256;function Lc(e,t,r,n,o=tw,a=Pc){let s=Ho(n),{racingLine:i,standingStart:c,lapCounts:l}=o;return e.map(u=>{let{track:m}=a(t,r,{racingLine:i,params:u});return Eg(gc(u,s,{track:m,numerics:r,standingStart:c,lapCounts:l}))})}function e0(e,t){let r=Ho(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 t0(e,t,r){let n={};for(let o of Ho(e).metrics)n[o.key]=o.value(t,r);return n}var up=36;var o0=287.05287,FO=461.495,mp=9.80665/(o0*.0065),CO=101325/(o0*288.15),TO=273.15,PO=-500,LO=6e3,DO=400,EO=1100,pp={source:"car",altitudeM:0,pressure:{kind:"standard"},humidityPct:0};function IO(e){return 101325*Math.pow(1-.0065*e/288.15,mp)}function _O(e){return 288.15/.0065*(1-Math.pow(e/CO,1/(mp-1)))}function NO(e){return 288.15/.0065*(1-Math.pow(e/101325,1/mp))}function OO(e,t){return e*Math.pow(1-.0065*t/288.15,mp)}function VO(e){return 611.21*Math.exp((18.678-e/234.5)*(e/(257.14+e)))}function BO(e,t){switch(e.kind){case"standard":return IO(t);case"qnh":return OO(e.hPa*100,t);case"station":return e.hPa*100}}function Dc(e,t,r=0,n=NO(e)){let o=t+TO,a=Math.min(.5*e,Math.max(0,Math.min(100,r))/100*VO(t)),s=e-a,i=s/(o0*o)+a/(FO*o);return{altitudeM:n,p:e,pDry:s,T:o,rho:i,densityAltitudeM:_O(i)}}function rw(e,t){return Dc(BO(e.pressure,e.altitudeM),t,e.humidityPct,e.altitudeM)}var r0=(e,t,r)=>Math.min(r,Math.max(t,e)),n0=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function dp(e){if(!e||typeof e!="object")return structuredClone(pp);let t=e,r=t.pressure??{},n=r0(n0(r.hPa,1013.25),DO,EO),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:r0(n0(t.altitudeM,0),PO,LO),pressure:o,humidityPct:r0(n0(t.humidityPct,0),0,100)}}var Ec=e=>e?.source==="venue";var $O=Math.PI/180;function GO(){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 KO(){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 a0(e){let t=-e*$O;return te([0,Math.cos(t),Math.sin(t)])}function fp(){let e={rodType:"push",pushrodAttach:"lowerArm",steerMode:"rack",spinAxis:a0(-1),loadedRadius:230,springRate:35,rackAxis:[0,1,0]};return{hardpoints:GO(),config:e}}function Ic(){let e={rodType:"pull",pushrodAttach:"lowerArm",steerMode:"fixed",spinAxis:a0(-1.5),loadedRadius:232,springRate:40,rackAxis:[0,1,0]};return{hardpoints:KO(),config:e}}function hp(){let e=[-25,635,460],t=[-40,600,710],r={layout:"mcpherson",actuation:"direct",rodType:"push",pushrodAttach:"upright",steerMode:"rack",spinAxis:a0(-.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 s0(){return{front:fp(),rear:Ic(),config:{wheelbase:1600,trackFront:1200,trackRear:1220,frontAxleX:800}}}var HO=Math.PI/180;function nw(e){let t=-e*HO;return te([0,Math.cos(t),Math.sin(t)])}function i0(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:nw(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]=zO(o[l]);return{hardpoints:o,config:c}}function zO(e){return e.map(t=>Math.round(t*10)/10+0)}function Yo(e){return{name:e.name,front:i0(fp(),e.front),rear:i0(Ic(),e.rear),config:{wheelbase:e.wheelbase,trackFront:e.trackFront,trackRear:e.trackRear,frontAxleX:e.wheelbase/2}}}function bs(e,t,r){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:t}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:r}}}}var gs=600,Wo=610,ys=230,jo=232;function Uo(){let e=s0();return{...e,name:"Formula Student",front:{...e.front,config:{...e.front.config,actuation:"rocker"}},rear:{...e.rear,config:{...e.rear.config,actuation:"rocker"}}}}function c0(){return Yo({name:"Formula 1",wheelbase:3600,trackFront:1600,trackRear:1600,front:{kx:1.3,ky:800/gs,kz:355/ys,lowerInnerDz:-5,upperInnerDz:0,camberDeg:-3,loadedRadius:355,springRate:200},rear:{kx:1.3,ky:800/Wo,kz:355/jo,lowerInnerDz:35,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:220}})}function _c(){return bs(Yo({name:"GT car",wheelbase:2700,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/gs,kz:325/ys,lowerInnerDz:18,upperInnerDz:5,camberDeg:-3.5,loadedRadius:325,springRate:110,actuation:"direct"},rear:{kx:1.2,ky:825/Wo,kz:325/jo,lowerInnerDz:36,upperInnerDz:15,camberDeg:-2,loadedRadius:325,springRate:120,actuation:"direct"}}),318.6,318.6)}function Nc(){return bs(Yo({name:"Sports car",wheelbase:2750,trackFront:1550,trackRear:1550,front:{kx:1.15,ky:775/gs,kz:320/ys,lowerInnerDz:36,upperInnerDz:15,camberDeg:-.5,loadedRadius:320,springRate:55,actuation:"direct"},rear:{kx:1.15,ky:775/Wo,kz:320/jo,lowerInnerDz:57,upperInnerDz:25,camberDeg:-1,loadedRadius:320,springRate:60,actuation:"direct"}}),305.4,309)}function YO(e,t,r,n,o,a){let s=hp(),i=Object.fromEntries(Object.entries(s.hardpoints).map(([l,[u,m,d]])=>[l,[u,m+e,d]])),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:nw(n),springRate:o,rackTravel:a}}}function ow(){return bs({name:"Cup car",front:YO(55,-25,-23,-3.5,150,55),rear:i0(Ic(),{kx:1.15,ky:820/Wo,kz:320/jo,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 aw(){return{...bs(Yo({name:"Stock car",wheelbase:2794,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/gs,kz:355/ys,lowerInnerDz:20,upperInnerDz:5,camberDeg:-2.5,loadedRadius:355,springRate:175,actuation:"direct"},rear:{kx:1.2,ky:825/Wo,kz:355/jo,lowerInnerDz:40,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:150,actuation:"direct"}}),343.8,345.3),chassis:{boxes:[],body:"nascar"}}}function sw(){let e=bs(Yo({name:"Hill-climb prototype",wheelbase:2550,trackFront:1580,trackRear:1540,front:{kx:1.1,ky:790/gs,kz:300/ys,lowerInnerDz:10,upperInnerDz:5,camberDeg:-2.5,loadedRadius:300,springRate:90},rear:{kx:1.1,ky:770/Wo,kz:300/jo,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 iw(){let e=bs(Yo({name:"Race truck",wheelbase:3700,trackFront:2050,trackRear:1950,front:{kx:1.5,ky:1025/gs,kz:506/ys,lowerInnerDz:40,upperInnerDz:10,camberDeg:-.5,loadedRadius:506,springRate:200,actuation:"direct"},rear:{kx:1.5,ky:975/Wo,kz:506/jo,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 yt=(e,t,r)=>({value:e,label:t,unit:r}),cw=(e,t)=>({...Er[e],value:t});function lw(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 Xo(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 kn(e){let t={name:e.name,m:yt(e.m,"vehicle mass (with driver)","kg"),A:yt(e.A,"frontal area","m^2"),c_l:yt(e.cl,"downforce coefficient","-"),c_w:yt(e.cw,"drag coefficient","-"),l_to_d_ratio:yt(e.cw>0?e.cl/e.cw:0,"lift-to-drag ratio","-"),driven_wheels:yt(e.drivenWheels,"driven wheels","-"),fr_0:yt(-.012,"rolling-resistance coefficient","-"),front_aero_diss:yt(e.frontAero,"front aero distribution","-"),front_mass_diss:yt(e.frontMass,"front mass distribution","-"),r_dyn:yt(e.rDyn,"dynamic tyre radius","m"),rho:yt(1.2,"air density","kg/m^3"),gear_ratio:yt(e.gearRatio,"gear ratio","-"),effi_pgb:yt(e.drivetrainEfficiency,"drivetrain efficiency","-"),capacity:yt(e.capacityAh,"pack capacity","Ah"),soc:yt(1,"state of charge","-"),ocv:yt(e.ocv,"pack open-circuit voltage","V"),power_scale:yt(1,"power scaling factor","-"),power_limit_kw:cw("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]=cw(r,n);return t}var xs={name:"Formula Student",m:300,A:1,cl:3,cw:1.3,frontMass:.47,frontAero:.45,rDyn:.222,drivenWheels:2,gearRatio:11.5,motor:lw(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}},u0={name:"Formula 1",m:798,A:1.5,cl:3,cw:.9,frontMass:.46,frontAero:.44,rDyn:.35,drivenWheels:2,gearRatio:4.9,motor:Xo(735,2e3,12500,2500,2),motorCount:1,driveline:{rear:Gt.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}},bp={name:"GT car",m:1300,A:2,cl:1.4,cw:.42,frontMass:.5,frontAero:.42,rDyn:.33,drivenWheels:2,gearRatio:3.43,motor:Xo(410,2e3,8e3,2e3,2),motorCount:1,driveline:{rear:Gt.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}},gp={name:"Sports car",m:1600,A:2.2,cl:-.1,cw:.3,frontMass:.55,frontAero:.5,rDyn:.32,drivenWheels:2,gearRatio:3.14,motor:Xo(220,1500,6500,1400,2),motorCount:1,driveline:{rear:Gt.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}},m0={name:"Cup car",m:1265,A:2.1,cl:.45,cw:.4,frontMass:.62,frontAero:.45,rDyn:.31,drivenWheels:2,gearRatio:3.5,motor:Xo(250,2e3,7e3,1190,2),motorCount:1,motorPlacement:"front",driveline:{front:Gt.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}},p0={name:"Stock car",m:1620,A:2.2,cl:.6,cw:.45,frontMass:.53,frontAero:.45,rDyn:.35,drivenWheels:2,gearRatio:4.1,motor:Xo(500,2500,9e3,1680,2),motorCount:1,driveline:{rear:Gt.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}},d0={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:Xo(330,3e3,8500,1240,2),motorCount:1,driveline:{rear:Gt.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}},f0={name:"Race truck",m:5300,A:6.2,cl:-.1,cw:.65,frontMass:.6,frontAero:.6,rDyn:.502,drivenWheels:2,gearRatio:3.55,motor:Xo(880,100,3e3,88e3,2),motorCount:1,driveline:{rear:Gt.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 l0(e,t,r){return kn(r({...structuredClone(e),name:t}))}var yp={[xs.name]:kn(xs),"Formula Student +15% downforce":l0(xs,"Formula Student +15% downforce",e=>({...e,cl:e.cl*1.15,cw:e.cw*1.08})),"Formula Student -15 kg":l0(xs,"Formula Student -15 kg",e=>({...e,m:e.m-15})),"Formula Student +15% power":l0(xs,"Formula Student +15% power",e=>({...e,motor:lw(25*1.15,15e3,2e4),powerLimitKw:80*1.15})),[u0.name]:kn(u0),[bp.name]:kn(bp),[gp.name]:kn(gp),[m0.name]:kn(m0),[p0.name]:kn(p0),[d0.name]:kn(d0),[f0.name]:kn(f0)},uw=Object.keys(yp),h0=uw.slice(0,4),b0=[xs.name,u0.name,bp.name,gp.name,m0.name,p0.name,d0.name,f0.name];var Rae={"Touring car":bp.name,"Street car":gp.name};var WO={bg:"#11141b",panel:"#161b22",panel2:"#202d3a",border:"#334050",borderBright:"#526477",sunken:"#0b1219",ink:"#06090d"},jO={normal:"#eef3fa",dim:"#9baab9",bright:"#ffffff",white:"#ffffff"},UO={label:"#c8d2dc",grid:"#39424e",gridFaint:"#232b35",empty:"#1a2028"},XO={accent:"#6aa8ff",accentInk:"#0d1b30",warn:"#ffb454",good:"#4ec9a0",bad:"#ff6b6b",badSoft:"#ff8f8f"},qO=["#f0e442","#7b68ee","#f7a8b8","#d55e00","#d8b4fe","#b5e48c"],xp={front:"#a6e22e",rear:"#00b4d8"},mw=["#5b4bd6","#4aa3ff","#4ec9a0","#f0e442"],g0={power:"#ffb454",traction:"#f0845c",front:xp.front,rear:xp.rear,grip:"#73c9b3",braking:"#b48aff",crest:"#e88fd0",below:"rgba(214, 221, 230, 0.32)"},QO={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"},ZO={x:"#ff6b6b",y:"#57c75a",z:"#4aa3ff"},JO={line:"#b4bfcb"},eV={compression:"#b48aff",tension:"#ff6b6b"},tV={fz:"#e7ecf3",fx:"#7ad7f0",fy:"#ff54c8"},rV={drivenLine:"#4d7cff",axis:"#eef3fa",slip:"#ffe81a",drive:g0.power,brake:g0.braking},nV={ground:"#101920",grid:"#1a2630",gridMajor:"#26343f",horizon:"#1d2833",bridge:"#6f7a86",coneLeft:"#2f63c9",coneRight:"#d9b51f",coneStart:"#ee7a2c"},oV={chassis:"#435160",volume:"#303b47",tyre:"#435160",tyreLine:"#39424e",tyreFace:"#1c232d"},aV={centreLine:"#4aa3ff",corridorFill:"rgba(74,163,255,0.10)",boundary:"#3d4956",racingLine:"#ffb454",start:"#e7ecf3",finish:"#ff6b6b",direction:"#8b96a3"},sV={SURFACE:WO,TEXT:jO,CHART:UO,ROLE:XO,SERIES:qO,AXLE:xp,LAP_SPEED:mw,LIMITER:g0,RIG:QO,AXIS:ZO,CONSTRUCTION:JO,FORCE:eV,TYRE_FORCE:tV,REPLAY:rV,SCENERY:nV,BODY:oV,TRACK:aV},pw=e=>Object.fromEntries(Object.entries(e).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):Object.freeze({...r})])),Rp=pw(sV),Ht=Rp.SERIES,dw=(()=>{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 pw({SURFACE:{bg:"#f5f6f6",panel:"#fcfcfd",panel2:"#ffffff",border:"#d8dfe6",borderBright:"#b7c3ce",sunken:"#e8edf2",ink:"#ffffff"},TEXT:{normal:"#17212c",dim:"#606c79",bright:"#10171f",white:"#000000"},CHART:{label:"#3a424b",grid:"#c2c8cd",gridFaint:"#e2e5e7",empty:"#e8eae7"},ROLE:{accent:"#2162bd",accentInk:"#ffffff",warn:e,good:"#0f8a66",bad:t,badSoft:"#e2696d"},SERIES:["#b5a11a","#2844e3","#f47ec1","#9b3a1b","#764299","#58b977"],AXLE:r,LAP_SPEED:["#4b3bc4","#1a64c2","#0f8a66","#a87e00"],LIMITER:n,RIG:{chassis:"#1a64c2",ballJoint:"#c27200",arm:"#56616d",tie:"#24907b",pushrod:"#a3820f",rocker:"#6656b8",kingpin:"#8f7f10",arbBar:"#b04d77",arbArm:"#9a4767",arbLink:"#c27200",heaveSpring:"#1688ad",wheelCentre:"#15181c",contactPatch:t,ground:"#e2e6e8",groundFaint:"#edf0f1"},AXIS:{x:"#d93a3a",y:"#2f9d34",z:"#1a64c2"},CONSTRUCTION:{line:"#5a6570"},FORCE:{compression:"#7b55d0",tension:t},TYRE_FORCE:{fz:"#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 fw=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},kae=(()=>{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=dw[r];for(let a of Object.keys(n)){let s=fw(n[a]);s&&!e.has(s)&&e.set(s,o[a])}}return e})();var hw=(e,t)=>new Set(t.flatMap(r=>{let n=e[r];return Array.isArray(n)?[...n]:Object.values(n)}).map(fw).filter(r=>r!==null)),Mae=hw(dw,["SERIES","AXLE","LAP_SPEED","LIMITER","ROLE","RIG","FORCE","TYRE_FORCE","REPLAY","AXIS","TRACK","CONSTRUCTION"]),Sae=hw(Rp,Object.keys(Rp).filter(e=>e!=="SURFACE"));function y0(){return{kind:"simple",name:"Simple motor",rpm:[0,16e3,2e4],torque:[21,21,14],efficiency:.95}}function x0(){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 R0(){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 v0(){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 k0(){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 bw(){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 gw(){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 yw(){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 xw(){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 Rw(){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 vw(){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 kw(e){return Go(iV(e))}function iV(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 Oc(e,t){return{...t,fingerprint:kw(e)}}var Mw="CC-BY-4.0",cV={title:"PaceDynamics built-in library",url:"https://pacedyn.dev/",licence:Mw},Sw={fidelity:"generic",licence:Mw,sources:[cV]};var vp=e=>Oc(e,Sw);var Aw=["raw.githubusercontent.com"],ww=["tum-csv"],uV=/^[0-9a-f]{64}$/;function Bc(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"||!uV.test(r)||!ww.includes(n))return!1;try{let o=new URL(t);return o.protocol==="https:"&&Aw.includes(o.hostname)&&!o.username&&!o.password&&!o.port}catch{return!1}}var kp=e=>new URL(e.url).hostname;async function Fw(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 mV(e){let t=new URL(e).pathname.split("/").pop()??"";return decodeURIComponent(t).replace(/\.[^.]*$/,"")||"Linked track"}function pV(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 dV={"tum-csv":pV};function Cw(e,t){return dV[t.format](e,mV(t.url))}async function M0(e,t,r){let n=await Fw(e);if(n!==t.sha256)throw new Error(`${kp(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=Cw(new TextDecoder().decode(e),t),a=await Mp(o);if(a!==r)throw new Error(`Linked track ${r} does not convert to its name (it is ${a}).`);return o}var S0=20,hV=new RegExp(`^[0-9a-f]{${S0}}$`),$c=e=>typeof e=="string"&&hV.test(e);async function Mp(e){let t=new TextEncoder().encode(Un(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,S0)}var A0=e=>`tracks/${e}.json`;var bV=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function w0(e){return{model:{name:e.name,source:e.source},...e.provenance?{provenance:e.provenance}:{}}}async function F0(e,t){if(!bV(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 Mp(e);if(r!==t)throw new Error(`Catalogue track ${t} does not match its name (it is ${r}).`);return e}var qo=(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}),Xn=[qo("suspensions","suspensionId","suspension"),qo("tires","tireModelId","tyre",[{key:"tiresRear",ref:"tireModelIdRear",label:"rear tyre"}]),qo("motors","motorModelId","motor"),qo("aeros","aeroModelId","aero map"),qo("batteries","batteryModelId","battery"),qo("brakes","brakeModelId","brakes"),qo("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 Xn)for(let n of r.refs)delete t[n];return t}var Ap=Ht,Gc=Ap,C0=Ap,qn=[...Ht.slice(3),...Ht.slice(0,3)],L0=[...Ht.slice(1),Ht[0]],T0=[...Ht.slice(2),...Ht.slice(0,2)],P0=[...Ht.slice(4),...Ht.slice(0,4)],D0=[...Ht.slice(5),...Ht.slice(0,5)],Kc=[...Ht.slice(2),...Ht.slice(0,2)];function E0(){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 I0(e,t,r){let n=yp[e];if(!n)throw new Error(`no preset vehicle named "${e}"`);return{id:t,params:{...Hi(structuredClone(n)),energy:{...sn},suspensionId:"sus1"},visible:!0,color:Gc[r%Gc.length]}}function xV(){return h0.map((e,t)=>I0(e,`v${t+1}`,t))}function RV(){return[yi(),fh(),hh(),bh(),gh(),yh(),xh(),Rh(),vh(),kh()].map((t,r)=>({id:`t${r+1}`,color:C0[r%C0.length],model:t}))}function vV(){return[jd(),Ud(),Xd(),qd(),Qd(),Zd(),Jd(),ef()].map((t,r)=>({id:`a${r+1}`,color:T0[r%T0.length],model:t}))}function kV(){return[Dd(),Ed(),Id()].map((t,r)=>({id:`b${r+1}`,color:P0[r%P0.length],model:t}))}function MV(){return[{id:"brk1",color:D0[0],model:structuredClone(Gh)}]}function SV(){return[{id:"dmp1",color:Kc[0],model:structuredClone(Zu)}]}function AV(){return[y0(),x0()].map((t,r)=>({id:`m${r+1}`,color:qn[r%qn.length],model:t}))}function _0(e){let t=r=>({...r,provenance:vp(r.model)});return{...e,suspensions:e.suspensions.map(t),vehicles:e.vehicles.map(r=>({...r,provenance:vp(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 Hc(e="Untitled project"){let t=new Date().toISOString(),r=xV();return _0({schemaVersion:up,meta:{id:E0(),name:e,domain:"racecar",rulesetId:Ko,createdAt:t,updatedAt:t},suspensions:[{id:"sus1",color:L0[0],model:Uo()}],activeSuspensionId:"sus1",vehicles:r,activeVehicleId:r[0]?.id??null,tires:RV(),motors:AV(),aeros:vV(),batteries:kV(),brakes:MV(),dampers:SV(),tracks:[],activeTrackId:null,mathChannels:[],rulesets:[],studies:[],activeStudyId:null,loadCases:[],reportLayouts:[],tyreSheets:[],kinSheets:[],lapSheets:[],plans:[],results:[],settings:{numerics:{...oc},ggvMode:"twoTrack",quasiTransient:!1,motorThermal:!1,brakeFade:!1,airTempC:Ut,air:structuredClone(pp),diffYaw:!1,lapCounts:{},pathPlanId:null,useRacingLine:!0,standingStart:!1}})}var wV=["front","rear"],N0=9.81,FV=Math.PI/180;var Kr="*",O0=40,Tw=.8;function V0(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 Pw(e,t,r){let n=t.rows.map(c=>c.v),o=c=>ht(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/N0*100)/100+0,axG:Math.round(u/N0*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(O0/3.6,o(O0/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(Tw*s,o(Tw*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 B0(e,t,r){let n=!1,o=e.map(a=>{if(!a.follows)return a;let s=Pw(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 $0(e,t){let r=e.speedKmh/3.6,n=e.ayG*N0;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)/FV}var Lw=e=>e.ayG<0?"L":"R";function G0(e,t=wV){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 Mn=Math.PI/180,CV=9.81,zc=.1,H0=20,Dw=6,Nw=50;function Ew(e,t,r){let n=e(0),o=0;for(let d=t;d<=r+1e-9;d+=t){let p=e(d);if(p>n)n=p,o=d;else if(d>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 d=0;d<14;d++)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 z0(e,t,r,n,o){let a=o*Mn;if(t==="side")return Ew(i=>r*e.Fy(r*i*Mn,n,a),1,45);let s=t==="drive"?1:-1;return Ew(i=>s*e.Fx(s*i,n,a),.02,.6)}function Fp(e){let t=e?bu(e)?.gamma:void 0,r=[t?.min,t?.max].filter(o=>o!==void 0&&Number.isFinite(o));if(!r.length)return{lo:-Dw,hi:Dw,stated:!1};let n=Math.max(...r.map(Math.abs))/Mn;return{lo:-n,hi:n,stated:!0}}function TV(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 f=0;f<n;f++){let b=t+f*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),d=e(u),p=e(m);for(let f=0;f<12;f++)d>p?(c=m,m=u,p=d,u=c-l*(c-i),d=e(u)):(i=u,u=m,d=p,m=i+l*(c-i),p=e(m));let h=d>=p?{g:u,v:d}:{g:m,v:p};return h.v>s?h.g:a}var Iw=250,_w=new WeakMap;function PV(e,t,r,n,o,a,s){let i=_w.get(e);i||_w.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=h=>{let f=l.get(h);if(f===void 0){let b=Math.max(50,h*Iw);f=TV(g=>z0(r,n,o,b,g).force,s.lo,s.hi),l.set(h,f)}return f},m=Math.max(0,a)/Iw,d=Math.floor(m),p=m-d;return p<1e-9?u(d):u(d)*(1-p)+u(d+1)*p}function Rs(e,t){return t==="front"?e.tireModel:e.tireModelRear??e.tireModel}var LV=new WeakMap,DV=new WeakMap,EV=new WeakMap,Y0=(e,t,r)=>{let n=e.get(t);return n===void 0&&e.set(t,n=r()),n};function Cp(e,t){let r=Rs(e,t);return r?Y0(LV,r,()=>mi(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 W0(e,t){let r=Rs(e,t);return r?Y0(EV,r,()=>gu(r).none)?"This tyre file has no drive or brake grip.":Y0(DV,r,()=>{let n=_e(r),o=r.kind==="magic"?r.fnomin:r.nominalLoad,a=n.Fx(.1,o,0),s=n.Fx(.1,o,3*Mn);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 Qo(e,t){return e==="side"||e==="ackermann"?Math.abs(t.ayG)>=zc?e==="ackermann"&&!(Ow(t)<=H0)?`is a corner wider than ${H0} m`:null:"does not corner":(e==="drive"?t.axG:-t.axG)>=zc?null:e==="drive"?"does not drive":"does not brake"}var IV=e=>e.axG>=zc?"drive":e.axG<=-zc?"brake":null;function Ow(e){let t=e.speedKmh/3.6,r=Math.abs(e.ayG)*CV;return r>1e-9?t*t/r:1/0}var wp=(e,t)=>`${e==="front"?"F":"R"}${t}`,_V=e=>e==="L"?"R":"L",NV=(e,t,r)=>Math.min(r,Math.max(t,e));function j0({ev:e,params:t,input:r,state:n,pose:o}){let a=`${re(t,"grip_scale")}|${re(t,"stiffness_scale")}`,s=Ow(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,R,M,A)=>{let F=Fe(e,k),T=Rs(t,k),P=Math.max(0,o.loads[v]),S=o.camber[v],w=NV(S,A.lo,A.hi),C=z0(F,R,M,P,w),L=P<Nw,E=T&&!L?PV(T,a,F,R,M,P,A):w,_=L?C.force:z0(F,R,M,P,E).force,O=.05;return{corner:v,Fz:P,lifted:L,camber:S,read:w,outside:w!==S,wants:E,atEdge:!L&&(E-A.lo<O||A.hi-E<O),peak:C.force,slip:C.at,best:_}},d=(k,v,R)=>{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:R}},p=new Map,h=k=>{if(p.has(k))return p.get(k)??null;let v=null;if(!Qo("side",n)){let R=Fp(Rs(t,k));v=[m(k,wp(k,o.outer),"side",1,R),m(k,wp(k,_V(o.outer)),"side",-1,R)]}return p.set(k,v),v},f=new Map,b=new Map,g=new Map,y=(k,v,R)=>{let M=k==="front"?i:-c,A=(v?1:-1)*u(k),F=R*Mn;return Math.atan2(M+s*Math.sin(F),s*Math.cos(F)-A)/Mn},x=k=>(n.ayG<0?-1:1)*o.steer[k];return{side(k){if(f.has(k))return f.get(k)??null;let v=Cp(t,k)?null:h(k),R=v?d("side",v,Fp(Rs(t,k))):null;return f.set(k,R),R},long(k){if(b.has(k))return b.get(k)??null;let v=IV(n),R=null;if(v&&!W0(t,k)){let M=Fp(Rs(t,k));R=d(v,[m(k,wp(k,"L"),v,1,M),m(k,wp(k,"R"),v,1,M)],M)}return b.set(k,R),R},toeLoss(k){let v=g.get(k);if(v!==void 0)return v;let R=h(k),M=NaN;if(R&&R[0].peak+R[1].peak>0){let A=Fe(e,k),[F,T]=R,P=[{g:F,dt:1,inner:!1,steer:x(F.corner)},{g:T,dt:-1,inner:!0,steer:x(T.corner)}],S=_=>P.reduce((O,I)=>{let z=I.steer-y(k,I.inner,_);return O+I.dt*A.Fy(I.dt*z*Mn,I.g.Fz,I.g.read*Mn)},0),w=P.map(_=>_.steer-_.g.slip-y(k,_.inner,0)),C=Math.min(...w)-2,L=Math.max(...w)+2,E=OV(S,C,L,.25);M=Math.max(0,1-E/(F.peak+T.peak))}return g.set(k,M),M},ackermann(){if(Qo("ackermann",n))return NaN;let k=h("front");if(!k||k[0].lifted||k[1].lifted)return NaN;let[v,R]=k,M=Math.sqrt(Math.max(s*s-c*c,1e-6)),A=u("front"),F=(Math.atan(l/(M-A))-Math.atan(l/(M+A)))/Mn;if(!(F>.001))return NaN;let T=x(R.corner)-x(v.corner),P=F+(R.slip-v.slip);return 100*(T-P)/F}}}function OV(e,t,r,n){let o=-1/0,a=t;for(let p=t;p<=r+1e-9;p+=n){let h=e(p);h>o&&(o=h,a=p)}let s=a-n,i=a+n,c=.6180339887498949,l=i-c*(i-s),u=s+c*(i-s),m=e(l),d=e(u);for(let p=0;p<14;p++)m>d?(i=u,u=l,d=m,l=i-c*(i-s),m=e(l)):(s=l,l=u,m=d,u=s+c*(i-s),d=e(u));return Math.max(o,m,d)}var VV=9.81,Vw=Math.PI/180,Yc={speed:20,ayG:1.2};function U0(e,t={}){let r=t.operating??Yc,n=t.assemble,o,a,s,i=new Map,c=new Map,l=new Map,u=new Map,m=new Map,d=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},h=()=>{if(a!==void 0)return a;try{a=Nr(e.params)}catch{a=null}return a},f=v=>{let R=d(v),M=`${R.speed}|${R.ayG}`,A=i.get(M);if(A!==void 0)return A;let F=h();if(!F)return i.set(M,null),null;let T={cornerStiffness:P=>F.corneringStiffness(P),ayG:R.ayG,speed:R.speed,fyAxle:(P,S)=>2*F.Fy(P,S/2),tire:F};return i.set(M,T),T},b=()=>{if(s!==void 0)return s;let v=p(),R=h();if(!v||!R)return s=null;try{s=So(R,v.massTotal*VV*1.2)}catch{s=null}return s},g=v=>{let R=d(v).speed,M=`${R}`,A=c.get(M);if(A!==void 0)return A;let F=p(),T=h(),P=null;if(F&&T)try{P=_b(F,T,R,{steering:!1})}catch{P=null}return c.set(M,P),P},y=v=>{let R=`${v.speedKmh}|${v.ayG}|${v.axG}`,M=m.get(R);if(M!==void 0)return M;let A=null,F=p();try{let T=F?.kinFront,P=F?.kinRear;if(F&&T&&P){let S=$0(v,F.wheelbase),w=v.speedKmh/3.6,C=Vn(F,T,P,w)(v.ayG,v.axG,0,S),L={FL:C.FL.travel,FR:C.FR.travel},E=wo(F,S*Vw,L),_=S?E.camber:null,O={},I={};for(let B of["FL","FR","RL","RR"]){let V=B[1]==="R"?C[B].camberRoad:0-C[B].camberRoad;O[B]=V+(_?.[B]??0),I[B]=E.steer[B]/Vw+(B[1]==="R"?1:-1)*C[B].bumpToe}let z=$e(F,v.ayG,v.axG,w,0,S,L,C.steeringJacking);A={corners:C,rollDeg:C.FL.camberRoad-C.FL.camber,steerDeg:S,camber:O,outer:Lw(v),loads:z,steer:I}}}catch{A=null}return m.set(R,A),A},x=new Map;return{operating:r,dynAvailable:!!n,poseAt:y,tyreAt:v=>{let R=`${v.speedKmh}|${v.ayG}|${v.axG}`,M=x.get(R);if(M!==void 0)return M;let A=y(v),F=p(),T=h(),P=A&&F&&T?j0({ev:T,params:e.params,input:F,state:v,pose:A}):null;return x.set(R,P),P},operatingAt:d,dynInput:p,tyre:h,dynCtx:f,grip:b,ymd:g,ymdLimit:v=>{let R=`${d(v).speed}`,M=l.get(R);if(M!==void 0)return M;let A=g(v),F=A?bg(A):null;return l.set(R,F),F},reserves:(v,R)=>{let M=d(R),A=`${v}|${M.speed}|${M.ayG}`,F=u.get(A);if(F!==void 0)return F;let T=p(),P=f(R),S=null;if(T&&P)try{S=uc(T,P,v,b()??void 0)}catch{S=null}return u.set(A,S),S}}}var Bw=["widthLeft","widthRight","bank","mu"];function Wc(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 X0(e){let t=Wc(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 d of Bw){let p=l[d];if(p===void 0)continue;let h=s[d],f=r[d];for(let b=0;b<o&&t[b]<l.from;b++)f=h[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;h[b]=u>0&&y<u?f+(p-f)*(y/u):p}}}return s}function Lp(e,t,r){if(!t.length)return e;let n=Wc(e),o=n.length,a={widthLeft:Tp(e.widthLeft,r.widthLeft),widthRight:Tp(e.widthRight,r.widthRight),bank:Tp(e.bank,r.bank),mu:Tp(e.mu,r.mu)},s={};for(let c of Bw){let l=e[c];Array.isArray(l)&&l.length===o&&(s[c]=l)}let i=Pp(t,n,a,s);return{...e,...i}}function Tp(e,t){return typeof e=="number"?e:t}var Kw=1,$w=4,Ep=Math.PI/180,q0=e=>e===null||!Number.isFinite(e)||e===0?0:1/e;function Q0(e){return e.kind==="arc"?Math.abs(e.radius)*Math.abs(e.angle)*Ep:e.length}function Dp(e,t){return e.kind==="straight"?0:e.kind==="arc"?q0(e.radius):t}function Gw(e){return e.kind==="straight"?0:e.kind==="arc"?q0(e.radius):q0(e.endRadius)}var jc=(e,t,r,n,o)=>e+t*o+(n>0?(r-t)*o*o/(2*n):0);function Uc(e,t={}){let r=Math.max(.05,t.spacing??Kw),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,w)=>S+Q0(w),0),m=Math.max(n?3:2,Math.round(u/r)),d=u>0?u/m:r,p=o.x,h=o.y,f=o.heading*Ep,b=e.length?Dp(e[0],0):0,g=0,y=d,x=(S,w,C)=>{s.push(S),i.push(w),c.push(C)};x(p,h,0);let k=(S,w,C,L,E)=>{let _=E-L;if(_<=0)return;if(Math.abs(w-S)<1e-12){let I=jc(f,S,S,C,L);if(Math.abs(S)<1e-12)p+=_*Math.cos(I),h+=_*Math.sin(I);else{let z=I+S*_;p+=(Math.sin(z)-Math.sin(I))/S,h+=-(Math.cos(z)-Math.cos(I))/S}return}let O=_/$w;for(let I=0;I<$w;I++){let z=L+I*O,B=jc(f,S,w,C,z),V=jc(f,S,w,C,z+O/2),j=jc(f,S,w,C,z+O);p+=O/6*(Math.cos(B)+4*Math.cos(V)+Math.cos(j)),h+=O/6*(Math.sin(B)+4*Math.sin(V)+Math.sin(j))}};for(let S of e){let w=Q0(S),C=Dp(S,b),L=Gw(S);if(l.push({from:g,to:g+w,...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}:{}}),w<=0){b=L;continue}let E=0;for(;y<=g+w+1e-9;){let _=Math.min(w,y-g);k(C,L,w,E,_),E=_,x(p,h,g+_),y+=d}k(C,L,w,E,w),f=jc(f,C,L,w,w),b=L,g+=w}let v=s.length>1?Math.hypot(s[0]-s[s.length-1],i[0]-i[i.length-1]):0,R=g;n&&s.length>1&&(s.pop(),i.pop(),c.pop());let M=e.length?Dp(e[0],b):0,A={gap:v,headingError:BV((f-o.heading*Ep)/Ep),curvatureError:b-M},F=[];for(let S=0;S<e.length;S++){let w=Gw(e[S]),C=S+1<e.length?e[S+1]:n?e[0]:null;if(!C)continue;let L=Dp(C,w);F.push({index:S,before:w,after:L,jump:Math.abs(L-w)})}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:F,closure:A,length:R}}function BV(e){let t=e%360;return t>180&&(t-=360),t<-180&&(t+=360),t}var $V={halfWidthM:1.5,spacingM:.5};function Xc(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 ${zw(e).toFixed(0)} m`}}}function zw(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 Yw=e=>e.kind==="skidpad"||e.kind==="curves"&&e.closed===!0,Ww=e=>e.kind==="acceleration",jw=1.5,Uw=3;function GV(e,t){let r=e.offsetM,n=e.pitchM,o=Math.max(1,e.gates)*n,a=Math.max(0,e.leadInM),s=jw*n,i=f=>{let b=Math.min(1,Math.max(0,f));return b*b*b*(b*(b*6-15)+10)},c=f=>Math.min(i(f/s),i((o-f)/s)),l=r*(Math.PI/n)**2,u=l>0?Math.max(.05,Math.min(t.spacingM,1/l*(Uw*Math.PI/180))):t.spacingM,m=[],d=[],p=Math.max(1,Math.round(a/u));for(let f=0;f<p;f++)m.push(-a+a*f/p),d.push(0);let h=Math.max(8,Math.round(o/u));for(let f=0;f<=h;f++){let b=o*f/h;m.push(b),d.push(r*c(b)*Math.sin(Math.PI*b/n))}return{name:Xc(e),x:m,y:d,closed:!1,widthLeft:t.halfWidthM,widthRight:t.halfWidthM,fit:"interpolate"}}function KV(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 Z0(e,t={}){let r={...$V,...t},n=Ww(e),o=KV(e);if(!o){let u=GV(e,r);return{asset:u,peakCurvature:Hw(u),worstJoint:0,standingStart:n}}let a=Yw(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*(Uw*Math.PI/180))):r.spacingM,c=Uc(o,{name:Xc(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:Hw(c.asset),worstJoint:l.reduce((u,m)=>Math.max(u,m.jump),0),standingStart:n}}function Hw(e){try{return Math.max(...wt(e).curvature.map(Math.abs))}catch{return NaN}}var _p={courses:[{id:"c1",course:{kind:"manoeuvre",spec:{kind:"skidpad",radiusM:8.375}}}],ggvMode:"twoTrack"};function J0(e){return e.course.kind==="project"?"the project\u2019s track":e.course.kind==="track"?e.course.name:Xc(e.course.spec)}var Xw=new WeakMap,Ip=new Map;function qw(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=Ip.get(n);if(o)return{...o,numerics:r};let a=Z0(e.spec),s={asset:a.asset,standingStart:a.standingStart};return Ip.size>64&&Ip.clear(),Ip.set(n,s),{...s,numerics:r}}function ey(e,t,r={}){let n=r.lap??_p,o=r.simParams,a=r.numerics??{},s=n.courses.length?n.courses:_p.courses,i,c,l,u=new Map,m=new Map,d=new Map,p=new Map,h=k=>(k?.courseId?s.find(v=>v.id===k.courseId):void 0)??s[0],f=()=>{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=h(k);if(!v)return null;let R=m.get(v.id);if(R!==void 0)return R;let M=qw(v.course,r,a),A=null;if(M)try{let F=JSON.stringify(M.numerics),T=Xw.get(M.asset);T||(T=new Map,Xw.set(M.asset,T));let P=T.get(F);P||(P=wt(M.asset,M.numerics),T.set(F,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=f();if(!k)return c=null;try{l=Xt(k),c=Vr(l,!1,n.ggvMode)}catch{c=null}return c},y=k=>{let v=b(k);if(!v)return null;let R=d.get(v.id);if(R!==void 0)return R;let M=g(),A=null;if(M)try{let F=l?Vo(l,M,[v.track],v.numerics,n.ggvMode,u):void 0,T=l?Wn(l,M.rows):void 0;A=Kt(M,v.track,v.numerics,{standingStart:v.standingStart,...F?{load:F}:{},...T?{shifts:T}:{}})}catch{A=null}return d.set(v.id,A),A};return{lapSettings:n,get lapAvailable(){return!!o&&s.some(k=>!!qw(k.course,r,a))},lapParams:f,courses:()=>s,course:b,ggv:g,lap:y,lapReserve:k=>{let v=b(k);if(!v)return null;let R=p.get(v.id);if(R!==void 0)return R;let M=y(k),A=t.dynInput(),F=t.tyre(),T=null;if(M&&A&&F)try{let P=f();T=Bm(A,F,Um({...M,ds:v.track.ds,rows:g()?.rows,gradient:v.track.gradient,bank:v.track.bank,mu:v.track.mu}),P?{driven:rb(P)}:{})}catch{T=null}return p.set(v.id,T),T}}}var Qw=180/Math.PI,ty={rise:0,sinPitch:0,sinRoll:0};function Zw(e){let t=e.kc;return t?Jw(e.vehicle,r=>t.ground0[r]):ty}function Jw(e,t){let r=e.config,n=En(r),o=0,a=0,s=0,i=0,c=0,l=0,u=0,m=0,d=0;for(let g of wr){let y=nt(g,r),x=y.axleX-n,k=y.sideSign*ar(e,y.isFront)/2,v=t(g);if(!Number.isFinite(v))return ty;o++,a+=x,s+=k,i+=v,c+=x*x,l+=k*k,u+=x*k,m+=x*v,d+=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 h=(i*(c*l-u*u)-a*(m*l-u*d)+s*(m*u-c*d))/p,f=(o*(m*l-u*d)-i*(a*l-u*s)+s*(a*d-m*s))/p,b=(o*(c*d-m*u)-a*(a*d-m*s)+i*(a*u-c*s))/p;return{rise:h,sinPitch:f,sinRoll:-b}}function qc(e,t){let r=e.kc,n=Jw(e.vehicle,o=>(r?r.ground0[o]:0)+t[o]);return te([-n.sinPitch,n.sinRoll,1])}function ry(e,t,r,n){let o=te(qr(e,nt(t,r)));return-Math.asin(Math.max(-1,Math.min(1,J(o,n))))*Qw}function Np(e,t,r,n,o){let a=te(qr(n,nt(t,r))),s=te([1-a[0]*a[0],-a[0]*a[1],-a[0]*a[2]]),i=le(a,s),c=p=>[J(p,s),J(p,i),J(p,a)],l=p=>oe(oe(Q(s,p[0]),Q(i,p[1])),Q(a,p[2])),u=e.points,m=c(u.spinAxis),d=Ks({uprightUpper:c(u.uprightUpper),uprightLower:c(u.uprightLower),wheelCenter:c(u.wheelCenter),spinAxis:m,tieOuter:c(u.tieOuter),loadedRadius:o.loadedRadius,patchShift:o.patchShift&&HV(o.patchShift,e.metrics.toe/Qw,Math.atan2(m[0],m[1]))});return{caster:d.caster,kpi:d.kpi,scrubRadius:d.scrubRadius,mechanicalTrail:d.mechanicalTrail,scrubAtWheel:d.scrubAtWheel,trailAtWheel:d.trailAtWheel,kingpinOffset:d.kingpinOffset,casterOffset:d.casterOffset,kingpinGround:l(d.kingpinGround),contactPatch:l(d.contactPatch),elbow:l([d.contactPatch[0],d.kingpinGround[1],d.kingpinGround[2]]),kingpinAtHub:l(d.kingpinAtHub)}}function HV(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 Op(e,t){let r=Zw(t);if(r===ty)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 Qn(e,t,r){let n=Op({heave:0,pitch:0,roll:0,steer:0},r);return e-hf(n,[t,0,0],En(r.vehicle.config))}var zV=180/Math.PI;function ny(e,t){return!e.valid||!e.ic?!1:Math.hypot(e.ic[0]-e.cp[0],e.ic[1]-e.cp[1])<=t}function Vp(e,t,r){let n=nt(t,e.vehicle.config),o=Vt(e,r),a=am(e,t,o[t]),s=a.at("uprightUpper"),i=a.at("uprightLower"),c=a.at("contactPatch"),l=a.at("wheelCenter"),u=w=>{let C=a.velocity(w);return[C[0],C[2]]},m=u(c),d=u(l),p=[c[0],c[2]],h=[l[0],l[2]];if(!a.solved)return{ic:null,line:null,cp:p,wc:h,road:[1,0],swingArmAngleDeg:NaN,tanTheta:NaN,tanThetaHub:NaN,valid:!1,unsolved:!0,sinAngle:0};let f=qc(e,{FL:o.FL.ground,FR:o.FR.ground,RL:o.RL.ground,RR:o.RR.ground}),b=Math.hypot(f[0],f[2]),g=[f[0]/b,f[2]/b],y=[g[1],-g[0]],x=w=>{let C=w[0]*g[0]+w[1]*g[1];return Math.abs(C)>1e-9?-(w[0]*y[0]+w[1]*y[1])/C:0},k=a.omega[1],v=Math.hypot(m[0],m[1]),R=Math.abs(k)*1e9>v?[p[0]+m[1]/k,p[1]-m[0]/k]:null,A=R?(w=>{let C=[s[0]-w[0],s[2]-w[1]],L=[i[0]-w[0],i[2]-w[1]];return Math.abs(C[0]*L[1]-C[1]*L[0])/(Math.hypot(...C)*Math.hypot(...L))})(R):0;if(!(Math.abs(m[0]*g[0]+m[1]*g[1])>1e-9))return{ic:R,line:null,cp:p,wc:h,road:y,swingArmAngleDeg:0,tanTheta:0,tanThetaHub:0,valid:!1,sinAngle:A};let F=[m[1]/v,-m[0]/v],T=R?[R[0]-p[0],R[1]-p[1]]:[n.isFront?-1:1,0],P=F[0]*T[0]+F[1]*T[1]<0?[-F[0],-F[1]]:F,S=x(m);return{ic:R,line:P,cp:p,wc:h,road:y,swingArmAngleDeg:Math.atan(S)*zV,tanTheta:S,tanThetaHub:x(d),valid:!0,sinAngle:A}}function eF(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 WV=180/Math.PI,jV=Math.PI/180,oy=.5,Bp=2,ay=.25,UV={heave:0,pitch:0,roll:0,steer:0},XV={FL:"FR",FR:"FL",RL:"RR",RR:"RL"},$p=e=>e.ok?e.state:{...e.nearest,converged:!1};function sy(e,t,r){return t.state?t.solved===!1?{...t.state,converged:!1}:t.state:$p(we(e,t.travel,t.steer,void 0,r))}var tF=new WeakMap;function rF(e,t){let r=e.ctx[t],n=Qe(e.vehicle,t).config.loadedRadius,o=sr(n,e.kc,t),a=tF.get(r);a||(a=new Map,tF.set(r,a));let s=a.get(o);if(!s){let i=In(t,e.vehicle.config,UV,e.vehicle);s=$p(we(r,i.travel,i.steer,void 0,o===n?void 0:{loadedRadius:o})),a.set(o,s)}return s}var Hr=(e,t)=>!e||!e.lo.converged||!e.hi.converged?NaN:(t(e.hi)-t(e.lo))/(2*e.step),nF=(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 aF(e,t,r,n,o){let a=e.vehicle.config,s=Ra(r),i=Qe(e.vehicle,r),c=nt(r,a),l=e.ctx[r],u=Vt(e,t),m=u[r],d={travel:m.travel,steer:m.steer},p=m.rigid?void 0:{loadedRadius:m.loadedRadius},h=sy(l,m,p),f=rF(e,r),b={lo:$p(we(l,d.travel-oy,d.steer,void 0,p)),hi:$p(we(l,d.travel+oy,d.steer,void 0,p)),step:oy},g=c.isFront?{lo:qe(l,h.beta,d.steer-Bp,void 0,p),hi:qe(l,h.beta,d.steer+Bp,void 0,p),step:Bp}:null,y=N=>{let Y=Vt(e,{...t,roll:t.roll+N*jV})[r];return sy(l,Y,Y.rigid?void 0:{loadedRadius:Y.loadedRadius})},x={lo:y(-ay),hi:y(ay),step:ay},k=QV(e,t,r,c.isFront,u,g),v=Wt(h.points.contactPatch,c),R=Wt(f.points.contactPatch,c),M=Math.abs(v[1])-Math.abs(R[1]),A=XV[r],F=u[A],T=sy(e.ctx[A],F,F.rigid?void 0:{loadedRadius:F.loadedRadius}),P=T.converged?M+Math.abs(T.points.contactPatch[1])-Math.abs(rF(e,A).points.contactPatch[1]):NaN,S=o??Ir(e,t,s),w=sm(S,Ot(i)),C=w?null:gM(S),L=c.sideSign>0?S.icRight:S.icLeft,E=L?Math.hypot(L[0]-v[1],L[1]-v[2]):1/0,_=Vp(e,r,t),O=_.ic?Math.hypot(_.ic[0]-_.cp[0],_.ic[1]-_.cp[1]):1/0,I=eF(_,s,a.wheelbase,n),z=-Hr(b,N=>N.points.damperLength),B=i.config.springRate,V=Hr(x,N=>N.metrics.camber),j=qc(e,{FL:u.FL.ground,FR:u.FR.ground,RL:u.RL.ground,RR:u.RR.ground}),q=e.kc?.loadCase,K=N=>q?Np(N,r,a,j,{loadedRadius:m.loadedRadius,patchShift:q.patchShift[r]}):N.metrics,D=K(h);return{id:r,converged:h.converged,travel:h.travel,camber:h.metrics.camber,camberRoad:ry(h.points.spinAxis,r,a,j),toe:h.metrics.toe,caster:D.caster,kpi:D.kpi,scrubRadius:D.scrubRadius,mechanicalTrail:D.mechanicalTrail,scrubAtWheel:D.scrubAtWheel,trailAtWheel:D.trailAtWheel,kingpinOffset:D.kingpinOffset,casterOffset:D.casterOffset,steeringArm:h.metrics.steeringArm,camberGain:Hr(b,N=>N.metrics.camber),bumpSteer:Hr(b,N=>N.metrics.toe),trackScrubRate:Hr(b,N=>Math.abs(Wt(N.points.contactPatch,c)[1])),casterGain:Hr(b,N=>K(N).caster),kpiGain:Hr(b,N=>K(N).kpi),scrubGain:Hr(b,N=>K(N).scrubRadius),trailGain:Hr(b,N=>K(N).mechanicalTrail),...c.isFront?{camberPerSteer:nF(g,N=>N.metrics.camber,N=>N.metrics.toe),steerJacking:-nF(g,N=>N.points.contactPatch[2],N=>N.metrics.toe),...k!==void 0?{steerLoad:k}:{}}:{},rollCamber:V,camberRecovery:-100*c.sideSign*V,rollSteer:c.sideSign*Hr(x,N=>N.metrics.toe),halfTrackChange:M,trackChange:P,longitudinal:v[0]-R[0],rollCentreHeight:C?C.heightAboveGround:S.heightAboveGround,rollCentreHeightChassis:(C?C.height:S.height)-Qn(0,c.axleX,e),rollCentreLateral:S.lateralAlongGround,rollCentreValid:S.valid,rollCentreUsable:w,rollCentreHeightUsable:w||C!==null,rollCentreSinAngle:S.sinAngle,fvsaLength:E,svsaLength:O,swingArmAngle:_.swingArmAngleDeg,svsaUsable:ny(_,a.wheelbase),svsaSinAngle:_.sinAngle,...s==="front"?{antiDive:I.brake,antiLift:I.drive}:{antiSquat:I.drive,antiLift:I.brake},decoupled:i.config.actuation==="decoupled",mcpherson:i.config.layout==="mcpherson",springRate:B,motionRatio:z,wheelRate:B*z*z,damperLength:h.points.damperLength,damperTravel:f.points.damperLength-h.points.damperLength,...qV(i,f.points.damperLength,h.points.damperLength,e.kc?.curve[r].spring?.law),rockerAngle:i.config.actuation==="direct"?0:(h.points.rockerAngle-f.points.rockerAngle)*WV,groundDisplacement:m.rigid?h.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 qV(e,t,r,n){if(e.config.actuation==="decoupled")return{};let o=n?{droop:n.droopStated?n.droop:null,bump:n.bump}:ka(t,e.config.coilover),a=t-r;return{...o.droop!==null?{damperToExtended:a-o.droop}:{},...o.bump!==null?{damperToClosed:o.bump-a}:{}}}function QV(e,t,r,n,o,a){if(!a||!n)return;let s=jl(e,t,"front"),i=e.kc;if(!s||!i)return;let c=["FL","FR"],l=[0,0],u=[0,0],m={lo:[],hi:[]},d=0;for(let f=0;f<2;f++){let b=c[f],g=o[b],y=e.ctx[b],x=g.rigid?void 0:{loadedRadius:g.loadedRadius},R=(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=Lt(we(y,g.travel,g.steer-R,M,x)),F=Lt(we(y,g.travel,g.steer+R,M,x));if(!A||!F)return NaN;l[f]=F.points.contactPatch[2]-A.points.contactPatch[2],u[f]=Qr(i.curve[b],g.travel,F.points.damperLength)-Qr(i.curve[b],g.travel,A.points.damperLength),m.lo.push(A),m.hi.push(F),b===r&&(d=F.metrics.toe-A.metrics.toe)}let p=i.elements?.front;if(p){let f=[o.FL.travel,o.FR.travel],b=Js(p,f,[m.hi[0],m.hi[1]]),g=Js(p,f,[m.lo[0],m.lo[1]]);u[0]+=b[0]-g[0],u[1]+=b[1]-g[1]}return Math.abs(d)>1e-9?s([0,0],l,u)[r==="FL"?0:1]/d:NaN}function Qc(e,t,r,n,o){return aF(e,t,r==="front"?"FL":"RL",n,o)}function iy(e,t,r,n){let o=Qc(e,t,"front",r,n?.front),a=Qc(e,t,"rear",r,n?.rear);return{front:o,rear:a,wheelbaseChange:o.longitudinal-a.longitudinal}}function Gp(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),Qn(Math.min(n.zMin,n.zMax),i,t)],max:[s,Math.max(n.yMin,n.yMax),Qn(Math.max(n.zMin,n.zMax),i,t)]}})}var Zo=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],lr=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],xt=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],yr=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Zc=e=>Math.sqrt(yr(e,e));function ZV(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 JV(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=>yr(r,e)>=yr(r,t)?e:t,samples:()=>Array.from({length:41},(r,n)=>lr(e,xt(Zo(t,e),n/40)))}}function e5(e,t,r,n){let o=xt(t,1/(Zc(t)||1)),a=n/2,s=o.map(i=>r*Math.sqrt(Math.max(0,1-i*i))+a*Math.abs(i));return{min:Zo(e,s),max:lr(e,s),support:i=>{let c=yr(i,o),l=Zo(i,xt(o,c)),u=Zc(l),m=u>1e-12?xt(l,r/u):[0,0,0];return lr(lr(e,xt(o,c>=0?a:-a)),m)},samples:()=>{let i=Math.abs(o[0])<.9?[1,0,0]:[0,1,0],c=Zo(i,xt(o,yr(i,o))),l=xt(c,1/Zc(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 d of[-1,-.5,0,.5,1]){let p=lr(e,xt(o,d*a));m.push(p);let h=Math.abs(d)===1?[.5,1]:[1];for(let f of h)for(let b=0;b<72;b++){let g=b/72*2*Math.PI;m.push(lr(p,lr(xt(l,f*r*Math.cos(g)),xt(u,f*r*Math.sin(g)))))}}return m}}}function t5(e){let t=e[0],r=e.slice(1).map(c=>Zo(c,t)),n=r.length;if(n===0)return{v:t,w:[1]};let o=r.map(c=>r.map(l=>yr(c,l))),a=r.map(c=>-yr(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 d=c;d<n;d++)o[u][d]-=m*o[c][d];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=lr(i,xt(r[c],s[c]));return{v:i,w:[1-s.reduce((c,l)=>c+l,0),...s]}}function r5(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=t5(a.map(c=>c.w));if(!s||s.w.some(c=>c<-1e-9))continue;let i=yr(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 n5(e,t){let r=s=>{let i=e.support(s),c=t.support(xt(s,-1));return{w:Zo(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=lr(c,xt(u.a,s.weights[m])),l=lr(l,xt(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=yr(i,i);if(c<1e-12)return n(a,0);let l=r(xt(i,-1));if(c-yr(i,l.w)<=1e-9*Math.max(1,c))return n(a,Math.sqrt(c));let u=r5([...a.keep,l]);if(u.keep.length===4)return n(u,0);if(yr(u.v,u.v)>=c-1e-12)return n(a,Math.sqrt(c));a=u}return n(a,Zc(a.v))}function o5(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 a5(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 cF={linkRadius:8,mountAllowance:15},s5=(e,t,r)=>e.z0+e.dzdx*t+e.dzdy*r;function i5(e,t){let r=Math.sin(e.pitch);return{z0:-e.heave+t*r,dzdx:-r,dzdy:Math.sin(e.roll)}}function lF(e){return i5(Op({heave:0,pitch:0,roll:0,steer:0},e),En(e.vehicle.config))}var c5=[{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 l5(e){return c5.filter(t=>t.name==="strut"?e.mcpherson:t.name==="pushrod"?!e.direct:!(e.mcpherson&&t.name.startsWith("upper")))}var u5=(e,t,r)=>e.every((n,o)=>n>=t.min[o]-r&&n<=t.max[o]+r);function sF(e,t,r){let n=Zo(t,e),o=Zc(n);return o>1e-9?lr(e,xt(n,r/o)):e}function iF(e,t){let r=null;for(let{shape:n,pad:o,part:a,pose:s}of t){if(r&&a5(e,n)-o>=r.distance)continue;let i=n5(e,n),c=i.distance>0?null:o5(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 m5(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:xt(a.reduce((c,l)=>lr(c,l),[0,0,0]),1/a.length)}}function uF(e,t){return{...m5(e,r=>r[2]-s5(t,r[0],r[1])),road:t}}function mF(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 p5(e,t){let r=e.map(o=>({pose:o,part:`${o.corner} tyre`,pad:0,shape:e5(o.g.wheelCenter,o.g.spinAxis,o.corner[0]==="F"?t.tyreRadius.front:t.tyreRadius.rear,t.tyreWidth)})),n=e.flatMap(o=>l5(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:JV(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 d5(e,t,r){let n=ZV(e.min,e.max),o=t.links.filter(a=>!u5(a.inboard,e,r.mountAllowance+r.linkRadius));return{tyre:iF(n,t.tyres),link:iF(n,o)}}function pF(e,t,r){let n=p5(t,r);return e.map(o=>({boxId:o.id,...d5(o,n,r)}))}var yF=152,xF={travelSteps:9,rackSteps:5},Jo=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Sn=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Jc=(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]],xr=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]},RF=180/Math.PI,f5=[[1,0,0],[0,1,0],[0,0,1]],dF=(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]],h5=(e,t)=>[Sn(e[0],t),Sn(e[1],t),Sn(e[2],t)];function fF(e,t,r){let n=xr(Jo(t,e)),o=xr(Jc(n,Jo(r,e)));return[n,Jc(o,n),o]}function b5(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 cy(e,t,r,n){let o=xr(Jo(t,e)),a=b=>{let g=Jo(b,e),y=Sn(g,o);return[g[0]-y*o[0],g[1]-y*o[1],g[2]-y*o[2]]},s=xr(a(r)),i=xr(a(n)),c=Sn(Jc(s,i),o),u=Sn(s,i),m=c,d=1-u,[p,h,f]=o;return[[d*p*p+u,d*p*h+m*f,d*p*f-m*h],[d*p*h-m*f,d*h*h+u,d*h*f+m*p],[d*p*f+m*h,d*h*f-m*p,d*f*f+u]]}var g5=(e,t)=>Math.acos(Math.max(-1,Math.min(1,Sn(xr(e),xr(t)))))*RF;function y5(e,t){return{upright:b5(fF(e.uprightLower,e.tieOuter,e.wheelCenter),fF(t.uprightLower,t.tieOuter,t.wheelCenter)),uca:t.mcpherson?null:cy(t.ucaFront,t.ucaRear,e.uprightUpper,t.uprightUpper),lca:cy(t.lcaFront,t.lcaRear,e.uprightLower,t.uprightLower),rocker:t.direct?null:cy(t.rockerPivotA,t.rockerPivotB,e.rockerToPushrod,t.rockerToPushrod)}}function vF(e){let t=xr(e[0]),r=Math.abs(t[0])<.9?[1,0,0]:[0,1,0],n=xr(Jc(t,r)),o=Jc(t,n),a=e.map(h=>{let f=xr(h);return[Sn(f,n),Sn(f,o)]}),s=h=>{let f=Math.cos(h),b=Math.sin(h),g=0;for(let[y,x]of a)g=Math.max(g,Math.abs(y*f+x*b));return g},i=Math.PI/180,c=0,l=1/0;for(let h=0;h<180;h++){let f=s(h*i);f<l&&([c,l]=[h*i,f])}let u=c-i,m=c+i,d=(Math.sqrt(5)-1)/2;for(let h=0;h<30;h++){let f=m-d*(m-u),b=u+d*(m-u);s(f)<s(b)?m=b:u=f}let p=Math.min(l,s((u+m)/2));return Math.asin(Math.min(1,p))*RF}function hF(e){let t=null;for(let r of e)Number.isFinite(r.angle)&&(!t||r.angle>t.angle)&&(t=r);return t}var x5={upright:"upright",lowerArm:"lca",upperArm:"uca"};function kF(e,t,r,n){let o=t.map(m=>y5(e,m)),a=xr(Jo(e.uprightUpper,e.uprightLower)),s=m=>Math.max(0,...o.map(d=>d[m]?g5(dF(d.upright,a),dF(d[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,d,p)=>{let h=[Jo(e[d],e[m])];for(let f=0;f<t.length;f++){let b=p(o[f]);if(!b)return null;h.push(h5(b,Jo(t[f][d],t[f][m])))}return h},l=[["tie rod, inner end",c("tieInner","tieOuter",()=>f5)],["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[x5[r]])]);let u=l.filter(m=>m[1]!==null).map(([m,d])=>({joint:m,angle:vF(d)}));return{ballJoint:hF(i),rodEnd:hF(u)}}function R5(e){let t=(r,n)=>{let o=sr(n,e.kc,r),a=e.kc?.input.corners[r];return a&&a.tyreRate>0&&Number.isFinite(a.tyreRate)?o+Math.max(0,a.staticLoad)/a.tyreRate:o};return{front:t("FL",e.vehicle.front.config.loadedRadius),rear:t("RL",e.vehicle.rear.config.loadedRadius)}}function MF(e,t){let r=xu(t);return{...cF,tyreRadius:R5(e),tyreWidth:r!==null?r*1e3:yF}}var bF={front:["FL","FR"],rear:["RL","RR"]},gF=(e,t,r)=>r<=1||t===e?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function ly(e,t,r,n,o=xF){let a=e.vehicle,[s]=bF[t],i=nm(e,s,0,0)?.geometry;if(!i)return null;let c=Gp(a.chassis?.boxes??[],{vehicle:a,kc:e.kc}),l=t==="front"?Bt(a.front.config):0,u=l>0?gF(-l,l,Math.max(3,o.rackSteps|1)):[0],m=gF(Math.min(0,r.min),Math.max(0,r.max),Math.max(2,o.travelSteps)),d=[];for(let b of c.length?bF[t]:[s])for(let g of m)for(let y of u){let x=nm(e,b,g,y)?.geometry;x&&d.push({corner:b,travel:g,rack:y,g:x})}let p=null;if(c.length){for(let b of pF(c,d,MF(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 h=a[t].config,f=kF(i,d.filter(b=>b.corner===s).map(b=>b.g),h.pushrodAttach,h.rodType==="pull"?"pullrod":"pushrod");return{chassis:p,...f}}var Kp=Math.PI/180,el={travelSteps:9,heaveSteps:5,rollSteps:4,rackSteps:6},Hp={travelMin:-25,travelMax:25,rollMaxDeg:3,rollAtLimitDeg:2.5};function v5(e){let t=e.params;return{cgHeight:t.cg_height?It({...t,surveyedRadiusFront:e.vehicle.front.config.loadedRadius,surveyedRadiusRear:e.vehicle.rear.config.loadedRadius}).cgHeight:300,...sb(t),drive:nb(t)}}function SF(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 uy(e,t=el,r=Hp,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=Jt(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=Jt(s)},m=C=>C==="front"?"FL":"RL",d=C=>{let L=u();if(!L.kc)return;let E=i(C).config.loadedRadius,_=sr(E,L.kc,m(C));return _===E?void 0:{loadedRadius:_}},p=(C,L)=>-ei(u(),m(C),L),h=new Map,f=new Map,b=new Map,g=new Map,y=new Map,x=new Map,k=new Map,v=new Map,R=new Map,M=null,A=()=>{if(M)return M;u();let C=v5(e);return M=l!==null&&Number.isFinite(l)?{...C,cgHeight:l}:C},F,T,P=()=>{if(T!==void 0)return T;let C=Jl(u().ctx.FL,Bt(s.front.config));return T=C?eu(C):null,T},S=(C,L,E)=>{if(C.has(L))return C.get(L)??null;let _=E();return C.set(L,_),_};return{car:e,density:t,envelope:r,get failure(){return o},axisLength:(C,L)=>{let E=i(C),_=E.hardpoints;return L==="uca"&&E.config.layout==="mcpherson"?NaN:L==="uca"?Ee(_.ucaFront,_.ucaRear):Ee(_.lcaFront,_.lcaRear)},linkLength:C=>{let L=i(C).hardpoints;return Ee(L.tieInner,L.tieOuter)},compliance:C=>S(f,C,()=>ch(i(C))??null),sweep:C=>S(h,C,()=>{let L;try{L=ot(i(C),{travelMin:r.travelMin,travelMax:r.travelMax,steps:t.travelSteps})}catch{return a(500,`the ${C} travel sweep threw`)}if(!L.covered){let _=L.samples.map(z=>z.travel),O=Math.max(..._)-Math.min(..._),I=r.travelMax-r.travelMin;return a(Math.max(0,I-O),`the ${C} linkage reaches only ${O.toFixed(0)} mm of the ${I.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(_=>!_.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 _=P();if(_)return a(_.violation,_.reason)}return L}),rcHeave:C=>S(b,C,()=>{let L=[],E=[],_=Math.max(2,t.heaveSteps);try{for(let I=0;I<_;I++){let z=r.travelMin+(r.travelMax-r.travelMin)*I/(_-1);L.push(z),E.push(Ir(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=SF(E,I=>Math.abs(L[I]-L[I-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=[],_=Math.max(2,t.rollSteps);try{for(let I=0;I<_;I++){let z=r.rollMaxDeg*I/(_-1);L.push(z),E.push(Ir(u(),{heave:0,pitch:0,roll:z*Kp,steer:0},C))}}catch{return a(500,`the ${C} roll-centre construction threw in roll`)}let O=SF(E,I=>Math.abs(E[I].cpLeft?.[0]??0)*Math.abs(L[I]-L[I-1])*Kp);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=Qn(0,nt(m(C),s.config).axleX,u()),y.set(C,L)),L},steer:()=>{if(F!==void 0)return F;try{F=Kf(u(),{steerMax:Bt(s.front.config),steps:t.rackSteps})}catch{F=a(500,"the steering sweep threw")}let C=F?.filter(L=>!L.converged).length??0;if(F&&C>0){let L=P();F=L?a(L.violation,L.reason):a(100+10*C,`${C} of ${F.length} steering solves did not converge`)}return F??null},solveAt:(C,L,E=0)=>S(x,`${C}:${L}:${E}`,()=>{try{let _=we(u().ctx[m(C)],L,E,void 0,d(C));return _.ok?_.state:_.why==="unconverged"?a(100,`the ${C} corner did not solve at ${L.toFixed(0)} mm of travel`):a(100+Math.abs(_.travelMiss),`the ${C} corner reaches only ${(L+_.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 iy(u(),C,A())}catch{return a(500,"the derived readout threw")}}),readoutAtTravel:(C,L)=>S(R,`${C}:${L}`,()=>{try{return Qc(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*Kp),_=u();if(!_.kc)return E;try{let O=Vt(_,{heave:0,pitch:0,roll:L*Kp,steer:0}),I=C==="front"?Math.max(O.FL.travel,O.FR.travel):Math.max(O.RL.travel,O.RR.travel);return Number.isFinite(I)?I: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,_={min:r.travelMin,max:r.travelMax};return ly(u(),C,_,E)??a(100,`the ${C} corner did not solve at its design ride`)}catch{return a(500,`the ${C} keep-outs threw`)}})}}var k5=Jg();function my(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=tp(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?Lc([c],a.track,a.numerics,wc(s),a.settings,k5)[0]:gc(c,s,{numerics:a.numerics,standingStart:l,lapCounts:u});o={};for(let d of s.metrics)vl(d)&&(o[d.key]=d.value(m,void 0))}}catch{o=null}return r.set(n,o),o}}}var zp=.01;function M5(e,t){return t.bump!==null&&e>t.bump-zp?{at:"closed",past:Math.max(0,e-t.bump)}:t.droopStated&&e<t.droop+zp?{at:"toppedOut",past:Math.max(0,t.droop-e)}:t.seat!==null&&e<t.seat+zp?{at:"unseated",past:Math.max(0,t.seat-e)}:{at:"free",past:0}}var AF=e=>({droop:e.droop,droopStated:e.droopStated,bump:e.bump,seat:e.holdsLoad&&Number.isFinite(e.free)?e.free:null}),S5=[["front","FL","FR"],["rear","RL","RR"]];function dy(e,t){let r=[];for(let[n,o,a]of S5){let s=[t[o],t[a]];for(let m of[o,a]){let d=e.curve[m],p=d.spring?.law;if(!d.spring||!p)continue;let h=kf(d,t[m]);h===null||!Number.isFinite(h)||r.push(py(m,n,n,h,d.spring.length0-h,AF(p),!0))}let i=e.elements?.[n];if(!i)continue;let c=i.heave?.law;if(c){let m=rv(i,s),d=i.read.heave?.span0,p=n==="front"?"heaveFront":"heaveRear";r.push(py(p,p,n,m,d!==void 0?d-m:null,AF(c),i.carriesLoad))}let l=i.rollStop,u=l?nv(i,s):null;if(l&&u!==null){let m=l.length0-u,d=n==="front"?"rollFront":"rollRear",p={droop:l.droop??-1/0,droopStated:l.droop!==null,bump:l.bump,seat:null};r.push(py(d,d,n,m,u,p,i.carriesLoad))}}return r}function py(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,...M5(n,a),bumpStated:a.bump!==null,bounds:s}}var CF=Math.PI/180;function fy(e,t,r,n){let o=t.speedKmh/3.6,a=nf(e,o,t.axG,Pn(e,t.ayG,0));if(!a||!e.aero)return null;let s=e.wheelbase,i=ya(e.aero,s),c=(f,b)=>Math.atan((b-f)/s)/CF,l={},u={};for(let f of wr)l[f]=r.corners[f].travel,u[f]=r.corners[f].ground;let m=n.kc?dy(n.kc,l):[],d=e.aero.model,p=a.downFront+a.downRear,h=d?{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:TF(d,s,a.hFront,a.hRear)}:null;return{front:{height:a.hFront,...wF(m,"front")},rear:{height:a.hRear,...wF(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:h,clearance:A5(n,u)}}function wF(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 TF(e,t,r,n){let o=(a,[s,i])=>Math.min(a-s,i-a);if(Xx(e)){let{x:a,y:s}=fa(e),i=[a[0],a[a.length-1]],c=[s[0],s[s.length-1]];return Cn(e)?FF(e.frame,t,i,c,r,n):Math.min(o(r,i),o(n,c))}return Fl(e)?FF(e.frame,t,e.range.h,e.range.pitch,r,n):Math.min(o(r,e.range.hFront),o(n,e.range.hRear))}function FF(e,t,r,n,o,a){let s=ha(e,t,o,a),i=l=>t*Math.tan(l*CF),c=a-o;return Math.min(s.h-r[0],r[1]-s.h,c-i(n[0]),i(n[1])-c)}function A5(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=ar(e.vehicle,!0)/2,c=ar(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 wr){let g=[1,l[b][0],l[b][1]];for(let y=0;y<3;y++){m[y]+=g[y]*t[b];for(let x=0;x<3;x++)u[y][x]+=g[y]*g[x]}}let d=mF(u,m);if(!d)return null;let p=lF(n),h={z0:p.z0+d[0],dzdx:p.dzdx+d[1],dzdy:p.dzdy+d[2]},f=null;for(let b of Gp(r,n)){let g=uF(b,h);(!f||g.height<f.height)&&(f={height:g.height,volume:b.name})}return f}function Yp(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 w5={front:"front",rear:"rear",heaveFront:"front",heaveRear:"rear",rollFront:"front",rollRear:"rear"};function tl(e,t,r,n){let o=pm(e,t);return tm.some(s=>{if(w5[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 hy(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 Wp=Math.PI/180,jp=1e-6;function LF(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 rl(e){let t=e.measured;if(t)return LF(t.travel,t.camber);let r=te(e.config.spinAxis);return-Math.asin(Math.max(-1,Math.min(1,r[2])))/Wp}function nl(e){let t=e.measured;if(t)return LF(t.travel,t.toe);let[r,n]=e.config.spinAxis;return Math.atan2(r,n)/Wp}function by(e,t){let r=Math.abs(t.camber)>=jp,n=Math.abs(t.toe)>=jp;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=(rl(e)+t.camber)*Wp,l=(nl(e)+t.toe)*Wp,[u,m]=n?[Math.sin(l),Math.cos(l)]:[a/i,s/i],d=[u*Math.cos(c),m*Math.cos(c),-Math.sin(c)];return{...e,config:{...e.config,spinAxis:d}}}function Up(e){let t=e&&typeof e=="object"?e.value:void 0;return typeof t=="number"&&Number.isFinite(t)?t:void 0}function F5(e,t){let r=t;return{front:Up(r.camber_front_deg)??rl(e.front),rear:Up(r.camber_rear_deg)??rl(e.rear)}}function C5(e,t){let r=t;return{front:Up(r.toe_front_deg)??nl(e.front),rear:Up(r.toe_rear_deg)??nl(e.rear)}}function T5(e){return{camber:{front:rl(e.front),rear:rl(e.rear)},toe:{front:nl(e.front),rear:nl(e.rear)}}}var PF=new WeakMap;function P5(e,t){let r=T5(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)<jp&&Math.abs(u.toe)<jp;if(o(n.front)&&o(n.rear))return e;let a=`${t.camber.front}|${t.camber.rear}|${t.toe.front}|${t.toe.rear}`,s=PF.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&&by(m,n[Ra(u)])])):void 0,l={...e,front:by(e.front,n.front),rear:by(e.rear,n.rear),...c?{corners:c}:{}};return s||PF.set(e,s=new Map),s.size>=16&&s.clear(),s.set(a,l),l}function vs(e,t){return t?P5(e,{camber:F5(e,t),toe:C5(e,t)}):e}var L5=9.81;function ks(e){let t=mo(e),r=Math.max(0,e.unsprungPerCorner)*L5,n=a=>{let s=a==="FL"||a==="FR",i=s?"front":"rear",c=lt(e,i),l=c>0?c:1/0,u=Od(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:cr(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 DF=new WeakMap;function D5(e){let t=vs(e.vehicle,e.params);if(t===e.vehicle)return e;let r=DF.get(e);return(!r||r.vehicle!==t)&&DF.set(e,r={...e,vehicle:t}),r}function Zn(e,t={}){let r=D5(e),n=U0(r,t),o=t.assemble?()=>{let m=n.dynInput();if(!m)throw new Error("the car did not assemble");return{kc:ks(m),cgHeight:m.cgHeight}}:void 0,a=uy(r,t.density,t.envelope,o),s=ey(r,n,t),i=my(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(d=>d.id===m)??null,platformAt:m=>{let d=`${m.speedKmh}|${m.ayG}|${m.axG}`,p=l.get(d);if(p!==void 0)return p;let h=n.poseAt(m),f=n.dynInput(),b=null;if(h&&f)try{b=fy(f,m,h,a.contexts())}catch{b=null}return l.set(d,b),b}}}var E5=["x","y","z"],I5=/^(line|plane)\((-?\d+),(-?\d+)\)([uv]?)$/,EF=Math.PI/18e3,IF=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],_F=(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]],_5=e=>Math.hypot(e[0],e[1],e[2]),gy=(e,t)=>[e[0]*t,e[1]*t,e[2]*t];function yy(e){let t=_5(e);return t>1e-9?gy(e,1/t):null}function N5(e,t){let r=e*EF,n=t*EF;return[Math.cos(n)*Math.cos(r),Math.cos(n)*Math.sin(r),Math.sin(n)]}function ur(e){let t=e.lastIndexOf(".");if(t<0)return null;let r=I5.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:N5(Number(r[2]),Number(r[3]))},coord:n==="line"?"along":r[4]}}function NF(e){let t=yy(_F([0,0,1],e))??[1,0,0];(t[0]<-1e-9||Math.abs(t[0])<=1e-9&&t[1]<0)&&(t=gy(t,-1));let r=yy(_F(e,t))??[0,1,0];return(r[2]<-1e-9||Math.abs(r[2])<=1e-9&&r[1]<0)&&(r=gy(r,-1)),[t,r]}function xy(e){if(e.coord==="along")return e.shape.dir;let[t,r]=NF(e.shape.dir);return e.coord==="u"?t:r}function OF(e,t){let r=ur(t);if(!r)return;let n=E5.map(u=>e[`${r.point}.${u}`]);if(n.some(u=>!u))return;let o=xy(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=>IF(s(u),o),write:(u,m)=>{let d=s(u),p=m-IF(d,o),h=u;for(let f of a)h=n[f].write(h,d[f]+p*o[f]);return h},...c?{supersededBy:c}:{}}}var Ms=["x","y","z"];var O5=/^(?:hp\.(?:front|rear)\.\w+|(?:heave|roll)\.(?:front|rear)\.(?:outer|inner|anchor))$/;function ea(e){let t=e.lastIndexOf("."),r=e.slice(0,t);if(t<0||!O5.test(r))return null;let n=e.slice(t+1);if(n==="x"||n==="y"||n==="z")return{point:r,axis:n};let o=ur(e);return o?{point:r,axis:o.coord}:null}var ol="*";function Ry(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 vy=e=>e?.reads==="speed"||e?.reads==="operating",ky=e=>e?.reads==="lateral"||e?.reads==="operating";function ta(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 Xp(e,t){return e?.appliesAt?t.find(r=>!e.appliesAt(r)):t[0]}function Ss(e,t,r){let n=r?.stateId?e.stateOf(r.stateId):Xp(t,e.states)??null;return n&&!t.appliesAt?.(n)?n:null}function Ft(e,t,r){let n=`${t.id}@${ta(r)}`,o=e.values.get(n);if(o!==void 0)return o;let a;try{a=r?.courseId===ol&&t.reads==="course"?V5(e,t,r):r?.stateId===Kr&&t.reads==="state"?B5(e,t,r):t.read(e,r)}catch{a=NaN}return e.values.set(n,a),a}function V5(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:Ft(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 B5(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:Ft(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 My(e){let t={mean:"weighted mean",max:"highest",min:"lowest",span:"span"};return e?.acrossStates?`every state, ${t[e.acrossStates]}`:"every state"}function it(e){return`${e.quantity??e.groupShort??e.group} \xB7 ${e.label}`}var $5={front:"Front",rear:"Rear"},al={heave:0,pitch:0,roll:0,steer:0},VF="RC height (chassis) [mm]";function BF(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 G5(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 sl=e=>e.length?Math.max(...e)-Math.min(...e):NaN;function $F(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 GF(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 il=(e,t)=>`${e==="front"?"F":"R"}${t}`,KF=e=>e==="L"?"R":"L";function HF(e){let t=$5[e],r=R=>`kin.${e}.${R}`,n=(R,M)=>{let A=R.sweep(e);return A?{x:A.samples.map(F=>F.travel),y:A.samples.map(M)}:{x:[],y:[]}},o=R=>e==="front"?R.vehicle.front:R.vehicle.rear,a=R=>R.params[e==="front"?"heaveFrontDesign":"heaveRearDesign"],s=R=>R.params[e==="front"?"arbFrontDesign":"arbRearDesign"],i=e==="front"?"the front axle":"the rear axle";function c(R){return o(R).config.actuation==="decoupled"?`${i} is decoupled, with no corner damper \u2014 read its heave and roll elements`:null}function l(R){let M=a(R);return M&&M.design.kind!=="none"?null:`${i} has no heave element`}function u(R){let M=a(R);return M?.design.kind==="coil"&&M.linkage?null:`${i} has no heave element on a linkage`}function m(R){let M=s(R);return M&&M.design.kind!=="none"?null:`${i} has no roll element`}function d(R){let M=s(R);return M?.linkage&&M.design.kind!=="none"&&M.design.kind!=="direct"?null:`${i} has no roll element on a linkage`}let p=R=>{if(u(R.car))return null;let M=R.sweep(e);return M?Ff(o(R.car),a(R.car).linkage,M.samples):null},h=R=>{if(d(R.car))return null;let M=R.sweep(e);if(!M)return null;let A=s(R.car),F=Sf(o(R.car),A.linkage,A.design.kind,M.samples),T=F.atDesign<0?-1:1;return{travel:F.travel,ratio:F.ratio.map(P=>P*T),atDesign:F.atDesign*T}},f=R=>R.readout(al)?.[e],b=R=>R.readoutAtTravel(e,R.envelope.travelMax),g=R=>{let M=n(R,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=R=>{let M=n(R,A=>A.metrics.toe);return M.x.length?{key:r("bumpSteer"),title:`${t} toe vs travel`,xLabel:"travel [mm]",yLabel:"toe [\xB0]",...M}:null},x=[{id:r("rcStatic"),group:`${t} roll centre`,label:"static height",unit:"mm",scale:30,scope:e,cost:"cheap",read:R=>R.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:R=>{let M=R.rcHeave(e);return M?G5(M.at,M.rc.map(A=>A.height)):NaN},curve:R=>{let M=R.rcHeave(e);return M?{key:r("rcHeaveWorst"),title:`${t} roll-centre height vs wheel travel`,xLabel:"travel [mm]",yLabel:VF,x:M.at,y:M.rc.map(A=>A.height-R.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:R=>{let M=R.rcRoll(e);return M?sl(M.rc.map(A=>A.height)):NaN},curve:R=>{let M=R.rcRoll(e);return M?{key:r("rcRollSpan"),title:`${t} roll-centre height vs body roll`,xLabel:"roll [\xB0]",yLabel:VF,x:M.at,y:M.rc.map(A=>A.height-R.roadUnder(e))}:null}},{id:r("rcLateralSpan"),group:`${t} roll centre`,label:"lateral migration over roll",unit:"mm",scale:50,scope:e,cost:"cheap",read:R=>{let M=R.rcRoll(e);return M?sl(M.rc.map(A=>A.lateral)):NaN},curve:R=>{let M=R.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:R=>{let M=R.rcHeave(e),A=R.rcRoll(e);return!M||!A?NaN:Math.min(...M.rc.map(F=>F.sinAngle),...A.rc.map(F=>F.sinAngle))},curve:R=>{let M=R.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:R=>f(R)?.fvsaLength??NaN},{id:r("complianceSteer"),group:`${t} compliance`,label:"compliance steer",unit:"\xB0/kN lateral",scale:.05,scope:e,cost:"readout",read:R=>(R.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:R=>(R.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:R=>(R.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:R=>(R.compliance(e)?.toePerMz??0)*1e5},{id:r("staticCamber"),group:`${t} camber & toe`,label:"static camber",unit:"\xB0",scale:1,scope:e,cost:"cheap",read:R=>{let M=R.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:R=>R.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:R=>f(R)?.camberGain??NaN,curve:R=>g(R)},{id:r("rollCamber"),group:`${t} camber & toe`,label:"camber gain in roll",unit:"\xB0/\xB0",scale:.2,scope:e,cost:"readout",read:R=>f(R)?.rollCamber??NaN},{id:r("rollCamberRecovery"),group:`${t} camber & toe`,label:"camber recovery in roll",unit:"%",scale:20,scope:e,cost:"readout",read:R=>f(R)?.camberRecovery??NaN},{id:r("bumpSteerDesign"),group:`${t} camber & toe`,label:"bump steer at design",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:R=>f(R)?.bumpSteer??NaN,curve:R=>y(R)},{id:r("rollSteer"),group:`${t} camber & toe`,label:"roll steer",unit:"\xB0/\xB0",scale:.1,scope:e,cost:"readout",read:R=>f(R)?.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:R=>{let M=n(R,A=>A.metrics.toe);return M.x.length?BF(M.x,M.y):NaN},curve:R=>y(R)},{id:r("camberGain"),group:`${t} camber & toe`,label:"camber gain, RMS over the travel",unit:"\xB0/mm",scale:.02,scope:e,cost:"cheap",read:R=>{let M=n(R,A=>A.metrics.camber);return M.x.length?BF(M.x,M.y):NaN},curve:R=>g(R)},{id:r("camberSpan"),group:`${t} camber & toe`,label:"camber range over travel",unit:"\xB0",scale:1,scope:e,cost:"cheap",read:R=>sl(n(R,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:R=>sl(n(R,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:R=>{let M=R.solveAt(e,R.travelAtRoll(e,R.envelope.rollAtLimitDeg)),A=R.solveAt(e,0);return!M||!A?NaN:Math.abs(M.metrics.camber-A.metrics.camber+R.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:(R,M)=>As(R,M,A=>A.camber[il(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:(R,M)=>As(R,M,A=>A.camber[il(e,KF(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:(R,M)=>As(R,M,A=>A.corners[il(e,A.outer)].bumpToe)},{id:r("caster"),group:`${t} upright`,label:"caster",unit:"\xB0",scale:5,scope:e,cost:"cheap",read:R=>R.solveAt(e,0)?.metrics.caster??NaN},{id:r("kpi"),group:`${t} upright`,label:"kingpin inclination",unit:"\xB0",scale:5,scope:e,cost:"cheap",read:R=>R.solveAt(e,0)?.metrics.kpi??NaN},{id:r("scrubRadius"),group:`${t} upright`,label:"scrub radius",unit:"mm",scale:20,scope:e,cost:"cheap",read:R=>R.solveAt(e,0)?.metrics.scrubRadius??NaN},{id:r("mechanicalTrail"),group:`${t} upright`,label:"mechanical trail",unit:"mm",scale:20,scope:e,cost:"cheap",read:R=>R.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:R=>R.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:R=>R.solveAt(e,0)?.metrics.casterOffset??NaN},{id:r("steeringArm"),group:`${t} upright`,label:"steering arm",unit:"mm",scale:20,scope:e,cost:"cheap",read:R=>R.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:R=>f(R)?.casterGain??NaN},{id:r("kpiGain"),group:`${t} upright`,label:"kingpin inclination gain in bump",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:R=>f(R)?.kpiGain??NaN},{id:r("scrubGain"),group:`${t} upright`,label:"scrub radius gain in bump",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:R=>f(R)?.scrubGain??NaN},{id:r("trailGain"),group:`${t} upright`,label:"mechanical trail gain in bump",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:R=>f(R)?.trailGain??NaN},{id:r("motionRatio"),group:`${t} rates`,label:"motion ratio at design",unit:"-",scale:.2,scope:e,cost:"cheap",unavailable:c,read:R=>{if(c(R.car))return NaN;let M=R.sweep(e);return M?GF(M.samples.map(A=>A.travel),M.samples.map(A=>A.metrics.motionRatio??NaN))??NaN:NaN},curve:R=>{if(c(R.car))return null;let M=n(R,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:R=>{if(c(R.car))return NaN;let M=R.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 F=A.reduce((T,P)=>T+P,0)/A.length;return F>0?(Math.max(...A)-Math.min(...A))/F:NaN}},{id:r("wheelRate"),group:`${t} rates`,label:"wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:c,read:R=>{if(c(R.car))return NaN;let M=R.sweep(e);return M?GF(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:R=>p(R)?.atDesign??NaN,curve:R=>{let M=p(R);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:R=>$F(p(R)?.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:R=>l(R.car)||!R.sweep(e)?NaN:es(R.car.vehicle,R.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:d,read:R=>h(R)?.atDesign??NaN,curve:R=>{let M=h(R);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:d,read:R=>$F(h(R)?.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:R=>m(R.car)||!R.sweep(e)?NaN:To(R.car.vehicle,R.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:R=>R.axisLength(e,"uca")},{id:r("lcaAxisLength"),group:`${t} package`,label:"lower arm pivot-axis length",unit:"mm",scale:80,scope:e,cost:"geometry",read:R=>R.axisLength(e,"lca")},{id:r("linkLength"),group:`${t} package`,label:"tie/toe link length",unit:"mm",scale:100,scope:e,cost:"geometry",read:R=>R.linkLength(e)},{id:r("trackScrubRate"),group:`${t} package`,label:"track scrub rate",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:R=>R.readout(al)?.[e].trackScrubRate??NaN},{id:r("trackChange"),group:`${t} package`,label:"track change at full bump",unit:"mm",scale:2,scope:e,cost:"readout",read:R=>b(R)?.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:(R,M)=>As(R,M,A=>A.corners[il(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:(R,M)=>As(R,M,A=>A.corners[il(e,KF(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:R=>c(R.car)?NaN:sl(n(R,M=>M.metrics.damperLength).y),curve:R=>{if(c(R.car))return null;let M=n(R,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"&&x.push({id:r("camberPerSteer"),group:`${t} camber & toe`,label:"camber change with steer",unit:"\xB0/\xB0",scale:.05,scope:"front",cost:"readout",read:R=>f(R)?.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:R=>f(R)?.steerJacking??NaN}),e==="front"?x.push({id:r("antiDive"),group:`${t} anti geometry`,label:"anti-dive",unit:"%",scale:20,scope:"front",cost:"readout",read:R=>R.readout(al)?.front.antiDive??NaN}):x.push({id:r("antiSquat"),group:`${t} anti geometry`,label:"anti-squat (driving)",unit:"%",scale:20,scope:"rear",cost:"readout",read:R=>R.readout(al)?.rear.antiSquat??NaN},{id:r("antiLift"),group:`${t} anti geometry`,label:"anti-lift (braking)",unit:"%",scale:20,scope:"rear",cost:"readout",read:R=>R.readout(al)?.rear.antiLift??NaN});let k=R=>{let M=R.slice(t.length+1);return M.charAt(0).toUpperCase()+M.slice(1)};return[...new Set(x.map(R=>R.group))].flatMap(R=>x.filter(M=>M.group===R)).map(R=>({...R,quantity:`${t} \xB7 ${k(R.group)}`}))}function zF(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 K5=[{id:"kin.front.ackermannCentre",group:"Steering",label:"Ackermann near centre",unit:"%",scale:25,scope:"front",cost:"cheap",read:e=>zF(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=>zF(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}}],H5=[{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}}],Sy=[...HF("front"),...HF("rear"),...K5,...H5];var z5={front:"Front",rear:"Rear"};function WF(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 YF(e){let t=z5[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=>WF(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=[...YF("front"),...YF("rear")];var QF={front:"Front",rear:"Rear"},jF=e=>Qo("side",e),Y5=e=>Qo("drive",e)&&Qo("brake",e)?"neither brakes nor drives":null;function W5(e,t,r,n){let o=Ss(e,t,r),a=o?e.tyreAt(o):null;return a?n(a):NaN}function ws(e,t){let r={...e,read:(n,o)=>W5(n,r,o,t)};return r}var UF=e=>e?100*e.lossCamber:NaN,XF=e=>e&&!e.lifted?e.camber-e.wants:NaN;function qF(e){let t=QF[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:jF,unavailable:s=>Cp(s.params,e)},a=[ws({...o,id:r("camberErrorOuter"),label:"camber error at the outer wheel",unit:"\xB0",scale:.5},s=>XF(s.side(e)?.wheels[0])),ws({...o,id:r("camberErrorInner"),label:"camber error at the inner wheel",unit:"\xB0",scale:.5},s=>XF(s.side(e)?.wheels[1])),ws({...o,id:r("sideLossCamber"),label:"side grip lost to camber",unit:"%",scale:1},s=>UF(s.side(e))),ws({...n,appliesAt:jF,id:r("sideLossToe"),label:"side grip lost to the toe split",unit:"%",scale:1},s=>100*s.toeLoss(e)),ws({...n,appliesAt:Y5,unavailable:s=>W0(s.params,e),id:r("longLossCamber"),label:"drive and brake grip lost to camber",unit:"%",scale:1},s=>UF(s.long(e)))];return e==="front"&&a.push(ws({...n,appliesAt:s=>Qo("ackermann",s),id:r("ackermannError"),label:"Ackermann against the tyre",unit:"%",scale:25},s=>s.ackermann())),a}var wy=[...qF("front"),...qF("rear")],j5=/^tyre\.(front|rear)\.(camberErrorOuter|camberErrorInner|sideLossCamber|longLossCamber)$/;function Fy(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=j5.exec(a.id);if(!i)continue;let c=i[1],l=i[2]==="longLossCamber",u=s?.stateId==="*"?e.states.filter(m=>!a.appliesAt?.(m)):[Ss(e,a,s)].filter(m=>!!m);for(let m of u){let d=`${c}|${m.id}|${l}`;if(r.has(d))continue;let p=e.tyreAt(m),h=p?l?p.long(c):p.side(c):null;if(!h)continue;let{lo:f,hi:b,stated:g}=h.range,y=g?`the ${o(f)} \u2026 ${o(b)} its data covers`:`the \xB1${b.toFixed(0)}\xB0 read without a stated range`,x=M=>l?M===0?"left":"right":M===0?"outer":"inner",k=h.wheels.findIndex(M=>M.atEdge),v=h.wheels.findIndex(M=>M.outside&&!M.lifted),R=[];k>=0&&R.push(`the ${QF[c].toLowerCase()} ${x(k)} tyre wants ${o(h.wheels[k].wants)}, the edge of ${y}, and may want more`),v>=0&&R.push(`the ${x(v)} wheel has ${o(h.wheels[v].camber)}, past it, and is read at ${o(h.wheels[v].read)}`),R.length&&r.set(d,`In the ${n(m)} ${R.join("; ")}.`)}}return[...r.values()]}function Cy(e,t){let r=e.appliesAt?.(t);return r?`is read at ${t.name}, which ${r}`:null}var U5={front:"Front",rear:"Rear"};function X5(e,t,r,n){let o=Ss(e,t,r),a=o?e.platformAt(o):null;return(a?n(a):null)??NaN}function mr(e,t){let r={...e,read:(n,o)=>X5(n,r,o,t)};return r}var Ty={cost:"cheap",reads:"state"},q5={unavailable:e=>Yp(e.params)};function ZF(e){let t=U5[e],r=o=>`platform.${e}.${o}`,n={...Ty,group:`${t} platform`,quantity:`${t} \xB7 Platform`,scope:e};return[mr({...n,id:r("rideHeight"),label:"ride height at a state",unit:"mm",scale:5,acrossStates:"min"},o=>o[e].height),mr({...n,id:r("toBumpStop"),label:"travel left to the bump stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>tl(o.vehicle,o.params,e,"bump")},o=>o[e].toBump),mr({...n,id:r("toDroopStop"),label:"travel left to the droop stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>tl(o.vehicle,o.params,e,"droop")},o=>o[e].toDroop)]}var qp={...Ty,group:"Platform",scope:"car"},cl={...Ty,...q5,group:"Aero platform",groupShort:"Aero",scope:"car"},Py=[...ZF("front"),...ZF("rear"),mr({...qp,id:"platform.rake",label:"rake at a state",unit:"\xB0",scale:.2,acrossStates:"span"},e=>e.rakeDeg),mr({...qp,id:"platform.pitch",label:"pitch at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.pitchDeg),mr({...qp,id:"platform.roll",label:"body roll at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.rollDeg),mr({...qp,id:"platform.groundClearance",label:"ground clearance at a state",unit:"mm",scale:5,acrossStates:"min",unavailable:e=>hy(e.vehicle)},e=>e.clearance?.height),mr({...cl,id:"platform.balance",label:"balance at a state",unit:"%",scale:1,acrossStates:"span"},e=>e.aero?.balance),mr({...cl,id:"platform.clA",label:"downforce Cl\xB7A at a state",unit:"m\xB2",scale:.1,acrossStates:"mean"},e=>e.aero?.clA),mr({...cl,id:"platform.cdA",label:"drag Cd\xB7A at a state",unit:"m\xB2",scale:.05,acrossStates:"mean"},e=>e.aero?.cdA),mr({...cl,id:"platform.dataMargin",label:"margin to the model\u2019s data",unit:"mm",scale:5,acrossStates:"min"},e=>e.aero?.dataMargin),mr({...cl,id:"platform.loopMargin",label:"aero-elastic margin, 1 \u2212 loop gain",unit:"-",scale:.1,acrossStates:"min"},e=>e.aero?.loopMargin)];var JF={understeer:"operating",yawFreq:"speed",yawZeta:"speed",yawStiffness:"operating",steeringTorque:"operating",steeringTorqueGradient:"operating"};function Rt(e,t,r,n="cheap"){let o=gg[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,...JF[e]?{reads:JF[e]}:{},read:(a,s)=>{let i=a.dynInput(),c=a.dynCtx(s);return i&&c?o.compute(i,c):NaN}}}var Q5=[Rt("understeer","Handling \u2014 balance",.1),Rt("tlltdFront","Handling \u2014 balance",5),Rt("rollStiffFront","Handling \u2014 balance",5)],Z5=[Rt("yawFreq","Handling \u2014 response",.5),Rt("yawZeta","Handling \u2014 response",.2),Rt("stabilitySpeed","Handling \u2014 response",50),Rt("yawStiffness","Handling \u2014 response",2e4,"trim")],J5=[Rt("steeringTorque","Steering feel",1,"trim"),Rt("steeringTorqueGradient","Steering feel",2,"trim")],e3=[Rt("rollGradient","Ride & body",.5),Rt("pitchGradient","Ride & body",.5),Rt("rideFreqFront","Ride & body",.5),Rt("rideFreqRear","Ride & body",.5),Rt("rollFreq","Ride & body",.5),Rt("pitchFreq","Ride & body",.5),Rt("zetaFront","Ride & body",.2),Rt("zetaRear","Ride & body",.2)],t3=[{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}],r3=[{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=[...Q5,...Z5,...J5,...e3,...t3,...r3];function n3(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 Dy=[{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)=>n3(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 o3(e,t){let r=/^(.*?)\s*\(([^)]+)\)\s*$/.exec(e);return r?{label:r[1],unit:r[2]}:{label:e,unit:t?"s":""}}function a3(e){return e==="s"||e==="kWh"?.1:e==="km/h"?2:1}var eC=new WeakMap;function Qp(e){let t=eC.get(e);return t||(t=e.metrics.filter(vl).map(r=>{let{label:n,unit:o}=o3(r.label,r.format==="time");return{id:`event.${e.id}.${r.key}`,group:`Events \xB7 ${e.label}`,groupShort:"Events",label:n,unit:o,scale:a3(o),scope:"car",cost:"session",read:a=>a.session(e.id)?.[r.key]??NaN}}),eC.set(e,t),t)}var Ey=fs.flatMap(Qp);var Zp=[...Sy,...Ay,...wy,...Py,...Ly,...Dy,...Ey],Fs=Object.fromEntries(Zp.map(e=>[e.id,e]));var tC={all:Zp,byId:Fs},rC=new WeakMap;function Rr(e=[]){if(e.length===0)return tC;let t=rC.get(e);if(t)return t;let r=Hg(e).filter(n=>!hs(n.id)).flatMap(Qp);return t=r.length?{all:[...Zp,...r],byId:{...Fs,...Object.fromEntries(r.map(n=>[n.id,n]))}}:tC,rC.set(e,t),t}var ll=180/Math.PI,Cs=Math.PI/180,i3=.2;function Jp(e,t){let r=G(t,e);return te(r[0]<0?af(r):r)}var ed=e=>({side:Math.atan2(e[2],e[0])*ll,plan:Math.atan2(e[1],e[0])*ll}),td=(e,t)=>te([1,Math.tan(t*Cs),Math.tan(e*Cs)]),ul=e=>Math.abs(e[0])>=i3,rd=(e,t)=>Math.atan(t/Math.max(e,1))*ll,nd=(e,t)=>Math.tan(t*Cs)*Math.max(e,1);var Jn=["side","plan","clock","len"],rr={uca:{fore:"ucaFront",aft:"ucaRear",ball:"uprightUpper"},lca:{fore:"lcaFront",aft:"lcaRear",ball:"uprightLower"}},ml={uca:"upper arm",lca:"lower arm"},c3=1,nC=(e,t)=>Jp(e[rr[t].fore],e[rr[t].aft]);function oC(e){let t=te(G(of,Q(e,J(of,e))));return{e1:t,e2:le(e,t)}}function Iy(e,t){let r=nC(e,t);if(!ul(r))return`the ${ml[t]}'s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it`;let n=rr[t],o=Dn(e[n.ball],e[n.fore],r);return Math.hypot(...G(o,e[n.ball]))>=c3?null:`the ${ml[t]}'s ball joint sits on its own pivot axis, so the arm has no length to swing on`}function An(e,t){let r=rr[t],n=e[r.ball],o=nC(e,t),a=Dn(n,e[r.fore],o),s=G(a,n),i=Math.hypot(s[0],s[1],s[2]),{e1:c,e2:l}=oC(o),u=i>0?Q(s,1/i):c;return{...ed(o),clock:Math.atan2(J(u,l),J(u,c))*ll,len:i,sFront:J(G(e[r.fore],a),o),sRear:J(G(e[r.aft],a),o)}}function _y(e,t){let r=td(e.side,e.plan),{e1:n,e2:o}=oC(r),a=oe(Q(n,Math.cos(e.clock*Cs)),Q(o,Math.sin(e.clock*Cs))),s=oe(t,Q(a,e.len));return{fore:oe(s,Q(r,e.sFront)),aft:oe(s,Q(r,e.sRear))}}function aC(e,t,r,n){let o=rr[t],a={...An(e,t),[r]:n},{fore:s,aft:i}=_y(a,e[o.ball]);return{...e,[o.fore]:s,[o.aft]:i}}function sC(e,t){return t==="clock"?e.len:Math.abs(e.sFront-e.sRear)/2}function od(e,t,r){return t==="len"?r:rd(sC(e,t),r)}function Ny(e,t,r){return t==="len"?r:nd(sC(e,t),r)}var ra=["side","plan","atY","atZ"],zr={fore:"rockerPivotA",aft:"rockerPivotB"},l3=5,iC=e=>Jp(e.rockerPivotA,e.rockerPivotB);function Ts(e){return Math.hypot(...G(e.rockerPivotB,e.rockerPivotA))<l3?"the rocker\u2019s two pivots are the same point, so there is no axis to describe":ul(iC(e))?null:"the rocker\u2019s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it"}function eo(e){let t=iC(e),r=ul(t)?t:[1,0,0],n=e.rockerPivotA,o=oe(n,Q(r,-n[0]/r[0]));return{...ed(r),atY:o[1],atZ:o[2],sA:J(G(n,o),r),sB:J(G(e.rockerPivotB,o),r)}}function Oy(e){let t=td(e.side,e.plan),r=[0,e.atY,e.atZ];return{a:oe(r,Q(t,e.sA)),b:oe(r,Q(t,e.sB))}}function cC(e,t,r){if(Ts(e))return e;let{a:n,b:o}=Oy({...eo(e),[t]:r});return{...e,rockerPivotA:n,rockerPivotB:o}}var lC=e=>Math.abs(e.sA-e.sB)/2;function Vy(e,t,r){return t==="side"||t==="plan"?rd(lC(e),r):r}function By(e,t,r){return t==="side"||t==="plan"?nd(lC(e),r):r}var kr={front:"Front",rear:"Rear"},vr=["x","y","z"],tt=(e,t)=>t==="front"?e.front:e.rear,pl=(e,t,r)=>t==="front"?{...e,front:r}:{...e,rear:r},uC=[{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"}]}],mC={damperChassis:"strut top mount",pushrodOuter:"strut lower mount"},na=30;function u3(e){let t=[];for(let r of["front","rear"]){let n=tt(e.vehicle,r).config.layout==="mcpherson";for(let o of uC)for(let{key:a,label:s}of o.keys){let i=n&&mC[a]||s;for(let c=0;c<3;c++)t.push({id:`hp.${r}.${a}.${vr[c]}`,group:`${kr[r]} hardpoints \u2014 ${o.kind}`,label:`${i} ${vr[c]}`,scope:kr[r],unit:"mm",defaultSpan:na,read:l=>tt(l.vehicle,r).hardpoints[a][c],write:(l,u)=>{let m=tt(l.vehicle,r),d=[...m.hardpoints[a]];d[c]=u;let p={...m.hardpoints,[a]:d};return{...l,vehicle:pl(l.vehicle,r,{...m,hardpoints:p})}}})}}return t}var m3={side:"axis side-view angle",plan:"axis plan-view angle",clock:"arm clock angle",len:"effective arm length"},p3={side:"\xB0",plan:"\xB0",clock:"\xB0",len:"mm"};function d3(e){let t=[];for(let r of["front","rear"]){let n=tt(e.vehicle,r).config.layout==="mcpherson";for(let o of["uca","lca"]){let a=tt(e.vehicle,r).hardpoints,s=Iy(a,o)?null:An(a,o);for(let i of Jn)t.push({id:`arm.${r}.${o}.${i}`,group:`${kr[r]} ${n?"arm axes":"wishbone axes"}`,label:`${ml[o]} \u2014 ${m3[i]}`,scope:kr[r],unit:p3[i],defaultSpan:s?od(s,i,na):na,read:c=>An(tt(c.vehicle,r).hardpoints,o)[i],write:(c,l)=>{let u=tt(c.vehicle,r),m=aC(u.hardpoints,o,i,l);return{...c,vehicle:pl(c.vehicle,r,{...u,hardpoints:m})}}})}}return t}var f3={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"},h3={side:"\xB0",plan:"\xB0",atY:"mm",atZ:"mm"};function b3(e){let t=[];for(let r of["front","rear"]){let n=tt(e.vehicle,r).hardpoints,o=Ts(n)?null:eo(n);for(let a of ra)t.push({id:`rocker.${r}.${a}`,group:`${kr[r]} rocker axis`,label:`rocker \u2014 ${f3[a]}`,scope:kr[r],unit:h3[a],defaultSpan:o?Vy(o,a,na):na,read:s=>eo(tt(s.vehicle,r).hardpoints)[a],write:(s,i)=>{let c=tt(s.vehicle,r),l=cC(c.hardpoints,a,i);return{...s,vehicle:pl(s.vehicle,r,{...c,hardpoints:l})}}})}return t}var ad={front:"heaveFrontDesign",rear:"heaveRearDesign"},$y={front:"arbFrontDesign",rear:"arbRearDesign"};function g3(e,t){return{heave:e.config.actuation==="decoupled"?"heave element":"third spring",roll:t?.design.kind==="coil"?"roll shock":"anti-roll bar"}}var sd=e=>/^(heave|roll)\.(front|rear)\.(outer|inner|anchor)\.[xyz]$/.test(e);function y3(e){let t=[];for(let r of["front","rear"]){let n=tt(e.vehicle,r),o=e.params[ad[r]],a=e.params[$y[r]],s=g3(n,a),i=h=>h.params[ad[r]],c=h=>h.params[$y[r]],l=(h,f)=>({...h,params:{...h.params,[ad[r]]:f}}),u=(h,f)=>({...h,params:{...h.params,[$y[r]]:f}}),m={group:`${kr[r]} heave & roll elements`,scope:kr[r]},d=(h,f,b,g,y)=>{for(let x of b)t.push({...m,id:`${h}.${vr[x]}`,label:`${f} ${vr[x]}`,unit:"mm",defaultSpan:na,read:k=>g(k)[x],write:(k,v)=>{let R=[...g(k)];return R[x]=v,y(k,R)}})},p=(h,f,b,g,y)=>{t.push({...m,id:h,label:f,unit:"N/mm",defaultSpan:Math.max(5,b*.4),read:g,write:y})};if(o?.design.kind==="coil"){if(o.linkage){let h=b=>i(b).linkage;d(`heave.${r}.outer`,`${s.heave} eye`,[0,1,2],b=>h(b).outer,(b,g)=>l(b,{...i(b),linkage:{...h(b),outer:g}})),o.linkage.mount?.kind==="chassis"&&d(`heave.${r}.anchor`,`${s.heave} chassis anchor`,[0,2],b=>h(b).mount.anchor,(b,g)=>l(b,{...i(b),linkage:{...h(b),mount:{kind:"chassis",anchor:g}}}))}if(typeof o.design.rate=="number"){let h=f=>i(f).design;p(`heave.${r}.rate`,`${s.heave} spring rate (@element)`,o.design.rate,f=>h(f).rate,(f,b)=>l(f,{...i(f),design:{...h(f),rate:b}}))}}if(a&&a.design.kind!=="none"){if(a.linkage&&a.design.kind!=="direct"){let f=x=>c(x).linkage,b=_n(n,a.linkage,a.design.kind),[g,y]=b?["left arm eye","right arm eye"]:["drop-link pickup","arm tip"];d(`roll.${r}.outer`,`${s.roll} ${g}`,[0,1,2],x=>f(x).outer,(x,k)=>u(x,{...c(x),linkage:{...f(x),outer:k}})),d(`roll.${r}.inner`,`${s.roll} ${y}`,[0,1,2],x=>f(x).inner,(x,k)=>u(x,{...c(x),linkage:{...f(x),inner:k}}))}let h=a.design;if(h.kind==="coil"&&typeof h.rate=="number"){let f=b=>c(b).design;p(`roll.${r}.rate`,`${s.roll} spring rate (@element)`,h.rate,b=>f(b).rate,(b,g)=>u(b,{...c(b),design:{kind:"coil",rate:g}}))}else h.kind==="direct"&&p(`roll.${r}.wheelRate`,`${s.roll} rate (@wheel)`,h.wheelRate,f=>c(f).design.wheelRate,(f,b)=>u(f,{...c(f),design:{kind:"direct",wheelRate:b}}))}}return t}var x3=[{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 R3(e){let t=[];for(let r of["front","rear"]){let n=tt(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:kr[r],unit:"N/mm",defaultSpan:Math.max(500,l*.4),read:u=>i(tt(u.vehicle,r).compliance??{})??l,write:(u,m)=>{let d=tt(u.vehicle,r),p={...d,compliance:c(d.compliance??{},Math.max(1,m))};return{...u,vehicle:pl(u.vehicle,r,p)}}})};for(let a of["ucaFront","ucaRear","lcaFront","lcaRear","tieRod","pushRod"])o(`link.${a}`,`${v3[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}`,`${k3[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 v3={ucaFront:"UCA front leg",ucaRear:"UCA rear leg",lcaFront:"LCA front leg",lcaRear:"LCA rear leg",tieRod:"tie rod",pushRod:"push/pull rod"},k3={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 M3(){return x3.map(e=>({id:`cfg.${e.axle}.${e.field}`,group:e.group,label:e.label,scope:kr[e.axle],unit:e.unit,defaultSpan:e.span(e.fallback),read:t=>tt(t.vehicle,e.axle).config[e.field]??e.fallback,write:(t,r)=>{let n=tt(t.vehicle,e.axle),o={...n,config:{...n.config,[e.field]:r}};return{...t,vehicle:pl(t.vehicle,e.axle,o)}}}))}function S3(e){let t=ho(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=>ho(c.params.steeringSystem)[n],write:(c,l)=>({...c,params:{...c.params,steeringSystem:ho({...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 A3(e){let t=Do(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=bm[`${n}.${s}`];return{id:`driveline.${n}.${s}`,group:"Differential",label:c.label.charAt(0).toLowerCase()+c.label.slice(1),scope:kr[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:hm({...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 w3(e){if(Li(e.params)!=="hydraulic")return[];let t=[{id:"brakeSetup.barFront",group:"Brakes",label:`${pb("barFront").toLowerCase()}, front share`,unit:"-",defaultSpan:.05,read:a=>an(a.params.brakeSetup).barFront,write:(a,s)=>({...a,params:{...a.params,brakeSetup:an({...an(a.params.brakeSetup),barFront:s})}})}];if(!e.params.brakeModel)return t;let r=Lr(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:mb(a.circuit?`${a.circuit}.${String(a.key)}`:a.key),unit:s,defaultSpan:i,read:c=>n(Lr(c.params.brakeModel),a),write:(c,l)=>{let u=Lr(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:Lr(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 pC=e=>!!e&&typeof e=="object"&&"value"in e&&"label"in e;function dC(e){let t={...e};for(let r of Object.keys(t)){let n=t[r];pC(n)&&(t[r]={...n})}return t}function F3(e){let t=[];for(let r of HM(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 pC(s)?s.value:NaN},write:(a,s)=>{let i=dC(a.params);return vm(i,n.label,s),{...a,params:i}}})}return t}function fC(e){let t={};for(let s of["front","rear"]){if(!tt(e.vehicle,s).measured)continue;let c="this axle is described by measured curves, so its linkage is not solved";for(let l of uC)for(let{key:u}of l.keys)for(let m of vr)t[`hp.${s}.${u}.${m}`]={why:c};for(let l of["uca","lca"])for(let u of Jn)t[`arm.${s}.${l}.${u}`]={why:c};for(let l of ra)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 d of vr)t[`${u}.${s}.${m}.${d}`]={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(tt(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 vr)t[`hp.${s}.${c}.${l}`]={why:i};for(let c of ra)t[`rocker.${s}.${c}`]={why:i}}for(let s of["front","rear"]){let i=tt(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 vr)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=tt(e.vehicle,s),c=e.params[ad[s]]?.linkage;if(i.measured||!c||c.attach!=="rocker"||c.mount?.kind==="chassis")continue;let l=i.hardpoints,u=[0,1,2].map(d=>l.rockerPivotB[d]-l.rockerPivotA[d]),m=Math.hypot(u[0],u[1],u[2]);if(m>0)for(let d=0;d<3;d++)Math.abs(u[d]/m)<1-1e-12||(t[`heave.${s}.outer.${vr[d]}`]={why:`the rocker shaft runs along ${vr[d]} \u2014 this only slides the eye along it`})}for(let s of["front","rear"]){let i=tt(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 vr)t[`hp.${s}.${l}.${u}`]={why:c,useInstead:`hp.${s}.damperChassis.${u}`};for(let l of Jn)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=tt(e.vehicle,s);if(i.measured)continue;for(let l of["uca","lca"]){if(l==="uca"&&i.config.layout==="mcpherson")continue;let u=Iy(i.hardpoints,l);if(u)for(let m of Jn)t[`arm.${s}.${l}.${m}`]={why:u,useInstead:`hp.${s}.${rr[l].fore}.z`}}let c=Ts(i.hardpoints);if(c&&i.config.actuation!=="direct")for(let l of ra)t[`rocker.${s}.${l}`]={why:c,useInstead:`hp.${s}.${zr.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 d=m.design.kind==="direct"?`${u}.${l}.wheelRate`:`${u}.${l}.rate`;t[i]={why:`computed from ${c}`,useInstead:d}}let o=e.params.aeroModelId||e.params.aeroModel?qb:Qb;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(ym))t[`param.${s}`]={why:i};for(let[s,i]of Object.entries(xm(e.params)))t[`param.${s}`]={why:i};for(let[s,i]of Object.entries(Zb(e.params)))t[`param.${s}`]={why:i};let a=Li(e.params)==="hydraulic";for(let[s,i]of Object.entries(Iu(e.params)))t[`param.${s}`]=a?{why:i,useInstead:"brakeSetup.barFront"}:{why:i};return t}function hC(e){let t={...T3,...fC(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[...u3(e),...d3(e),...b3(e),...y3(e),...M3(),...S3(e),...w3(e),...A3(e),...R3(e),...F3(e.params)].map(r)}var C3={spring_front:"cfg.front.springRate",spring_rear:"cfg.rear.springRate"},T3=Object.fromEntries(Object.entries(Xb).map(([e,t])=>[`param.${e}`,{why:t,useInstead:C3[e]}])),bt=e=>e.scope?`${e.scope} \xB7 ${e.label}`:e.label;function _t(e){let t={};for(let n of hC(e))t[n.id]=n;let r=(n,o)=>{if(typeof o!="string")return;let a=OF(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 Gy=e=>e.step!==void 0&&Number.isFinite(e.step)&&e.step>0?e.step:0,Ky=e=>Gy(e)>0||(e.values?.length??0)>0,Hy=e=>e.some(Ky),bC=e=>1e-9*Math.max(1,Math.abs(e.lo),Math.abs(e.hi));function gC(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=Gy(e);if(!r||!Number.isFinite(e.start))return t;let n=bC(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 yC=(e,t)=>t.map((r,n)=>e[n]&&Ky(e[n])?gC(e[n],r):r);function zy(e,t=1e3){if(e.values?.length)return e.values.length;let r=Gy(e);if(!r||!Number.isFinite(e.start))return 1/0;let n=bC(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 Yy(e,t,r){let n=yC(e.variables,t),o=n.every((a,s)=>a===t[s]);return{x:n,score:o?r:tn(e,n)}}function Uy(e,t){if(!e.variables.some(RC))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(vC(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 RC=e=>!!(e.fixed||e.around||e.follows)||vC(e),vC=e=>!!e.values?.length&&(e.lo!==Math.min(...e.values)||e.hi!==Math.max(...e.values));function Ct(e,t){if(!t.variables.some(RC))return t;let r=_t(e);return Uy(t,n=>{let o=r[n];if(!o)return NaN;try{return o.read(e)}catch{return NaN}})}function Mr(e){return[...e.objectives,...e.constraints,...e.watches??[]]}var cd=e=>(e.metrics??Rr()).byId;function Xy(e,t){t=Ct(e,t);let r=_t(e),n=[];for(let o of t.variables){let a=r[o.id];a&&n.push({id:a.id,name:bt(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 Ps(e,t,r){t=Ct(e,t);let n=_t(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]))}),Zy(e,o,t.followers,n)}function qy(e,t,r={}){let n=t.states??[],o=n.some(c=>c.follows);if(!o&&!t.envelopeFollows)return t;let a=Zn(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=B0(n,c,D3(r)))}catch{s=n}let i=t.envelope;if(t.envelopeFollows&&s.length){let c=s.map(f=>a.poseAt(f)).filter(f=>f!==null),l=cd(r),u=Qy(t,l),m=Mr(t).map(f=>({r:f,m:l[f.metricId]})).filter(({m:f})=>f&&f.id.startsWith("kin.")&&f.reads!=="state"&&(f.scope==="car"||u.includes(f.scope))),d=f=>{let b=Zn(e,{density:t.density,envelope:f,assemble:r.assemble,numerics:r.numerics});return m.every(({r:g,m:y})=>Number.isFinite(Ft(b,y,g.at)))},p=c.length===s.length?L3(e,G0(c,u),u):null,h=p&&m.length?P3(p,d):p;h&&!K0(h,t.envelope)&&(i=h)}return s===n&&i===t.envelope?t:{...t,states:s,envelope:i}}var id=3;function P3(e,t){let r=(c,l)=>t({...e,travelMin:c,travelMax:l}),n=e.travelMin-id,o=e.travelMax+id;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+id)),i=Math.max(1,Math.min(e.travelMax,o-id));return s===e.travelMin&&i===e.travelMax?e:{...e,travelMin:s,travelMax:i}}function Qy(e,t){let r=new Set;for(let n of Mr(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 L3(e,t,r){if(!t)return null;let n=vs(e.vehicle,e.params),{travelMin:o,travelMax:a}=t;for(let s of r.map(i=>n[i]))try{let i=ot(s,{travelMin:o,travelMax:a,steps:el.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 D3(e){let t=e.projectTrack?.();if(!t)return null;try{return V0(wt(t.asset,t.numerics))}catch{return null}}function Zy(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 to(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 kC=(e,t="")=>t&&t!=="-"?`${e} ${t}`:`${e}`;function MC(e,t,r){let n=t??Fs[e.metricId],o=(n?it(n):e.metricId)+oa(e.at,n,r),a=s=>kC(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 oa(e,t,r){if(!e&&t?.reads!=="state")return"";e??={};let n=[];if(t?.reads==="state")if(e.stateId===Kr)n.push(My(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&&vy(t)&&n.push(`${(e.speed*3.6).toFixed(0)} km/h`),e.ayG!==void 0&&ky(t)&&n.push(`${e.ayG.toFixed(2)} g`),e.courseId===ol&&t?.reads==="course")n.push(Ry(t));else if(e.courseId&&t?.reads==="course"){let o=r?.lap.courses.find(a=>a.id===e.courseId);o&&n.push(J0(o))}return n.length?` @ ${n.join(", ")}`:""}function SC(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 AC=5e-4;function wC(e,t){return e.cost!=="lap"&&e.cost!=="session"?0:Number.isFinite(t)?AC*Math.abs(t):0}function ld(e,t,r={}){return Zn(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 ud(e,t,r={}){t=Ct(e,t);let n=Xy(e,t),o=_t(e),a=cd(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,d)=>{let p=0,h=[];for(let{spec:f,metric:b}of m){let g=Ft(d,b,f.at);if(!Number.isFinite(g))return{ok:!1,violation:d.failure?.violation??400,reason:d.failure?.reason??`${it(b)} could not be computed`};let y=to(f,g);y>0&&(p+=y/b.scale,h.push(`${MC(f,b,t)} (${kC(g.toFixed(3),b.unit)})`))}return h.length===0?xi:{ok:!1,violation:p,reason:h.join("; ")}};return{name:"study",variables:n,build:m=>{let d=e;return t.variables.forEach((p,h)=>{let f=o[p.id];f&&(d=f.write(d,m[h]))}),d=Zy(e,d,t.followers,o),{car:d,ev:ld(d,t,r)}},feasible:({ev:m})=>{let d=u(i,m);if(!d.ok)return d;for(let{spec:p,metric:h}of c)Ft(m,h,p.at);for(let{spec:p,metric:h}of l)Ft(m,h,p.at);return m.failure?{ok:!1,violation:m.failure.violation,reason:m.failure.reason}:u(c,m)},terms:({ev:m})=>l.map(({spec:d,metric:p})=>{let h=Ft(m,p,d.at);return{name:it(p)+oa(d.at,p,t),raw:h,unit:p.unit,weight:d.weight,contribution:SC(d,p,h),resolution:Math.abs(d.weight)*wC(p,h)/p.scale}})}}function Wy(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 FC(e,t){if(e.variables.some(o=>o.id===t))return!0;let r=ea(t);if(!r||!Ms.includes(r.axis))return!1;if(e.variables.some(o=>ur(o.id)?.point===r.point))return!0;let n=Wy(t);return!!n&&e.variables.some(o=>/^(arm|rocker)\./.test(o.id)&&Wy(o.id)===n)}function E3(e,t){let r=e.followers??[],n=new Map(r.map(i=>[i.id,i.follows])),o=i=>{let c=t[i],l=ea(i);return c&&l&&Ms.includes(l.axis)?{name:bt({...c,label:c.label.replace(/ [xyz]$/,"")}),axis:l.axis}:{name:c?bt(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),d=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}${d(p)} cannot be moved: ${c.supersededBy.why}.`),!l)s(`no-lead:${u.name}:${i.follows}`,u.axis,p=>`${u.name}${d(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}${d(p)} cannot move with itself.`);else if(l.unit!==c.unit)s(`unit:${u.name}:${m.name}`,u.axis,p=>`${u.name}${d(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,h=>`${u.name}${d(h)} moves with ${m.name}, which itself moves with ${p.name}. Link it to ${p.name}.`)}else FC(e,i.follows)||s(`still:${u.name}:${m.name}`,u.axis,p=>`${u.name}${d(p)} moves with ${m.name}, which the study does not move${d(p)}. Free that one, or give this its own bound.`)}return[...a.values()].map(i=>i.text(i.axes.join(", ")))}function Jy(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=Ct(e,t);let a=_t(e),s=[],i=cd(r),c=Mr(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=Mr(t).filter(y=>i[y.metricId]?.reads==="state");if(m.length){let y=t.states??[];if(!y.length)s.push("This study reads targets at a state and has none. Take the car\u2019s five under Conditions.");else{let x=new Set([...y.map(k=>k.id),Kr]);for(let k of m){let v=i[k.metricId];if(k.at?.stateId&&!x.has(k.at.stateId))s.push(`${it(v)} names a state this study no longer has. Point it at one of the states under Conditions.`);else if(k.at?.stateId===Kr&&!v.acrossStates)s.push(`${it(v)} is read at one state at a time, not over every state.`);else if(v.appliesAt){let R=k.at?.stateId&&k.at.stateId!==Kr?y.find(A=>A.id===k.at.stateId):void 0,M=R?Cy(v,R):null;M?s.push(`${it(v)} ${M}. Point it at a state that does.`):!R&&!Xp(v,y)&&s.push(`${it(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 d=new Set([...t.lap.courses.map(y=>y.id),ol]);for(let y of Mr(t))if(y.at?.courseId&&!d.has(y.at.courseId)){let x=i[y.metricId];s.push(`${x?it(x):y.metricId} names a course this study no longer has. Point it at one of the courses below.`)}u&&t.lap.ggvMode==="fast"&&t.variables.some(x=>/arb_|spring|heave_|front_mass_diss|cg_height|^hp\./.test(x.id.replace("param.","")))&&s.push("The fast grip envelope is a point mass: no load transfer, no trim. It cannot see bars, springs, roll centres or where the mass sits, and this study moves at least one of those."),n?s.push(o?"Every variable is fixed or moves with another \u2014 there is nothing to search.":"Every variable is fixed \u2014 there is nothing to search."):t.variables.length===0&&s.push("No variables selected \u2014 there is nothing to search."),t.objectives.length===0&&s.push("No objective selected. Constraints alone say which designs are legal, not which is better.");for(let y of t.variables){let x=a[y.id];if(!x){s.push(`\u201C${y.id}\u201D is not a variable this car has.`);continue}if(y.values&&y.values.length<2?s.push(`${bt(x)}: list two values or more, or fix it where it is.`):y.hi>y.lo?y.step!==void 0&&zy({...y,start:x.read(e)})<2&&s.push(`${bt(x)}: a step of ${y.step} ${x.unit} leaves no other place to land in its box. Make the step finer or the box wider, or fix it.`):s.push(`${bt(x)}: the upper bound must be above the lower one (${y.lo} to ${y.hi}).`),x.supersededBy){let v=x.supersededBy.useInstead?a[x.supersededBy.useInstead]:void 0,R=v?bt(v):void 0;s.push(`${bt(x)} cannot be searched: ${x.supersededBy.why}.`+(R?` Use ${R} instead.`:""))}let k=x.read(e);Number.isFinite(k)&&(k<y.lo||k>y.hi)&&s.push(`${bt(x)} starts at ${k.toFixed(1)} ${x.unit}, outside its own bounds.`)}let p=t.followers??[],h=new Map;for(let y of[...t.variables.map(x=>x.id),...p.map(x=>x.id)]){let x=Wy(y);if(!x)continue;let k=h.get(x);k||h.set(x,k={arms:[],coords:[]}),(/^(arm|rocker)\./.test(y)?k.arms:k.coords).push(y)}for(let[y,x]of h){if(x.arms.length===0||x.coords.length===0)continue;let k=R=>a[R]?bt(a[R]):R,v=y.endsWith("rocker")?"rocker":`${y.endsWith("uca")?"upper":"lower"} arm`;s.push(`${y.startsWith("front")?"The front":"The rear"} ${v} is being moved two ways at once \u2014 as an axis (${x.arms.map(k).join(", ")}) and as pivot coordinates (${x.coords.map(k).join(", ")}). They describe the same ${v}, so whichever is applied second overwrites the other. Keep one.`)}let f=new Map,b=new Set(p.map(y=>y.id));for(let y of[...t.variables.map(x=>x.id),...b]){let x=ea(y);if(!x)continue;let k=ur(y),v=b.has(y)?"with":k?`${k.shape.kind}:${y.slice(y.lastIndexOf(".")+1).replace(/[uv]$/,"")}`:"axes",R=f.get(x.point);R||f.set(x.point,R=new Set),R.add(v)}for(let[y,x]of f){if(x.size<2||x.size===2&&x.has("axes")&&x.has("with"))continue;let k=[...x].map(F=>F.split(":")[0]),v=F=>k.filter(T=>T===F).length,R=[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?bt({...M,label:M.label.replace(/ x$/,"")}):y;s.push(`${A} is moved more than one way at once \u2014 ${R.join(" and ")}. Each write moves it off the other's, so keep one.`)}s.push(...E3(t,a));for(let y of t.constraints){let x=i[y.metricId];if(!x){s.push(`\u201C${y.metricId}\u201D is not a metric.`);continue}y.op==="band"&&!((y.limit2??y.limit)>y.limit)&&s.push(`${it(x)}: the band's upper limit must be above its lower one.`)}l&&!(t.operating.speed>0)&&s.push("Whole-car metrics need a speed to be read at; a yaw-moment diagram at rest is degenerate.");for(let y of Mr(t))if(y.at?.speed!==void 0&&!(y.at.speed>0)){let x=i[y.metricId];s.push(`${x?it(x):y.metricId} is asked for at rest, where a yaw-moment diagram is degenerate.`)}for(let y of t.watches??[])i[y.metricId]||s.push(`\u201C${y.metricId}\u201D is not a metric.`);let g=new Set;for(let y of Mr(t)){let x=i[y.metricId],k=x?.unavailable?.(e);!x||!k||g.has(x.id)||(g.add(x.id),s.push(`${it(x)} 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(`${it(i[y.metricId])}: \u201Chit a value\u201D needs a value.`):y.goal==="target"&&y.tolerance!==void 0&&!(y.tolerance>=0)&&s.push(`${it(i[y.metricId])}: the tolerance must be zero or more.`):s.push(`${it(i[y.metricId])}: weight must be positive.`):s.push(`\u201C${y.metricId}\u201D is not a metric.`);return s}var CC=.1,TC=2e3,jy=3;function ex(e,t,r={},n=TC){t=Ct(e,t);let o=ud(e,t,r),a=cd(r),s=_t(e),i=o.variables.map(S=>S.start),c=S=>{let w=o.build(S);return o.feasible(w).ok&&o.terms(w),w},l=c(i),u=o.feasible(l),m=[...t.objectives,...t.constraints],d=(S,w=m)=>{let C={};for(let L of w){let E=a[L.metricId];E&&(C[`${L.metricId}@${ta(L.at)}`]=Ft(S.ev,E,L.at))}return C},p=S=>m.map(w=>S[`${w.metricId}@${ta(w.at)}`]).map(w=>Number.isFinite(w)?w.toFixed(9):"x").join("|"),h=d(l,Mr(t)),f=p(h),b=[],g=[],y={},x=[],k=0;t.variables.forEach((S,w)=>{let C=s[S.id];if(!C)return;if(x.length>=jy&&k>n){g.push(C);return}let L=[...i];L[w]=i[w]+(S.hi-i[w])*.25||S.hi;let E=performance.now(),_=c(L),O=performance.now()-E;k+=O,x.push(O);let I=d(_);y[C.id]=I,p(I)===f&&b.push(C)});let v=t.variables[0],R=v?t.variables.indexOf(v):-1;for(let S=0;v&&x.length>0&&x.length<jy;S++){let w=[...i];w[R]=i[R]+(v.hi-i[R])*(.4+.15*S)||v.hi;let C=performance.now();c(w),x.push(performance.now()-C)}let M=[...x].sort((S,w)=>S-w),A=M.length?M[M.length>>1]:0,F=[],T=Mr(t).map(S=>S.metricId);if(T.some(S=>S.startsWith("dyn.trim")||S==="dyn.ymdMaxAy")){let S=l.ev.ymdLimit();S?.onGridEdge&&F.push("The yaw-moment diagram peaks on the edge of its swept grid, so the trim readings are where the sweep stopped rather than where the car does. Widen the \u03B2/\u03B4 envelope before trusting them."),!S&&l.ev.dynAvailable&&F.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,w=S?Nn(S):null;w==="assumed"?F.push("This tyre carries no explicit Mz coefficient block. Its steering-aligning contribution uses Magic Formula defaults, so optimise the curve only as a qualitative placeholder until Mz is imported or fitted."):w==="none"&&F.push("This tyre model has no aligning-moment curve. Steering metrics contain contact-patch force and jacking, but not the pneumatic-trail signal that normally warns the driver at the tyre limit.")}let P=["lap.minStabil","lap.understeerFrac"];if(T.some(S=>P.includes(S))){let w=l.ev.lapReserve()?.beyondFrac;if(w!==void 0&&Number.isFinite(w)){let C=(w*100).toFixed(0);w>=CC?F.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.`):w>0&&F.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 F.push(...Fy(l.ev,Mr(t).map(S=>({m:a[S.metricId],at:S.at})).filter(S=>!!S.m))),{msPerEval:A,values:h,samples:x.length,times:x,dead:b,moves:y,unprobed:g,warnings:F,beyondFrac:T.some(S=>P.includes(S))?l.ev.lapReserve()?.beyondFrac:void 0,startFeasible:u.ok,startReason:u.reason}}var _3=[{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:N3.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 N3=["setup:m","characteristics:peak_power","characteristics:power_to_weight","characteristics:cla","characteristics:cda","characteristics:pack_energy","characteristics:maxAy","characteristics:top_speed"];var Rue=new Set(_3.map(e=>e.kind));var PC={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 tx=["FL","FR","RL","RR"],zt=(e,t,r)=>({input:e,from:r?r[0]:PC[e].from,to:r?r[1]:PC[e].to,n:t}),Sue=[{id:"sides",name:"Inside and outside",cards:[{id:"camber-roll",form:"curves",title:"Camber to the road through roll",sweep:zt("roll",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"toe-rack",form:"curves",title:"Wheel angle against the rack",sweep:zt("steer",25),wheels:["FL","FR"],y:["toe"]},{id:"camber-rack",form:"curves",title:"Camber to the road through the steer",sweep:zt("steer",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"load-roll",form:"curves",title:"Wheel loads through roll",sweep:zt("roll",25),wheels:tx,y:["wheelLoad"]},{id:"travel-roll",form:"curves",title:"Wheel travel through roll",sweep:zt("roll",25),wheels:tx,y:["travel"]},{id:"toe-roll",form:"curves",title:"Roll steer, all four",sweep:zt("roll",25),wheels:tx,y:["toe"]}]},{id:"maps",name:"Travel and steer together",cards:[{id:"camber-map",form:"surface",title:"Camber over travel and rack",sweep:zt("travel",17),second:zt("steer",13),wheels:["FL"],y:["camber"]},{id:"bump-steer-map",form:"map",title:"Bump steer over travel and rack",sweep:zt("travel",17),second:zt("steer",13),wheels:["FL"],y:["bumpSteer"]},{id:"bump-steer-family",form:"curves",title:"Bump steer through travel, at five rack positions",sweep:zt("travel",25),second:zt("steer",5,[-20,20]),wheels:["FL"],y:["bumpSteer"]},{id:"scrub-map",form:"surface",title:"Scrub radius over travel and rack",sweep:zt("travel",17),second:zt("steer",13),wheels:["FL"],y:["scrubRadius"]}]}];function rx(e){let t=Number(e);return Number.isFinite(t)?Math.min(Ih,Math.max(Eh,t)):Ut}var DC=6e4;var vme=[{within:60*6e4,every:DC},{within:1440*6e4,every:60*6e4},{within:720*60*6e4,every:1440*6e4},{within:1/0,every:10080*6e4}];var U3=new Set(["color","visible","source","origin"]),Dme=["id",...U3];var _C=.18/1.18,NC={induction:{kind:"natural"}},OC=e=>e.breathing??NC;function md(e){switch(e?.kind){case"sae-j1349":return Dc(99e3,25);case"measured":return Dc(e.hPa*100,e.tempC);default:return Dc(101325,20)}}var q3=md(void 0);function VC(e,t){let r=md(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 BC(e,t){let r=e.induction;if(r.kind==="table"){let o=s=>Ue(r.densityAltitudeM,r.powerPct,s),a=o(md(e.rated).densityAltitudeM);return a>0?Math.max(0,o(t.densityAltitudeM)/a):0}let n=e.frictionShare??_C;return Math.max(0,(VC(e,t)-n)/(1-n))}var IC=new WeakMap;function ox(e,t){let r=e.asRated??e,n=`${t.p}|${t.pDry}|${t.T}`,o=IC.get(r);o||IC.set(r,o=new Map);let a=o.get(n);if(a)return a;let s=BC(OC(r),t),i={...r,torque:r.torque.map(c=>c*s),asRated:r};return o.set(n,i),i}function eB(e){return JSON.parse(ax(sx(e,"public/laptime/index.json"),"utf8")).tracks}var tB=async e=>{let t=await fetch(e.url);if(!t.ok)throw new Error(`The track could not be read from ${kp(e)} (${t.status}).`);return new Uint8Array(await t.arrayBuffer())};function $C(e,t=new Map,r=tB){let n=eB(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(!$c(o.address))throw new Error(`"${o.address}" is not a catalogue address`);if(!Bc(o.link))throw new Error("This track is linked to a source this version does not read from.");i=await M0(await r(o.link),o.link,o.address)}else if(o.kind==="catalogue"){if(!$c(o.address))throw new Error(`"${o.address}" is not a catalogue address`);let c=JSON.parse(ax(sx(e,"public/catalogue",A0(o.address)),"utf8"));i=await F0(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(ax(sx(e,"public/laptime",c),"utf8"))}return t.set(a,i),structuredClone(i)}}var rB=9.81;function KC(e,t=e.tireModel,r=e.tireModelRear){if(!t)return e;e=nB(e,t,r);let n=e.m.value*rB/4,o=Eo(e,t,r),a=_e(o.front).rollingRadius(n),s=o.rear===o.front?a:_e(o.rear).rollingRadius(n),i=oB(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 nB(e,t,r){let n=Eo(e,t,r),o=_e(n.front).verticalStiffness(),a=n.rear===n.front?o:_e(n.rear).verticalStiffness();if(!(o>0&&a>0))return e;let s=o===a?"the fitted tyre\u2019s own vertical rate":`the fitted tyres\u2019 own vertical rates: front ${GC(o)}, rear ${GC(a)} N/mm`;return{...e,...e.tire_vertical_rate?{tire_vertical_rate:{...e.tire_vertical_rate,value:o}}:{},readouts:{...e.readouts,tire_vertical_rate:s}}}var GC=e=>Math.round(e*10)/10;function oB(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 aB=1e-6;function HC(e,t,r){let n=e.cgReference;if(!n||!e.cg_height)return e;let o=_M(e,t,r);if(o===void 0||Math.abs(o-n.standingRadius)<aB)return e;let a=n.typed??e.cg_height.value;return{...e,cg_height:{...e.cg_height,value:ts(e.cg_height.value,n.standingRadius,o)},cgReference:{...n,standingRadius:o,typed:a}}}function zC(e,t,r){let n=e.rcRoad,o=e.rc_front,a=e.rc_rear;if(!n||!o||!a)return e;let s=fm(e,t,r),i=gn(o.value,n.gainFront,n.radiusFront,s.front),c=gn(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 YC=e=>({brakeFade:e.brakeFade,airTempC:e.airTempC,diffYaw:e.diffYaw,...Ec(e.air)?{air:e.air}:{}});var aa=(e,t)=>t?e.find(r=>r.id===t)?.model:void 0;function sa(e){return{tire:t=>aa(e.tires,t),motor:t=>aa(e.motors,t),aero:t=>aa(e.aeros,t),battery:t=>aa(e.batteries,t),brake:t=>aa(e.brakes??[],t),damper:t=>aa(e.dampers??[],t),suspensionOf:t=>vs(ix(e,t),t)}}function ix(e,t){let r=aa(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 ia(e,t,r){let n={front:t.tire(e.tireModelId),rear:t.tire(e.tireModelIdRear)};return cx(CM(t.suspensionOf(e),e,n),t,r)}function sB(e){return Ec(e.air)?rw(e.air,e.airTempC??Ut):void 0}var iB="the air the session states, at its venue";function cB(e,t){return t?{...e,rho:{...e.rho,value:t.rho},readouts:{...e.readouts,rho:iB}}:e}function lB(e,t,r){if(!r)return{rho:e.rho,motorModel:t,readouts:e.readouts};let{rho:n,readouts:o}=cB(e,r);return{rho:n,motorModel:t&&pt(t)?ox(t,r):t,air:r,readouts:o}}function cx(e,t,r){let n=t.tire(e.tireModelId),o=t.tire(e.tireModelIdRear),a=zC(HC(KC(BM(NM(UM(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}=lB(a,t.motor(e.motorModelId),sB(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),...ji(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 dB=e=>e!==!1,fB=(e,t,r)=>r&&t>0?(e%t+t)%t:Math.min(Math.max(e,0),t);function hB(e,t,r){let n=e.points.filter(o=>Number.isFinite(o.at)&&Number.isFinite(o.z)).map(o=>({...o,at:fB(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 bB(e,t,r){let n=hB(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,h,f)=>i[p]+i[h]>f?f*i[p]/(i[p]+i[h]):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,d=p=>!r&&p===o-1&&o>1&&n[p].at>=t-1e-9?s(p-1):s(p);return n.map((p,h)=>{let f=l(h),b=u(h),g=Math.min(i[h],f,b),y=!r&&g<i[h]&&(h===o-1&&g===f||h===0&&g===b);return{at:p.at,z:p.z,gIn:m(h),gOut:d(h),half:g,asked:i[h],atEnd:y}})}function gB(e,t,r,n){let o=t-e.at;return n&&r>0?o-r*Math.round(o/r):o}function yB(e,t,r,n){for(let s of e){let i=gB(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 WC(e,t,r,n){let o=dB(n),a=bB(e,r,o);return a.length?t.map(s=>yB(a,s,r,o)):t.map(()=>0)}function dl(e,t){if(!t?.points.length)return e;let r=Wc(e),{zSmoothing:n,...o}=e;return{...o,z:WC(t,r,X0(e),e.closed)}}var pd={widthLeft:1.5,widthRight:1.5,bank:0,mu:1};function jC(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 fl(e,t){let r=jC(e.source);return UC(e,r?await t(r):void 0)}function UC(e,t){let{source:r}=e;if(r.kind==="segments"){let{segments:i,closed:c,spacing:l}=r,{asset:u}=Uc(i,{name:e.name,closed:c,spacing:l,base:pd});return dl(u,r.profile)}let n=r.sections??[];if(r.kind==="inline")return dl(Lp(r.asset,n,pd),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 dl(Lp({...t,...o!==void 0?{widthLeft:o}:{},...a!==void 0?{widthRight:a}:{},...s!==void 0?{closed:s}:{}},n,pd),r.profile)}var lfe=1/500;var ufe=5*Math.PI/180;var xfe=1/3;var kB=[4,2,1,.5,.25,.125];function XC(e,t,r={}){let n=[...r.steps??kB].sort((g,y)=>y-g),o=At(r.numerics),a=r.tolPct??.5,s=Xt(e),i=e.ggvMode??"twoTrack",c=Vr(s,!1,i),l={...o,dsTarget:n[0]??o.dsTarget},u=n.length?Vo(s,c,[wt(t,l)],l,i):void 0,m=Wn(s,c.rows),d=n.map((g,y)=>{let x={...o,dsTarget:g},k=Date.now(),v=wt(t,x),R=Kt(c,v,x,{...u?{load:u}:{},...m?{shifts:m}:{}});return r.onStep?.(y+1,n.length),{dsTarget:g,npts:v.npts,lapTime:R.laptime,ms:Date.now()-k}}),p=d[d.length-1]?.lapTime??NaN,h=d.map(g=>{let y=g.lapTime-p;return{...g,delta:y,deltaPct:p?100*y/p:NaN}}),f=h.filter(g=>Math.abs(g.deltaPct)<=a),b=f.length?Math.max(...f.map(g=>g.dsTarget)):null;return{points:h,reference:p,recommended:b,tolPct:a}}function Ls(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:rx(t.airTempC??r.airTempC),...Ec(dp(t.air??r.air))?{air:dp(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:At(r.numerics)}}async function dd(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 fl(r,t)}}function AB(e,t){let r=structuredClone(e);for(let[n,o]of Object.entries(t))if(!vm(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 lx=(e,t)=>{let r=e?.name;return typeof r=="string"&&r?r:t};function wB(e,t){let r={};for(let n of Xn){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:lx(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:lx(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:lx(i.model,i.id),byFallback:!0}:null;continue}r[n.doc]=null}return r}function FB(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 qC(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 QC=e=>e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`;async function fd(e,t,r={}){let n=Ls(e,r.settings),{entry:o,asset:a}=await dd(e,t),s=sa(e),i=r.vehicleIds?.length?r.vehicleIds.map(h=>{let f=e.vehicles.find(b=>b.id===h);if(!f)throw new Error(`this project holds no vehicle "${h}"`);return f}):e.vehicles.filter(h=>h.visible);if(!i.length)throw new Error("no vehicle is visible in this project \u2014 name some in vehicleIds");let c=i.map(h=>{let f=r.overrides?.[h.id]?AB(h.params,r.overrides[h.id]):h.params;return ia(structuredClone(f),s,n)}),l=wc(Ho(e.meta.rulesetId,e.rulesets)),u=Lc(c,a,n.numerics,l,{racingLine:n.racingLine,standingStart:n.standingStart,lapCounts:n.lapCounts}),m={};i.forEach((h,f)=>{m[h.id]=u[f]});let{scores:d,field:p}=e0(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:d!==null,vehicles:i.map((h,f)=>({id:h.id,name:u[f].name||String(h.params.name??h.id),events:FB(u[f]),metrics:t0(l,u[f],p?.[h.id]),fitted:wB(e,h.params),...d?.[h.id]?{score:{total:d[h.id].total,parts:{...d[h.id].parts}}}:{}})),raw:{results:m,scores:d,field:p}}}async function ZC(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=Ls(e),{asset:a}=await dd(e,t),s=ia(structuredClone(n.params),sa(e),o);return XC(s,a,{...r.steps?{steps:r.steps}:{},numerics:o.numerics,...r.tolPct!==void 0?{tolPct:r.tolPct}:{},...r.onStep?{onStep:r.onStep}:{}})}var CB=(e,t)=>e[t]??[],TB=(e,t,r)=>r<=1?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function hd(e){return e.kind==="param"?TB(e.start,e.end,Math.max(1,Math.round(e.steps))):e.kind==="part"?[...e.partIds]:[...e.values]}var JC=e=>e.kind==="param"?e.label:e.kind==="part"?`${e.part} model`:e.setting;function PB(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=ia(structuredClone(r.params),sa(e),Ls(e)),o=WM(n,{geometry:!0}),a=Rm(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=Xn.find(l=>l.doc===i.part);if(!c)throw new Error(`"${i.part}" is not a library \u2014 it is one of ${Xn.map(l=>l.doc).join(", ")}`);for(let l of i.partIds)if(!CB(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*hd(c).length,1);if(s>lp)throw new Error(`that grid is ${s} runs, over the ${lp} cap \u2014 a run is a whole session. Drop an axis or use fewer steps.`)}var LB=e=>e.map(t=>String(typeof t=="number"?Number(t.toPrecision(4)):t)).join(" \xD7 ");function DB(e,t){let r=[...new Set(e.flatMap(o=>(o.didNotFinish??[]).map(a=>a.label)))],n=e.map(o=>({name:LB(o.at),events:r.map(a=>({label:a,incomplete:o.didNotFinish?.find(s=>s.label===a)}))}));return qC(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`:QC(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 EB(e){let t=[[]];for(let r of e){let n=hd(r),o=[];for(let a of n)for(let s of t)o.push([...s,a]);t=o}return t}async function eT(e,t,r,n){PB(e,r);let o=EB(r.axes),a=[],s=!1;for(let[u,m]of o.entries()){let d=structuredClone(e),p=d.vehicles.find(k=>k.id===r.vehicleId),h={...r.settings},f={};r.axes.forEach((k,v)=>{let R=m[v];if(k.kind==="param")f[k.label]=R;else if(k.kind==="part"){let M=Xn.find(A=>A.doc===k.part);p.params[M.ref]=R}else h[k.setting]=R});let b=r.fleet?d.vehicles.filter(k=>k.visible||k.id===r.vehicleId).map(k=>k.id):[r.vehicleId],g=await fd(d,t,{vehicleIds:b,settings:h,...Object.keys(f).length?{overrides:{[r.vehicleId]:f}}:{}});s=g.fleetScored;let y=g.vehicles.find(k=>k.id===r.vehicleId),x=y.events.flatMap(k=>k.incomplete?[{label:k.label,...k.incomplete}]:[]);a.push({at:m,metrics:y.metrics,...x.length?{didNotFinish:x}:{}}),n?.(u+1,o.length)}let i=Object.keys(a[0]?.metrics??{}),c=[];r.axes.forEach((u,m)=>{if(hd(u).length<2)return;i.some(p=>{if(new Set(a.map(b=>`${b.at[m]}`)).size<2)return!1;let f=a.map(b=>b.metrics[p]).filter(Number.isFinite);return Math.max(...f)-Math.min(...f)>1e-9})||c.push(JC(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(...DB(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:JC(u),values:hd(u)})),runs:a,metricKeys:i,fleetScored:s,flat:c,caveats:l}}var Abe=Math.PI/180;var bd=.5,jB=new Set(["lap","session"]);function UB(e){return bt({...e,label:e.label.replace(/ [xyz]$/,"")})}function rT(e){let t=ea(e);if(t)return[t.point];let r=ur(e);if(r)return[r.point];let n=/^arm\.(front|rear)\.(uca|lca)\./.exec(e);if(n){let a=rr[n[2]];return[`hp.${n[1]}.${a.fore}`,`hp.${n[1]}.${a.aft}`]}let o=/^rocker\.(front|rear)\./.exec(e);return o?[`hp.${o[1]}.${zr.fore}`,`hp.${o[1]}.${zr.aft}`]:[]}function nT(e,t){let r=Ct(e,t),n=_t(e),o=new Map;for(let a of[...r.variables,...r.followers??[]])for(let s of rT(a.id)){if(o.has(s))continue;let i=Ms.map(c=>`${s}.${c}`).filter(c=>n[c]&&!n[c].supersededBy);i.length&&o.set(s,{id:s,name:UB(n[i[0]]),coords:i})}return[...o.values()]}function ux(e,t,r,n={},o=bd){let a=Ct(e,t),s=(n.metrics??Rr()).byId,i=Ps(e,a,r),c=nT(e,a),l=_t(i),u=[];a.objectives.forEach((S,w)=>{let C=s[S.metricId];C&&u.push({key:S.key??`target:${w}`,role:"target",metric:C,at:S.at})}),a.constraints.forEach((S,w)=>{let C=s[S.metricId];C&&u.push({key:S.key??`hold:${w}`,role:"hold",metric:C,at:S.at,hold:S})}),(a.watches??[]).forEach((S,w)=>{let C=s[S.metricId];C&&u.push({key:S.key??`watch:${w}`,role:"watch",metric:C,at:S.at})});let m=u.filter(S=>!jB.has(S.metric.cost)),d=S=>{let w=ld(S,a,n),C=m.map(L=>Ft(w,L.metric,L.at));return w.failure?null:C},p=d(i)??m.map(()=>NaN),h=[],f=[],b=[],g=1,y=[...p],x=[...p],k=S=>S.forEach((w,C)=>{Number.isFinite(w)&&(w>=y[C]||(y[C]=w),w<=x[C]||(x[C]=w))}),v=S=>{g++;try{return d(S())}catch{return null}};for(let S of c)for(let w of S.coords){let C=l[w],L=C.read(i),E=w.slice(w.lastIndexOf(".")+1),_=v(()=>C.write(i,L+o)),O=v(()=>C.write(i,L-o));if(!_||!O){b.push(`${S.name} ${E}`);continue}h.push({id:w,def:C,now:L,point:S,axis:E}),f.push([_,O]),k(_),k(O)}let R=new Map,M=S=>{let w=S.join("");if(R.has(w))return;let C=v(()=>h.reduce((L,E,_)=>E.def.write(L,E.now+S[_]*o),i));R.set(w,C),C&&k(C)};h.length>1&&m.forEach((S,w)=>{let C=f.map(([L,E])=>L[w]-p[w]>=E[w]-p[w]?1:-1);Number.isFinite(p[w])&&(M(C),M(C.map(L=>-L)))});let A=[...R.values()].filter(S=>!S).length;A&&b.push(`${A} of ${R.size} corners`);let F=u.map(S=>{let w={key:S.key,role:S.role,name:it(S.metric)+oa(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{...w,value:NaN,lo:NaN,hi:NaN,skipped:"read off a lap"};let L=p[C],E=Number.isFinite(L)?y[C]:NaN,_=Number.isFinite(L)?x[C]:NaN,O=f.map(([V,j])=>Math.max(Math.abs(V[C]-L),Math.abs(j[C]-L))),I=O.filter(Number.isFinite).reduce((V,j)=>V+j,0),z;if(I>0){let V=O.indexOf(Math.max(...O.filter(Number.isFinite)));z={point:h[V].point.name,axis:h[V].axis,share:O[V]/I}}let B=S.hold?Math.max(to(S.hold,E),to(S.hold,_)):void 0;return{...w,value:L,lo:E,hi:_,...z?{most:z}:{},...B!==void 0?{excess:B}:{}}}),T=new Set(c.flatMap(S=>S.coords)),P=a.variables.filter(S=>!rT(S.id).length&&!T.has(S.id)).length;return{mm:o,points:c,rows:F,evaluations:g,unsolved:b,settings:P}}function mx(e){if(!e.chassis)return e;let{chassis:t,...r}=e;return t.boxes.length?{...r,chassis:{boxes:t.boxes}}:r}var rRe=180/Math.PI;var T$={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:Ko,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 Tve=T$.id;var hl=.02;function bT(e){let t=Math.max(hl,Math.abs(e.heaveMotionRatio)),r=Math.max(hl,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 L$=(e,t)=>({od:t,id:Math.min(e.id,t-.5)}),D$=(e,t)=>e/(2*t*t);function hT(e,t){switch(e.kind){case"ubar":case"blade":case"torsionTube":return{...e,section:L$(e.section,t)};default:return e}}function gT(e,t,r){let n=Math.max(hl,Math.abs(r));if(e?.kind==="coil"){let l=D$(t,n),u=e.rate;if(typeof u=="number")return{...e,rate:l};let m=hn(u,0);if(!(m>0))return{...e,rate:l};let d=l/m;return{...e,rate:{...u,y:u.y.map(p=>p*d)}}}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=>Qi(hT(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 hT(a,c)}function yT(e,t,r,n){let o=e?.design,a=gT(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 E$=Math.PI/180,gd=1e-6;function I$(e){return!(Ee(e.rockerPivotA,e.rockerPivotB)<gd||Ee(e.rockerToPushrod,e.rockerPivotA)<gd||Ee(e.rockerToDamper,e.rockerPivotA)<gd||Ee(e.rockerToDamper,e.damperChassis)<gd)}function kT(e){if(!I$(e.hardpoints))return!1;let t={...e,config:{...e.config,actuation:"rocker"}};try{let r=gt(t);for(let n of[-20,-1,0,1,20]){let o=we(r,n,0);if(!o.ok||!Number.isFinite(o.state.metrics.damperLength))return!1}return!0}catch{return!1}}function MT(e){if(e.config.actuation!=="direct"||kT(e))return;let{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}=N$(e);return{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}}var xT=40;function yd(e,t={}){let r=e.hardpoints,n=r.pushrodOuter,o=r.damperChassis,a=Ee(n,o),s=oe(n,Q(G(o,n),_$)),i=t.armRod??Math.max(25,.15*a),c=t.armDamper??i,l=[s[0]-xT,s[1],s[2]],u=[s[0]+xT,s[1],s[2]],m=te(G(u,l)),d=G(n,s),p=te(G(d,Q(m,RT(d,m)))),h=nr(p,m,(t.armAngleDeg??60)*E$),f=oe(s,Q(h,i)),b=G(o,s),g=te(G(b,Q(m,RT(b,m)))),y=Q(te(le(m,g)),t.damperSide??1),x=oe(s,Q(y,c));return{...r,rockerPivotA:l,rockerPivotB:u,rockerToPushrod:f,rockerToDamper:x}}var _$=.72,RT=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2];function vT(e){let t=ot(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 N$(e,t={}){let r=t.target??vT(e),n=t.armAngleDeg,o=yd(e,{armAngleDeg:n});if(!(r>0))return o;let a=Ee(e.hardpoints.pushrodOuter,e.hardpoints.damperChassis),s=Math.max(25,.15*a),i=(()=>{for(let p of[1,-1]){let h=yd(e,{armRod:s,armAngleDeg:n,damperSide:p}),f={...e,config:{...e.config,actuation:"rocker"},hardpoints:h};try{let b=gt(f),g=we(b,15,0),y=we(b,-15,0);if(g.ok&&y.ok&&g.state.metrics.damperLength<y.state.metrics.damperLength)return p}catch{}}return 1})(),c=(p,h)=>{try{return vT({...e,config:{...e.config,actuation:"rocker"},hardpoints:yd(e,{armRod:p,armAngleDeg:n,armDamper:h,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,d=1/0;for(let p of l){let h=.25*p,f=6*p,b=p;for(let y=0;y<24;y++){let x=(h+f)/2,k=c(p,x);if(!Number.isFinite(k))break;b=x,k<r?h=x:f=x}let g=Math.abs(c(p,b)-r);if(Number.isFinite(g)&&g<d&&(d=g,u=p,m=b),d<1e-4*Math.max(1,r))break}return yd(e,{armRod:u,armAngleDeg:n,armDamper:m,damperSide:i})}var Hve=Array.from({length:19},(e,t)=>-45+5*t);var zve=Math.PI/180;function O$(e){let t=e.hardpoints,r=te(G(t.rockerPivotB,t.rockerPivotA)),n=Dn(t.rockerToDamper,t.rockerPivotA,r),o=.6*Ln(G(t.rockerToDamper,n)),a=le(r,fR),s=Ln(a)>1e-6?te(a):te(G(t.rockerToDamper,n));return{outer:oe(n,Q(s,o)),inner:oe(n,Q(s,-o)),attach:"rocker"}}var V$=(e,t)=>({...e,config:{...e.config,actuation:t}});function fx(e,t,r,n){let o=r==="front"?e.front:e.rear,a=lm(o),s=o.config.springRate*a*a,i=re(t,r==="front"?"damper_front":"damper_rear")*a*a,c=r==="front"?t.arbFrontDesign:t.arbRearDesign,l=To(e,t)[r]??re(t,r==="front"?"arb_front":"arb_rear"),u=es(e,t)[r]??re(t,r==="front"?"heave_spring_front":"heave_spring_rear"),m=MT(o),d=V$(m?{...o,hardpoints:{...o.hardpoints,...m}}:o,"decoupled"),p=r==="front"?t.heaveFrontDesign:t.heaveRearDesign,h=n?.heave??ST(p?.linkage,F=>co(d,F).atDesign)??Tf(d,"rockerToRocker"),f=!c||c.design.kind==="none"||c.design.kind==="coil",b=f?"coil":"ubar",g=c?.linkage&&(c.design.kind==="none"||c.linkage.attach!=="rocker")?c.linkage:void 0,y=n?.roll??ST(f?g:c?.linkage,F=>Aa(d,F,{kind:b}).atDesign)??(f?O$(d):mM(d)),x=co(d,h).atDesign,k=Aa(d,y,{kind:b}).atDesign,v=mm(e,t),R=bT({cornerWheelRate:s,cornerDamper:i,arbWheelRate:l,heaveWheelRate:u,heaveWheelDamping:r==="front"?v.heaveFront:v.heaveRear,rollWheelDamping:r==="front"?v.rollFront:v.rollRear,heaveMotionRatio:x,rollMotionRatio:k}),M=!c||c.design.kind==="none"?{design:{kind:"coil",rate:1},linkage:y}:{...c,linkage:y},A=yT({design:p?.design??{kind:"none"},linkage:h,damper:p?.damper},M,R,k);return m?{...A,crank:m}:A}function ST(e,t){return e&&Math.abs(t(e))>=hl?e:void 0}var xd=[{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"]}],hx=()=>({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]}},$$={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]}},G$=()=>({outer:[0,189,486],attach:"rocker",mount:{kind:"chassis",anchor:[-225,0,486]}}),K$={rate:60,motionRatio:1},H$={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]}},z$=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]}},Y$={kind:"coil",rate:1560,motionRatio:1,gap:0,bothWays:!0},W$=40,j$={rockerPivotA:[50,130,440],rockerPivotB:[-50,130,440],rockerToPushrod:[10,170,460],rockerToDamper:[-20,64,440],damperChassis:[-20,64,215]},AT=()=>({outer:[-50,130,480],attach:"rocker",shaftStation:-50}),wT=()=>({outer:[50,130,400],inner:[50,130,480],attach:"rocker",shaftStationOuter:50,shaftStationInner:50}),U$=e=>[e[0],e[1],e[2]];function X$(e){let t=r=>({...r,hardpoints:{...r.hardpoints,...CT(j$)},config:{...r.config,actuation:"decoupled"}});return{...e,front:t(e.front),rear:t(e.rear)}}function CT(e){return Object.fromEntries(Object.entries(e).map(([t,r])=>[t,U$(r)]))}function TT(e,t=Uo(),r=e==="pull"?$$:B$){let n=(o,a)=>({...o,hardpoints:{...o.hardpoints,...CT(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=bx(e),n=Ds(e);if(e==="heave")return{meta:r,vehicle:n,components:{...hx(),heaveFront:{design:{...zb,...K$},linkage:G$()}}};if(e!=="decoupled")return{meta:r,vehicle:n,components:hx()};let o=fx(n,t,"front",{heave:AT(),roll:wT()}),a=fx(n,t,"rear",{heave:AT(),roll:wT()});return{meta:r,vehicle:n,components:{arbFront:o.arb,arbRear:a.arb,heaveFront:o.heave,heaveRear:a.heave}}}function Ds(e){let{name:t}=bx(e);if(e==="direct")return{..._c(),name:t};if(e==="mcpherson"){let n=Nc(),o=hp();return{...n,front:{...o,config:{...o.config,loadedRadius:n.front.config.loadedRadius}},name:t}}let r=q$(TT(e==="pullrod"?"pull":"push"));return{...e==="decoupled"?X$(r):r,name:t}}var FT={front:221.7,rear:220.9};function q$(e){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:FT.front}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:FT.rear}}}}function bx(e){let t=xd.find(r=>r.id===e);if(!t)throw new Error(`Unknown suspension template: ${e}`);return t}function vd(){let e=t=>({design:{...Y$},linkage:z$(t),damper:W$});return{meta:bx("heave"),vehicle:TT("push",c0(),H$),components:{...hx(),heaveFront:e("front"),heaveRear:e("rear")}}}var PT=[10,25,50,100,200,300],Q$=[{id:"c1",label:"Soft",scale:.7},{id:"c2",label:"Medium",scale:1},{id:"c3",label:"Firm",scale:1.4}],LT=e=>Math.round(e*100)/100;function Z$(e,t,r){let n=PT.map(o=>LT(r*o));return{id:e,label:t,speedMmS:[...PT],bumpN:n,reboundN:[...n]}}function J$(e){return{name:e.name,body:{...e.body},curves:Q$.map(t=>Z$(t.id,t.label,LT(e.coefficient*t.scale)))}}function bl(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 Yr(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:Kc[e.dampers.length%Kc.length],model:J$(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 Tt=e=>`${e} (typical)`,gx={car:{name:Tt("Formula Student damper"),coefficient:2.5,body:{extended:249,stroke:55}}},kd={car:gx.car,heave:{name:Tt("Formula Student heave damper"),coefficient:3.4,body:{extended:270,stroke:47}},roll:{name:Tt("Formula Student roll damper"),coefficient:3.7,body:{extended:322,stroke:100}}},Md={car:{name:Tt("Formula 1 damper"),coefficient:6,body:{extended:240,stroke:40}},heave:{name:Tt("Formula 1 heave damper"),coefficient:40,body:{extended:240,stroke:40}}},DT={car:{name:Tt("GT damper"),coefficient:4.5,body:{extended:510,stroke:80}}},yx={car:{name:Tt("Sports car damper"),coefficient:2.4,body:{extended:515,stroke:110}}},ET={car:{name:Tt("Sports car strut"),coefficient:2.4,body:{extended:310,stroke:120}},rear:yx.car},IT={car:{name:Tt("Cup car strut"),coefficient:4,body:{extended:285,stroke:75}},rear:{name:Tt("Cup car rear damper"),coefficient:3.5,body:{extended:505,stroke:80}}},_T={car:{name:Tt("Stock car front damper"),coefficient:7.5,body:{extended:555,stroke:110}},rear:{name:Tt("Stock car rear damper"),coefficient:6.75,body:{extended:555,stroke:110}}},NT={car:{name:Tt("Hill-climb front damper"),coefficient:3,body:{extended:285,stroke:65}},rear:{name:Tt("Hill-climb rear damper"),coefficient:3.5,body:{extended:285,stroke:65}}},OT={car:{name:Tt("Race truck front damper"),coefficient:12,body:{extended:780,stroke:160}},rear:{name:Tt("Race truck rear damper"),coefficient:8.5,body:{extended:780,stroke:160}}};function Is(e){return e.vehicles=e.vehicles.slice(0,1),e.activeVehicleId=e.vehicles[0]?.id??null,e}function ro(e,t){let r=Hc(e);return r.meta.rulesetId=t,r}function ca(e,t,r,n){let o=ro(e,t);return o.suspensions=[{...o.suspensions[0],model:n()}],o.vehicles=[I0(r,"v1",0)],o.activeVehicleId="v1",o}var[,eG,tG,rG,nG,oG,aG,sG]=b0;function xx(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 VT(){return{...Ds("decoupled"),name:Uo().name}}var iG=[{label:"Formula Student (decoupled)",vehicle:VT,components:e=>bl(Rd("decoupled",e).components,kd)},{label:"Formula 1 (third springs)",vehicle:()=>vd().vehicle,components:()=>bl(vd().components,Md)}],Rx={"direct-coilover":"direct",pushrod:"pushrod",pullrod:"pullrod","third-spring":"heave","mcpherson-strut":"mcpherson"},cG=[...iG.map(e=>e.vehicle),...Object.values(Rx).map(e=>()=>Ds(e))];function Es(e){let t=bl(Rd("decoupled",e.vehicles[0].params).components,kd);e.suspensions=[{...e.suspensions[0],model:VT()}];for(let r of e.vehicles)xx(r.params,t);return Yr(e,kd),e}var la={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"},BT={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]"},$T={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"},lG={id:"cota",name:"Circuit of the Americas, Austin",address:"e0c6ea889d708cf15f9c",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[la,Sd,$T]}},uG={id:"laguna-seca",name:"Laguna Seca, Monterey",address:"185b5811b9c423ef44ef",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[la,Sd,$T]}},mG={id:"nordschleife",name:"Nordschleife, N\xFCrburg",address:"74c49603c7b2f15985c6",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[la,BT]}},pG={id:"brands-hatch",name:"Brands Hatch, Kent",address:"c4953e3c25eaba4a5b7e",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[la,{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."}]}},dG={id:"bristol",name:"Bristol, Tennessee",address:"f0e23953669a414ad600",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[la,Sd]}},fG={id:"pikes-peak",name:"Pikes Peak, Colorado",address:"3de137fe33b5c2875036",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[la,Sd]},standingStart:!0},hG={source:"venue",altitudeM:3580,pressure:{kind:"standard"},humidityPct:0},bG=10,gG={id:"nurburg-sprint",name:"Sprintstrecke, N\xFCrburg",address:"1875636cdbb615aa2756",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[la,BT]}};function ua(e,t){let{id:r,name:n,address:o,provenance:a,standingStart:s}=t,i={kind:"catalogue",id:r,address:o},c=Oc(w0({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 no(e,t,r){let n=e.vehicles[0].params,o=`m${e.motors.length+1}`;e.motors=[...e.motors,{id:o,color:qn[e.motors.length%qn.length],model:t}];let a=DM({},{...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 yG=3.8,Ad={hubPlanetary:14.5,inboardChain:4,engineChain:3.4},xG="Hub motor, 35 kW (example)";function vx(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 GT(e){let t=e.motors.find(r=>r.id==="m1");return t.model={...t.model,name:xG},t.id}function wd(e,t,r){let n=Is(Es(ro(e,r)));return n.vehicles[0].params.name=t,n}function RG(){let e=wd("Formula Student combustion car","Formula Student combustion","fs-cv");no(e,v0(),Ad.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 vG(){let e=wd("Formula Student AWD car","Formula Student AWD","fs-ev");return vx(e,GT(e),4,"awd",Ad.hubPlanetary,"hub"),e}function kG(){let e=wd("Formula Student RWD hub-motor car","Formula Student RWD hub motors","fs-ev");return vx(e,GT(e),2,"rear",Ad.hubPlanetary,"hub"),e}function MG(){let e=wd("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:qn[e.motors.length%qn.length],model:R0()}],vx(e,t,1,"rear",Ad.inboardChain),e.vehicles[0].params.driveline={rear:structuredClone(Gt.clutch)},e}function SG(){let e=Is(Es(ro("Formula Student endurance energy","fs-ev"))),t=e.vehicles[0],r=structuredClone(t);if(r.id="v2",r.color=Gc[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 AG(){let e=vd(),t=ca("Formula 1 car","trackday",eG,()=>e.vehicle);return xx(t.vehicles[0].params,bl(e.components,Md)),Yr(t,Md),no(t,k0(),yG),ua(t,lG)}function KT(e="GT car",t=_c){let r=ca(e,"trackday",tG,t);return Yr(r,DT),no(r,bw(),r.vehicles[0].params.gear_ratio.value),ua(r,uG)}function HT(e="Sports car",t=Nc,r=yx){let n=ca(e,"trackday",rG,t);return Yr(n,r),no(n,gw(),n.vehicles[0].params.gear_ratio.value),ua(n,mG)}function wG(){let e=ca("Cup car","trackday",nG,ow);return Yr(e,IT),no(e,yw(),e.vehicles[0].params.gear_ratio.value),ua(e,pG)}function FG(){let e=ca("Stock car","trackday",oG,aw);return Yr(e,_T),no(e,xw(),e.vehicles[0].params.gear_ratio.value),ua(e,dG)}function CG(){let e=ca("Hill-climb prototype","trackday",aG,sw);return Yr(e,NT),no(e,Rw(),e.vehicles[0].params.gear_ratio.value),e.settings.air=structuredClone(hG),e.settings.airTempC=bG,ua(e,fG)}function TG(){let e=ca("Race truck","trackday",sG,iw);return Yr(e,OT),no(e,vw(),e.vehicles[0].params.gear_ratio.value),ua(e,gG)}function PG(e){let t=xd.find(o=>o.id===e);if(e==="direct")return KT(t.name,()=>Ds(e));if(e==="mcpherson")return HT(t.name,()=>Ds(e),ET);let r=Is(ro(t.name,"trackday")),n=Rd(e,r.vehicles[0].params);return r.suspensions=[{...r.suspensions[0],model:n.vehicle}],xx(r.vehicles[0].params,n.components),Yr(r,gx),r}function gl(e,t,r){let n=Rx[e],o=xd.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:()=>PG(n)}}var LG=[{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:()=>Es(ro("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:SG},{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:()=>Is(Es(ro("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:RG},{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:vG},{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:kG},{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:MG},{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:AG},{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:KT},{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:HT},{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:wG},{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:FG},{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:CG},{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:TG},{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:()=>Is(Es(ro("Suspension study","trackday")))},gl("direct-coilover","The GT car\u2019s wishbones driving coilovers straight into the towers, at Laguna Seca.","On the GT car, at Laguna Seca."),gl("pushrod","The FS car on pushrods: a rod from each lower wishbone works a rocker.","On the Formula Student car, at FSG."),gl("pullrod","The FS car on pullrods: a rod from each upper wishbone pulls a low rocker.","On the Formula Student car, at FSG."),gl("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."),gl("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:()=>Is(Es(ro("Tyre study","fs-ev")))}],zT=LG.map(e=>({...e,load:()=>_0(e.load())}));var YT={width:320,height:200},C1e=[.6*YT.width-9,.6*YT.height-9];var WT=new WeakMap,jT=new WeakMap,kx=e=>JSON.stringify(e,(t,r)=>r===1/0?"Infinity":r);function UT(e,t){if(!t){let a=WT.get(e);return a||(a=Jt(e),WT.set(e,a)),a}let r=jT.get(e);r||(r=new Map,jT.set(e,r));let n=kx(t),o=r.get(n);return o||(r.size>=4&&r.clear(),o=Jt(e,t),r.set(n,o)),o}var IG=Math.PI/180,_G=e=>e>1?e/100:e;function yl(e){let t=null;return()=>(t??={v:e()}).v}function XT(e){let t=ot(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 qT=new WeakMap,Mx={heave:0,pitch:0,roll:0,steer:0},QT=[0,1,2,3,4],ZT=[-20,-10,0,10,20];function eP(e,t){let r=bn(e,Mx),n=["front","rear"],o=c=>{let l=Ji(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 QT){let l=c===0?null:bn(e,{...Mx,roll:c*IG});n.forEach((u,m)=>{let d=l?Ji(l[u]):null,p=d&&Number.isFinite(a[m]);s[m].rc.push(p?t[m]+(d.left+d.right)/2-a[m]:t[m]),s[m].split.push(p?(d.left-d.right)/2:0)})}let i=n.map(()=>[]);for(let c of ZT){let l=c===0?null:bn(e,{...Mx,heave:-c});n.forEach((u,m)=>{let d=l&&l[u].valid&&r[u].valid;i[m].push(d?t[m]+l[u].height-r[u].height:t[m])})}return{roll:{rollDeg:QT,rcFront:s[0].rc,rcRear:s[1].rc,rcSplitFront:s[0].split,rcSplitRear:s[1].split},heave:{drop:ZT,rcFront:i[0],rcRear:i[1]}}}var JT=new WeakMap;function NG(e,t,r,n){let o=JT.get(e);o||(o=new Map,JT.set(e,o));let a=`${kx(r)}|${n[0]}|${n[1]}`,s=o.get(a);if(!s){o.size>=4&&o.clear();try{s=eP(UT(e,r),n)}catch{s=t.rigidMigration(n)}o.set(a,s)}return s}function OG(e){let t=qT.get(e);if(t)return t;let r=Jt(e),n=bn(r,{heave:0,pitch:0,roll:0,steer:0}),o=XT(e.front),a=XT(e.rear),s={wheelbase:e.config.wheelbase,trackFront:Ot(e.front),trackRear:Ot(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:Ja(n.front),rcGainRear:Ja(n.rear),rigidMigration:i=>eP(r,i),kinFront:yl(()=>Na(e.front)),kinRear:yl(()=>Na(e.rear))};return qT.set(e,s),s}function tP(e,t,r,n){let o=OG(e),a=To(e,t),s=es(e,t),i=AM(e,t),c=mm(e,t),l=wM(e,t),u=FM(t),m=pm(e,t),d=Co(e.front),p=Co(e.rear),h=Fo(t.damperModel,t.damperSetup,o.mrFront,o.mrRear,t.damperModelRear??t.damperModel),f={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,re(t,"cop_long"))),copHeight:re(t,"cop_height"),...t.aeroModel?{model:t.aeroModel}:{},rideHeightFront:re(t,"ride_height_front"),rideHeightRear:re(t,"ride_height_rear")},b=9.81,g=_G(t.front_mass_diss.value),y=Eo(t,r,n),x=_e(y.front),k=y.rear===y.front?x:_e(y.rear),v=n??t.tireModelRear??r,R=t.m.value*b*g/2,M=t.m.value*b*(1-g)/2,A=x.corneringStiffness(R),F=k.corneringStiffness(M),T=(r?x.verticalStiffness():0)||re(t,"tire_vertical_rate"),P=(v?k.verticalStiffness():0)||re(t,"tire_vertical_rate"),S=Pr(r)??0,w=Pr(v)??0,C=gm({freeRadius:S,staticLoad:R,tyreRate:T,surveyed:e.front.config.loadedRadius},{freeRadius:w,staticLoad:M,tyreRate:P,surveyed:e.rear.config.loadedRadius},g),L=cr(S,R,T,e.front.config.loadedRadius),E=cr(w,M,P,e.rear.config.loadedRadius),_=[gn(o.rcHeightFront,o.rcGainFront,e.front.config.loadedRadius,L),gn(o.rcHeightRear,o.rcGainRear,e.rear.config.loadedRadius,E)],O=yl(()=>nc(o.kinFront(),re(t,"camber_front_deg"))),I=yl(()=>nc(o.kinRear(),re(t,"camber_rear_deg"))),z=yl(()=>NG(e,o,ks(j),_)),B=Di({...t,wheelbase:{...t.wheelbase,value:o.wheelbase}}),V=rc(t),j={massTotal:t.m.value,frontMassFrac:g,steeringSystem:t.steeringSystem,tv:Qu(t),cgHeight:ts(re(t,"cg_height"),t.cgReference?.standingRadius,C),cgStandingRadius:C,wheelbase:o.wheelbase,trackFront:o.trackFront,trackRear:o.trackRear,wheelRateFront:d?0:o.wheelRateFront,wheelRateRear:p?0:o.wheelRateRear,decoupledFront:d,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&&!d?{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:re(t,"tire_vertical_damping"),arbFront:a.front??re(t,"arb_front"),arbRear:a.rear??re(t,"arb_rear"),brakeBalanceFront:B.balanceFront,brakes:B,...V?{driveline:V}:{},heaveSpringFront:s.front??re(t,"heave_spring_front"),heaveSpringRear:s.rear??re(t,"heave_spring_rear"),unsprungPerCorner:re(t,"unsprung_mass"),unsprungCgHeight:cr(S,R,T,o.unsprungCgHeight),tyreFreeRadius:S,...w!==S?{tyreFreeRadiusRear:w}:{},rcHeightFront:_[0],rcHeightRear:_[1],corneringStiffnessFront:A,corneringStiffnessRear:F,get kinFront(){return O()},get kinRear(){return I()},damperFront:d?0:h?.front?.rate??re(t,"damper_front")*o.mrFront*o.mrFront,damperRear:p?0:h?.rear?.rate??re(t,"damper_rear")*o.mrRear*o.mrRear,...h?.front&&!d?{damperCurveFront:h.front.curve}:{},...h?.rear&&!p?{damperCurveRear:h.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:re(t,"unsprung_mass"),get rollCentreCurve(){return z().roll},get rcHeaveCurve(){return z().heave},aero:f,yawInertia:re(t,"I_yaw"),rollInertia:re(t,"I_roll"),pitchInertia:re(t,"I_pitch"),get steerFront(){return dm(e.front,L)},ackermannPct:re(t,"ackermann_pct"),toeFrontDeg:re(t,"toe_front_deg"),toeRearDeg:re(t,"toe_rear_deg")};return j}var nP=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"},rP=new WeakMap;function wx(e,t=Ax){let r=rP.get(e.vehicle);r||rP.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={...nP(e.params),suspensionOf:()=>e.vehicle};n.set(o,a=ia(e.params,s,t))}return a}var oP=(e=Ax)=>t=>wx(t,e),aP=(e=Ax)=>t=>tP(t.vehicle,cx(t.params,nP(t.params),e),t.params.tireModel,t.params.tireModelRear);function VG(e,t){return wx(e,t.switches)}var Fx=e=>Rr(e?.rulesets);function sP(e,t,r,n,o={},a=()=>r.standingStart){let s=wx(n,r.switches),i=(l,u)=>{let m=cp(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 iP=e=>[...new Set(e.lap.courses.flatMap(t=>t.course.kind==="track"?[t.course.trackId]:[]))],cP=e=>{let t=e?.session;return t?{sessionParams:r=>VG(r,t),session:()=>t}:{}},Rl=e=>({metrics:Fx(e),assemble:aP(e?.switches),simParams:oP(e?.switches),projectTrack:()=>e?.course??null,libraryTrack:t=>e?.tracks?.[t]??null,numerics:e?.numerics,...cP(e)}),BG=(e,t)=>({density:e.density,envelope:e.envelope,states:e.states,operating:e.operating,lap:e.lap,assemble:aP(t?.switches),simParams:oP(t?.switches),projectTrack:()=>t?.course??null,libraryTrack:r=>t?.tracks?.[r]??null,numerics:t?.numerics,...cP(t)}),lP="nelder-mead",uP=600,xl=[0,.15,.15];function mP(e,t,r,n=xl.length){let o=Px(t);return xl.slice(0,Math.max(1,n)).map((a,s)=>({...e,seed:s+1,startJitter:a,car:o,...r?{lap:r}:{}}))}function pP(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 dP(e,t,r,n,o=.01){let a=Fx(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=Zn(Ps(e,t,r),BG(t,n))}catch{return[]}return GG(o,t,Fx(n))}function GG(e,t,r){let n=[];for(let o of t.constraints){let a=r.byId[o.metricId];if(!a)continue;let s=Ft(e,a,o.at);if(!Number.isFinite(s))continue;let i=`${it(a)}${oa(o.at,a)}`;n.push({key:o.key,metricId:o.metricId,label:i,unit:a.unit==="-"?"":a.unit,value:s,excess:to(o,s)})}return n}var KG=.05;function HG(e,t){if(t.id.startsWith("hp.")||sd(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 By(eo(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 Ny(An(o.hardpoints,n[2]),n[3],1)}function fP(e,t,r){let n=r.filter(d=>d.score.feasible);if(n.length<2)return null;let o=t.map(d=>HG(e,d)),a=o.every(d=>d!==null)?"mm":null,s=0,i="",c=0,l=n.reduce((d,p)=>p.score.total<d.score.total?p:d);for(let d of n)if(d!==l)for(let p=0;p<t.length;p++){let h=Math.abs(d.x[p]-l.x[p])*(o[p]??1);c+=h*h,h>s&&(s=h,i=t[p].name)}let u=n.map(d=>d.score.total),m=l.score.terms.reduce((d,p)=>d+(p.resolution??0),0);return{distance:Math.sqrt(c),worst:s,worstName:i,scoreSpread:Math.max(...u)-Math.min(...u),tolerance:Math.max(KG,m),unit:a}}var zG={steeringSystem:!0,brakeSetup:!0,driveline:!0,heaveFrontDesign:!0,heaveRearDesign:!0,arbFrontDesign:!0,arbRearDesign:!0},hP=e=>Object.hasOwn(zG,e);function Sx(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 YG(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":hP(t)||Sx(e)?"block":null}function Cx(e,t){t=Ct(e,t);let r=_t(e);return[...t.variables,...t.followers??[]].filter(n=>r[n.id]&&!r[n.id].supersededBy&&!YG(n.id)).map(n=>bt(r[n.id]))}function bP(e,t,r){t=Ct(e,t);let n=_t(e),o=Ps(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,d,p,h]=c.id.split(".");if(m==="rocker"){let f=`${d}.rocker`;if(i.has(f))continue;i.add(f);let b=d==="front"?o.vehicle.front:o.vehicle.rear;for(let g of[zr.fore,zr.aft]){let y=b.hardpoints[g];for(let x=0;x<3;x++)a.push({kind:"hardpoint",axle:d,key:g,axis:x,value:y[x]})}}else if(m==="arm"){let f=`${d}.${p}`;if(i.has(f))continue;i.add(f);let b=d==="front"?o.vehicle.front:o.vehicle.rear,g=rr[p];for(let y of[g.fore,g.aft]){let x=b.hardpoints[y];for(let k=0;k<3;k++)a.push({kind:"hardpoint",axle:d,key:y,axis:k,value:x[k]})}}else if(m==="hp"&&ur(c.id)){let f=`${d}.${p}`;if(i.has(f))continue;i.add(f);let b=(d==="front"?o.vehicle.front:o.vehicle.rear).hardpoints[p];for(let g=0;g<3;g++)a.push({kind:"hardpoint",axle:d,key:p,axis:g,value:b[g]})}else if(m==="hp")a.push({kind:"hardpoint",axle:d,key:p,axis:"xyz".indexOf(h),value:u});else if(m==="cfg")a.push({kind:"config",axle:d,field:p,value:u});else if(m==="kc"){if(s.has(`kc.${d}`))continue;s.add(`kc.${d}`);let f=d==="front"?o.vehicle.front:o.vehicle.rear;a.push({kind:"compliance",axle:d,value:f.compliance})}else if(m==="param")a.push({kind:"param",label:bt(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(hP(m)||Sx(c.id)){let f=Sx(c.id)??m;if(s.has(f))continue;s.add(f);let b=o.params[f];if(!b)throw new Error(`optimiser: "${c.id}" left the car with no ${f} to adopt`);a.push({kind:"block",key:f,value:b})}else throw new Error(`optimiser: Adopt has no way to write "${c.id}" back into the project`)}return a}function Tx(e){let t=performance.now(),r=Rl(e.lap),n=e.follow?qy(e.car,e.spec,r):e.spec,{dead:o,unprobed:a,...s}=ex(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 gP(e){let t=performance.now();return{tolerance:ux(e.car,e.spec,e.x,Rl(e.lap),e.mm),elapsedMs:performance.now()-t}}var Px=e=>e.vehicle.chassis?{...e,vehicle:mx(e.vehicle)}:e;function yP(e,t){try{let r=Lx(e.car,e.spec,e.lap),n=Ba.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:rn(r.variables),score:tn(r,rn(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&&Hy(r.variables)?Yy(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)=>ud(e,t,Rl(r));function xP(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),...ji(e,t.damper)}}function RP(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 vP=e=>({ggvMode:e.ggvMode,quasiTransient:e.quasiTransient===!0&&e.ggvMode!=="fast",motorThermal:e.motorThermal===!0,...YC({brakeFade:e.brakeFade===!0,airTempC:e.airTempC,diffYaw:e.diffYaw===!0,...e.air?{air:e.air}:{}})});function WG(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 kP(e,t){let r=t.plannedPath!==void 0,n=WG(t);return{...sP(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 Dx(e,t){let r=e.vehicles.find(o=>o.id===t);if(!r)throw new Error(`this project holds no vehicle "${t}"`);let n=sa(e);return RP(structuredClone(ix(e,r.params)),structuredClone(r.params),xP(r.params,n))}var jG="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 Ex(e,t,r,n){if(e.settings.pathPlanId)throw new Error(jG);let o=Ls(e),a=e.tracks.length?(await dd(e,t)).asset:null,s={};for(let i of n?iP(n):[]){let c=e.tracks.find(l=>l.id===i);c&&(s[i]=await fl(c,t))}return kP(r,{track:a,numerics:o.numerics,racingLine:o.racingLine,standingStart:o.standingStart,lapCounts:o.lapCounts??{},switches:vP(o),rulesets:e.rulesets??[],library:s,standingOf:i=>e.tracks.find(c=>c.id===i)?.standingStart===!0})}async function MP(e,t,r,n){let o=Dx(e,r),a=Ct(o,n),s=await Ex(e,t,o,a);return Tx({id:0,car:o,spec:a,lap:s})}async function SP(e,t,r,n){let o=Dx(e,r),a=Ct(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 Ex(e,t,o,a)}catch(l){return{problems:[l instanceof Error?l.message:String(l)]}}let c=Jy(o,a,{...Rl(i),metrics:Rr(e.rulesets)});return c.length?{problems:c}:{problems:[],msPerEval:Tx({id:0,car:o,spec:a,lap:i}).msPerEval,carFingerprint:Go(Px(o))}}async function UG(e,t,r,n,o,a=[]){let s=mP(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 d=[],p=null,h=null;if(yP(m,y=>{y.kind==="progress"?(d.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}:h=y.message}),h)throw new Error(h);if(!p)throw new Error("the search stopped without a result");let{result:f,elapsedMs:b}=p,g={seed:m.seed,startJitter:m.startJitter,x:f.x,score:f.score,evaluations:f.evaluations,infeasible:f.infeasible,history:f.history,trace:d,elapsedMs:b,...f.snapped?{snapped:f.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 AP(e,t,r,n){let o=Dx(e,r.vehicleId),a=Ct(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 Ex(e,t,o,a),c=r.method??lP;if(!Ba.some(x=>x.name===c))throw new Error(`unknown method "${c}" \u2014 it is one of ${Ba.map(x=>x.name).join(", ")}`);let l=r.budget??uP,u=Math.max(1,Math.min(r.seeds??xl.length,xl.length)),m=await UG(o,{spec:a,method:c,budget:l},i,u,n),d=Lx(o,a,i),p=m.runs.map(x=>({seed:x.seed,startScore:m.designScore.total,score:x.score.total,feasible:x.score.feasible,...x.score.reason?{reason:x.score.reason}:{},terms:x.score.terms,x:x.x,evaluations:x.evaluations,infeasible:x.infeasible,bounds:pP(d.variables,x.x),constraints:dP(o,a,x.x,i),...x.snapped?{onSteps:{x:x.snapped.x,score:x.snapped.score.total,feasible:x.snapped.score.feasible,...x.snapped.score.reason?{reason:x.snapped.score.reason}:{},terms:x.snapped.score.terms}}:{}})),h=m.runs.reduce((x,k)=>Ri(k.score,x.score)?k:x),f=h.snapped?.score.feasible?h.snapped:null,b=f?f.x:h.x,g=r.tolerance??bd,y=h.score.feasible&&g>0?gP({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?fP(o,d.variables,m.runs.map(x=>({x:x.x,score:x.score}))):null,writes:bP(o,a,b),...h.snapped?{adopts:f?"on its steps":`as found: on its steps it breaks a hold (${h.snapped.score.reason??"not legal"})`}:{},...y?{asBuilt:y}:{}}}function FP(){if(typeof process.threadCpuUsage!="function")return performance.now();let e=process.threadCpuUsage();return(e.user+e.system)/1e3}async function qG(e,t){let r=$C(e.root);switch(e.kind){case"sweep":return eT(e.doc,r,e.req,t);case"convergence":return ZC(e.doc,r,{vehicleId:e.vehicleId,...e.steps?{steps:e.steps}:{},...e.tolPct!==void 0?{tolPct:e.tolPct}:{},onStep:t});case"study":return AP(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 fd(e.doc,r,{...e.vehicleIds?{vehicleIds:e.vehicleIds}:{},...e.settings?{settings:e.settings}:{},...e.overrides?{overrides:e.overrides}:{}});case"probe":return MP(e.doc,r,e.vehicleId,e.spec);case"quote":return SP(e.doc,r,e.vehicleId,e.spec)}}if(wP){let e=wP,t=r=>e.postMessage(r);(async()=>{try{let r=await qG(XG,(n,o)=>t({type:"progress",done:n,total:o}));t({type:"done",result:r,cpuMs:FP()})}catch(r){t({type:"failed",message:r instanceof Error?r.message:String(r),cpuMs:FP()})}})()}export{qG as runJob,FP as threadCpuMs};
|
|
226
|
+
`)),this.name="RulesetDefError",this.problems=r}},Sc=e=>typeof e=="number"&&Number.isFinite(e),Mc=e=>Sc(e)&&e>0,tr=(e,t)=>e===void 0||t(e);function XN(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":Mc(a.distance)||r(`${s} needs a distance above zero, in metres`),tr(a.vStart,i=>Sc(i)&&i>=0)||r(`${s}'s entry speed must be zero or more`);break;case"constantRadius":Mc(a.radius)||r(`${s} needs a radius above zero, in metres`),tr(a.laps,i=>Sc(i)&&i>=1)||r(`${s} runs at least one lap`);break;case"trackLap":tr(a.laps,i=>Sc(i)&&i>=1)||r(`${s} runs at least one lap`),tr(a.distance,Mc)||r(`${s}'s distance must be above zero, in metres`),tr(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),tr(a.unit,i=>typeof i=="string")||r("Its unit is text",s),tr(a.over,i=>typeof i=="string")||r("Names its event by id",s),tr(a.format,i=>i==="time"||i==="points")||r("Is shown as a time, as points, or as a number",s),tr(a.max,Sc)||r("Its maximum is a number",s),tr(a.lowerBetter,i=>typeof i=="boolean")||r("Lower is better, or it is not",s),tr(a.hidden,i=>typeof i=="boolean")||r("Is hidden, or it is not",s)}tr(e.track?.minTurnRadius,Mc)||r("The tightest turn the rules allow is a radius above zero");let n=e.battery;for(let o of["packVoltageMax","segmentVoltageMax","powerLimitKw"])tr(n?.[o],Mc)||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 VA(e){let t=XN(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}=Qm(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 Jm(e){return VA(e).problems}var Gg=e=>Number.isFinite(e)?e:NaN;function qN(e){return e.unit&&e.format!=="time"?`${e.label} (${e.unit})`:e.label}function jn(e){let t=structuredClone(e),{plan:r,problems:n}=VA(t);if(!r)throw new Zm(t.id,n);let o=new WeakMap,a=p=>{let h=o.get(p);return h||(h=$g(r,p),o.set(p,h)),h},s=new Map(t.kpis.map(p=>[p.key,p])),i=new Map;for(let[p,h]of Object.entries(t.score?.parts??{}))i.has(h)||i.set(h,p);let c=p=>(h,f)=>{if(!f)return NaN;let b=f.kpis?.[p];if(b!==void 0)return Gg(b);let g=f,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 h=r.field.has(p.key);return{key:p.key,label:qN(p),lowerBetter:p.lowerBetter??!1,...p.format?{format:p.format}:{},...h?{field:!0}:{},value:h?c(p.key):f=>a(f)[p.key]}}),u=t.score,m=u?p=>{let h=kc(r,p),f={};for(let[b,g]of Object.entries(h)){let y={},x={};for(let[k,v]of Object.entries(u.parts)){y[k]=g[v];let R=s.get(v)?.max;R!=null&&(x[k]=R)}f[b]={total:g[u.total],parts:y,...Object.keys(x).length?{maxima:x}:{},kpis:Object.fromEntries(t.kpis.map(k=>[k.key,g[k.key]]))}}return f}:void 0,d=m||(r.field.size>0?p=>{let h=kc(r,p),f={};for(let[b,g]of Object.entries(h))f[b]={kpis:Object.fromEntries(t.kpis.map(y=>[y.key,g[y.key]]))};return f}: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}:{},...d?{field:d}:{},definition:t}}var gr={accel:"accel",skidpad:"skidpad",autocross:"autocross",endurance:"endurance"},BA=[{kind:"straightLineAccel",id:gr.accel,label:"Acceleration (75 m)",distance:75},{kind:"constantRadius",id:gr.skidpad,label:"Skidpad",radius:8.375},{kind:"trackLap",id:gr.autocross,label:"Autocross (1 lap)",laps:1},{kind:"trackLap",id:gr.endurance,label:"Endurance (22 km)",distance:22e3}],$A=[{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"}],GA={total:"overall",parts:{[gr.accel]:"accelPts",[gr.skidpad]:"skidpadPts",[gr.autocross]:"autocrossPts",[gr.endurance]:"endurancePts",efficiency:"efficiencyPts"}},KA={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:BA,kpis:$A,score:GA,track:{minTurnRadius:4.5},battery:Ox,traceEventId:gr.autocross},HA={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:BA,kpis:$A,score:GA,track:{minTurnRadius:4.5},traceEventId:gr.autocross},Ac=jn(KA),Kg=jn(HA);var Hg="lap",QN=[{kind:"trackLap",id:Hg,label:Xm,laps:1}],zA={id:"trackday",label:"Track day",description:"One flying lap of the selected track. Times and traces only \u2014 no scoring.",events:QN,kpis:[{key:"lap",label:"Lap time",format:"time",lowerBetter:!0,expr:"lap.time"},{key:"topSpeed",label:"Top speed",unit:"km/h",over:Hg,expr:"peak(speed)"},{key:"energy",label:"Energy / lap",unit:"kWh",lowerBetter:!0,expr:"lap.energy"}],traceEventId:Hg},zg=jn(zA);function Un(e){if(e===null||typeof e!="object")return JSON.stringify(e)??"null";if(Array.isArray(e))return`[${e.map(Un).join(",")}]`;let t=e,r=Object.keys(t).sort(),n=[];for(let o of r)t[o]!==void 0&&n.push(`${JSON.stringify(o)}:${Un(t[o])}`);return`{${n.join(",")}}`}function Go(e){let t=Un(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 bs=[Ac,Kg,zg],Ko=Ac.id,gs=e=>bs.some(t=>t.id===e),YA=new WeakMap,wc=new Map,ZN=64;function ep(e){let t=YA.get(e);if(t!==void 0)return t;let r=Un(e),n=wc.get(r);return n===void 0&&(n=Jm(e).length?null:jn(e),wc.size>=ZN&&wc.delete(wc.keys().next().value),wc.set(r,n)),YA.set(e,n),n}function tp(e,t=[]){if(e==null)return;if(typeof e!="string")return ep(e)??void 0;let r=bs.find(o=>o.id===e);if(r)return r;let n=t.find(o=>o.id===e);return n?ep(n)??void 0:void 0}function Ho(e,t=[]){return tp(e,t)??Ac}function Yg(e=[]){let t=e.filter(r=>!gs(r.id)).map(r=>ep(r)).filter(r=>r!==null);return[...bs,...t]}var Fc=e=>e.definition??e.id;function rp(e,t,r){let n=e.length,o=new Array(n);for(let h=0;h<n;h++){let f=h+1<n?e[h+1]:r;o[h]=f-e[h]}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 h=0;h<n;h++){let f=o[(h-1+n)%n],b=o[h];a[h]=f,s[h]=2*(f+b),i[h]=b;let g=t[(h+1)%n],y=t[(h-1+n)%n];c[h]=6*((g-t[h])/b-(t[h]-y)/f)}let l=JN(a,s,i,c),u=new Array(n),m=new Array(n),d=new Array(n),p=new Array(n);for(let h=0;h<n;h++){let f=o[h],b=l[h],g=l[(h+1)%n],y=t[h],x=t[(h+1)%n];u[h]=y,d[h]=b/2,p[h]=(g-b)/(6*f),m[h]=(x-y)/f-f*(2*b+g)/6}return{n,eval:(h,f)=>u[h]+f*(m[h]+f*(d[h]+f*p[h])),d1:(h,f)=>m[h]+f*(2*d[h]+f*3*p[h]),d2:(h,f)=>2*d[h]+f*6*p[h]}}function jg(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),d=new Array(u).fill(0),p=new Array(u).fill(0),h=new Array(u).fill(0);for(let g=0;g<u;g++){let y=g+1;m[g]=o[y-1],d[g]=2*(o[y-1]+o[y]),p[g]=o[y],h[g]=6*((t[y+1]-t[y])/o[y]-(t[y]-t[y-1])/o[y-1])}let f=n>=3;if(f){let g=o[0]/o[1];d[0]+=o[0]*(1+g),p[0]-=o[0]*g;let y=o[n-1]/o[n-2];d[u-1]+=o[n-1]*(1+y),m[u-1]-=o[n-1]*y}let b=Wg(m,d,p,h);for(let g=0;g<u;g++)a[g+1]=b[g];f&&(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 JN(e,t,r,n){let o=t.length;if(o===1)return[n[0]/(t[0]+e[0]+r[0])];if(o===2){let h=t[0],f=r[0]+e[0],b=e[1]+r[1],g=t[1],y=h*g-f*b;return[(n[0]*g-f*n[1])/y,(h*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=Wg(e,c,r,n),u=new Array(o).fill(0);u[0]=i,u[o-1]=s;let m=Wg(e,c,r,u),d=(l[0]+a*l[o-1]/i)/(1+m[0]+a*m[o-1]/i),p=new Array(o);for(let h=0;h<o;h++)p[h]=l[h]-d*m[h];return p}function Wg(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 Cc(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 WA(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 jA(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 d=r*i-o*o,p=n*o-r*s,h=r*a-n*n;return[(c*t[0]+l*t[1]+u*t[2])/m,(l*t[0]+d*t[1]+p*t[2])/m,(u*t[0]+p*t[1]+h*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(f=>e.closed?(f+t)%t:f);if(s.some(f=>f<0||f>=t))continue;let i=s.map(f=>WA(e,a,f)),c=Math.max(...i.map(Math.abs));if(!(c>0))continue;let l=i.map(f=>f/c),u=[0,0,0,0,0];for(let f of l)for(let b=0;b<5;b++)u[b]+=f**b;let m=jA([u[0],u[1],u[2],u[2],u[3],u[4]],[1,0,0]);if(!m)continue;let d=l.map(f=>m[0]+m[1]*f+m[2]*f*f),p=0,h=1;d.forEach((f,b)=>{p+=f*e.z[s[b]],h+=f*f}),r.push(Math.abs(e.z[a]-p)/Math.sqrt(h))}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 eO(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=WA(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 tO(e,t,r){let{j:n,t:o}=eO(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 d=0;d<5;d++)i[d]+=m,m*=l});let c=jA([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 Ug(e,t){return t>0?e.z.map((r,n)=>{let o=tO(e,n,t/2);return o?o.value.reduce((a,s,i)=>a+s*e.z[o.j[i]],0):r}):[...e.z]}function rO(e,t){if(!(e>0)||!(t>0))return 0;let r=(22.5*t*e*e/1e-4**2)**.2;return Math.min(100/2,r)}function np(e){let t=Cc(e);if(!t)return 0;let r=UA(t);return r>1e-6?Math.max(10,rO(r,nO(t))):0}function nO(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 Gr(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 ap(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 XA(e,t){let r=new Array(e).fill(0),n=new Array(e).fill(0),o=new Array(e).fill(0);for(let a=0;a<e;a++){a>=2&&(o[a]=r[a-2]!==0?t(a,a-2)/r[a-2]:0),a>=1&&(n[a]=r[a-1]!==0?(t(a,a-1)-o[a]*n[a-1])/r[a-1]:0);let s=t(a,a)-n[a]*n[a]-o[a]*o[a];if(!(s>0)||!Number.isFinite(s))return null;r[a]=Math.sqrt(s)}return{d:r,l1:n,l2:o}}function op(e,t){let r=t.length,n=new Array(r).fill(0);for(let a=0;a<r;a++){let s=t[a];a>=1&&(s-=e.l1[a]*n[a-1]),a>=2&&(s-=e.l2[a]*n[a-2]),n[a]=s/e.d[a]}let o=new Array(r).fill(0);for(let a=r-1;a>=0;a--){let s=n[a];a+1<r&&(s-=e.l1[a+1]*o[a+1]),a+2<r&&(s-=e.l2[a+2]*o[a+2]),o[a]=s/e.d[a]}return o}function oO(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 Xg(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=XA(r,(y,x)=>Gr(e,y,x));if(!b)return null;let g=op(b,t);return g.every(Number.isFinite)?g:null}let n=r-2,a=XA(n,(b,g)=>Gr(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]=Gr(e,b,r-2),i[b]=Gr(e,b,r-1);let c=op(a,t.slice(0,n)),l=op(a,s),u=op(a,i),m=(b,g)=>{let y=0;for(let x=0;x<b.length;x++)y+=b[x]*g[x];return y},d=[[Gr(e,r-2,r-2)-m(s,l),Gr(e,r-2,r-1)-m(s,u)],[Gr(e,r-1,r-2)-m(i,l),Gr(e,r-1,r-1)-m(i,u)]],p=[t[r-2]-m(s,c),t[r-1]-m(i,c)],h=oO(d,p);if(!h)return null;let f=new Array(r).fill(0);for(let b=0;b<n;b++)f[b]=c[b]-l[b]*h[0]-u[b]*h[1];return f[r-2]=h[0],f[r-1]=h[1],f.every(Number.isFinite)?f:null}function qA(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=Xg(i,t);if(c){let l=ap(i,c).map((m,d)=>m-t[d]);if(Math.sqrt(l.reduce((m,d)=>m+d*d,0))<=1e-6*Math.max(a,1e-12))return c}o=o===0?n*1e-12:o*10}return null}var QA=4,aO=8,qg=.001;function sO(e,t,r){let n=[];for(let c=1;c<e.length;c++){let l=e[c]-e[c-1];l>=qg&&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/QM(r,s,i)))}function iO(e,t){let r=e.closed!==!1,n=[],o=[],a=(A,F)=>{let T=n.length-1;T>=0&&Math.hypot(A-n[T],F-o[T])<qg||(n.push(A),o.push(F))},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 F=(A+1)%s;c[A+1]=c[A]+Math.hypot(e.x[F]-e.x[A],e.y[F]-e.y[A])}let l=c[i],u=e.fit==="interpolate",m=u?s:sO(c,r,t),d=r?m:m-1,p=0;for(let A=0;A<=d&&!(r&&A===d);A++){if(u){a(e.x[A],e.y[A]);continue}let F=A*l/d;for(;p<i-1&&c[p+1]<F;)p++;let T=c[p+1]-c[p],P=T>0?(F-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])<qg;)n.pop(),o.pop();let h=n.length,f=r?h:h-1,b=new Array(f+1);b[0]=0;for(let A=1;A<=f;A++){let F=A%h,T=n[F]-n[A-1],P=o[F]-o[A-1],S=Math.sqrt(Math.hypot(T,P))||1e-9;b[A]=b[A-1]+S}let g=r?rp(b.slice(0,h),n,b[h]):jg(b,n),y=r?rp(b.slice(0,h),o,b[h]):jg(b,o),x=new Array(f);for(let A=0;A<f;A++)x[A]=b[A+1]-b[A];let k=[0],v=[0],R=[0],M=0;for(let A=0;A<f;A++){let F=x[A]/QA;for(let T=0;T<QA;T++){let P=T*F;M+=Zh(S=>Math.hypot(g.d1(A,S),y.d1(A,S)),P,P+F),k.push(M),v.push(A),R.push(P+F)}}return{closed:r,sx:g,sy:y,h:x,sTable:k,segTable:v,uTable:R,length:M,rawCum:c,rawLength:l}}function Tc(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 d=i*n.rawLength,p=0,h=a;for(;p<h;){let b=p+h+1>>1;n.rawCum[b]<=d?p=b:h=b-1}let f=p<a?n.rawCum[p+1]-n.rawCum[p]:0;c=p+(f>0?(d-n.rawCum[p])/f: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 cO=.01,lO=3,ZA=10;function uO(e,t,r,n=ZA){let o={step:0,uncertainty:1/0},a=e.length;if(a<8||!(r>0))return o;let s=Math.max(ZA,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=[],d=[],p=(x,k,v)=>{let R=x/s;m.push([1,R,R*R,R*R*R,k]),d.push(v)};for(let x=0;x<u;x++)p(t[x]+i,1,e[x]);for(let x=0;x<u;x++)p(t[a-1-x]-r+i,0,e[a-1-x]);let h=Array.from({length:5},()=>new Array(5).fill(0)),f=new Array(5).fill(0);m.forEach((x,k)=>{for(let v=0;v<5;v++){f[v]+=x[v]*d[k];for(let R=0;R<5;R++)h[v][R]+=x[v]*x[R]}});let b=Ar(h,f),g=Ar(h,[0,0,0,0,1]);if(b.singular||g.singular)return o;let y=0;return m.forEach((x,k)=>{let v=0;for(let R=0;R<5;R++)v+=x[R]*b.x[R];y+=(d[k]-v)**2}),{step:b.x[4],uncertainty:Math.sqrt(y/(m.length-5)*g.x[4])}}function mO(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 pO(e,t,r){let{pos:n,loop:o}=mO(e.length,t),{step:a,uncertainty:s}=uO(e,n,o,r);return Math.abs(a)>Math.max(cO,lO*s)?{z:e.map((i,c)=>i+a*n[c]/o),drift:-a}:{z:e,drift:0}}function dO(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],d=r[u+1],p=n[u+1],h=o[u+1],f=n[u]===p?o[u]:0,b=d-m,g=b>0?f+(t-m)/b*(h-f):f;for(let y=0;y<2;y++){let x=m+Zh(v=>Math.hypot(s.d1(p,v),i.d1(p,v)),f,g),k=Math.hypot(s.d1(p,g),i.d1(p,g));if(k<1e-12)break;g-=(x-t)/k}return{seg:p,du:Math.min(Math.max(g,0),a[p])}}var fO=3,Qg=5;function hO(e,t,r,n=Qg){return ip(e,t,r,n)}function ip(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 d of[0,a-1])i[d]+=m,u[d]*=1+m}return Xg({n:a,diag:i,off1:c,off2:l,closed:r},u)??[...e]}function wt(e,t){let r=At(t),n=iO(e,r.fitSpacing),o=n.length,a=Math.max(aO,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 d=new Array(s),p=new Array(s),h=new Array(s);for(let T=0;T<s;T++){let P=T*i,{seg:S,du:w}=dO(n,P);c[T]=n.sx.eval(S,w),l[T]=n.sy.eval(S,w),u[T]=P;let C=n.sx.d1(S,w),L=n.sy.d1(S,w),E=n.sx.d2(S,w),_=n.sy.d2(S,w),O=Math.hypot(C,L),I=Math.pow(C*C+L*L,1.5);d[T]=I>0?(C*_-L*E)/I:0,p[T]=O>0?-L/O:0,h[T]=O>0?C/O:0}let f=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?pO(e.z,n.rawCum,g):null,x=y?y.z:e.z,k=g>0?Cc(e):null,v=k?Ug({...k,z:x},g):x,R=Tc(v,0,f,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),w=n.closed?(P-1+s)%s:Math.max(P-1,0),C=n.closed?2:S-w,L=R[S]-R[w];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,w=R[S]-R[P];m[P]=Math.hypot(i,w)}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,F;if(b){F=new Array(s).fill(0);let T=Math.max(fO,e.zReach??np(e)),P=Math.max(2,Math.round(T/i));if(n.closed?s>2*P:s>2*P+1){let S=0,w=0;for(let E=-P;E<=P;E++)S+=E*E,w+=E*E*E*E;let C=2*P+1,L=w-S*S/C;for(let E=0;E<s;E++){let _=n.closed?E:Math.min(Math.max(E,P),s-1-P),O=0,I=0;for(let V=-P;V<=P;V++){let j=R[n.closed?(_+V+s)%s:_+V];O+=(V*V-S/C)*j,I+=V*j}let z=2*O/L/(i*i),B=I/S/i;F[E]=z/Math.pow(1+B*B,1.5)}}}return{name:e.name,closed:n.closed,x:c,y:l,s:u,ds:m,curvature:e.turnReach?hO(d,i,n.closed,e.turnReach):d,npts:s,length:A,nx:p,ny:h,z:R,gradient:M,...F?{verticalCurvature:F}:{},widthLeft:Tc(e.widthLeft,1.5,f,n),widthRight:Tc(e.widthRight,1.5,f,n),bank:Tc(e.bank,0,f,n),mu:Tc(e.mu,1,f,n),...y?.drift?{elevationDrift:y.drift}:{}}}function JA(e,t,r){let n=ap(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 bO(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 d=s(l,m);d!=null&&(i[d]-=Gr(e,d,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 qA(c,i)}var gO=1e-4;function ew(e,t,r,n,o={}){let a=e.n,s=o.maxIter??60,i=o.tol??1e-9,c=o.bounds,l=(h,f)=>Math.min(n[f],Math.max(r[f],h)),u=r.map((h,f)=>c?.[f]==="hi"?n[f]:c?.[f]==="lo"?r[f]:l(0,f)),m=JA(e,t,u),d=new Array(a).fill("free"),p=!1;for(let h=0;h<s;h++){let f=ap(e,u).map((x,k)=>x-t[k]),b=!1;for(let x=0;x<a;x++){let k=u[x]<=r[x]+i&&f[x]>=-i?"lo":u[x]>=n[x]-i&&f[x]<=i?"hi":"free";k!==d[x]&&(d[x]=k,b=!0)}if(p&&!b)return{x:u,iterations:h+1,converged:!0,bounds:d};let g=bO(e,t,d,x=>u[x]);if(!g)return{x:u,iterations:h+1,converged:!1,bounds:d};let y=!1;for(let x=1;x>1e-12;x*=.5){let k=!1,v=u.map((A,F)=>{if(d[F]!=="free")return A;let T=A+x*(g[F]-A),P=l(T,F);return P!==T&&(k=!0),P}),R=JA(e,t,v),M=0;for(let A=0;A<a;A++)M+=f[A]*(v[A]-u[A]);if(x===1&&!k||R<m&&R<=m+gO*M){u=v,m=R,p=x===1&&!k,y=!0;break}}if(!y)return{x:u,iterations:h+1,converged:!1,bounds:d}}return{x:u,iterations:s,converged:!1,bounds:d}}var Zg={lineStep:2,carHalfWidth:.75,margin:.1,foldMargin:.25,referenceReach:5,passes:40,iterations:400},yO=[1,.5,.25,.125,.0625,.03125,.015625,.0078125,.00390625,.001953125,.0009765625],xO=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],d=e[i]-e[s],p=t[i]-t[s],h=Math.hypot(c,l),f=Math.hypot(u,m),b=Math.hypot(d,p),g=h*f*b;o[a]=g>1e-12?2*(c*m-l*u)/g:0}return o}var RO=Math.PI/180,tw=20;function vO(e,t){let r=e.npts,n=e.closed,o=e.x.map((p,h)=>p+t[h]*e.nx[h]),a=e.y.map((p,h)=>p+t[h]*e.ny[h]),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 h=0;h<r;h++)l.push(s[h]+p*i),u.push(h+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 d=p=>{let h=0,f=l.length-1;for(;f-h>1;){let g=h+f>>1;l[g]<=p?h=g:f=g}let b=l[f]>l[h]?(p-l[h])/(l[f]-l[h]):0;return m[h]+(l[f]-l[h])*b*(u[h]+.5*b*(u[f]-u[h]))};return s.map((p,h)=>{let f=n?tw:Math.min(tw,p,i-p);if(!(f>0))return e.z[h];let b=(d(p+f)-d(p-f))/(2*f),g=n?(b%r+r)%r:Math.min(Math.max(b,0),r-1),y=Math.min(Math.floor(g),r-1),x=n?(y+1)%r:Math.min(y+1,r-1);return e.z[y]+(g-y)*(e.z[x]-e.z[y])})}function kO(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?vO(t,r):t.z;return{...n||o?{z:s.map((i,c)=>i+r[c]*Math.tan(t.bank[c]*RO))}:{},...n?{zReach:e.zReach??np(e)}:{},...o?{bank:[...t.bank]}:{},...a?{mu:[...t.mu]}:{}}}function rw(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 MO(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,d)=>l*d-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,d=e[l]-e[u],p=t[l]-t[u],h=e[m]-e[l],f=t[m]-t[l],b=e[m]-e[u],g=t[m]-t[u],y=Math.hypot(d,p),x=Math.hypot(h,f),k=Math.hypot(b,g),v=y*x*k;if(!(v>1e-12))continue;let R=2*c(d,p,h,f)/v,M=Math.sqrt(.5*(y+x)),A=R/(2*M),F=(d*r[u]+p*n[u])/y,T=(b*r[u]+g*n[u])/k,P=(d*r[l]+p*n[l])/y,S=(h*r[l]+f*n[l])/x,w=(h*r[m]+f*n[m])/x,C=(b*r[m]+g*n[m])/k,L=-2*c(r[u],n[u],h,f)/v+R*(F/y+T/k),E=2*c(r[l],n[l],b,g)/v-R*(P/y-S/x),_=2*c(d,p,r[m],n[m])/v-R*(w/x+C/k);s[l]=R*M,i.l[l]=M*L-A*.5*F,i.d[l]=M*E+A*.5*(P-S),i.r[l]=M*_+A*.5*w}return{res:s,jac:i}}function SO(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=(f,b)=>o?f[(b+a)%a]:b>=0&&b<a?f[b]:0,m=new Array(a),d=new Array(a),p=new Array(a),h=new Array(a);for(let f=0;f<a;f++){let b=u(c,f-1),g=u(s,f+1);m[f]=b*b+i[f]*i[f]+g*g,d[f]=i[f]*c[f]+g*u(i,f+1),p[f]=g*u(c,f+1),h[f]=-(b*u(l,f-1)+i[f]*l[f]+g*u(l,f+1))}return{M:{n:a,closed:o,diag:m,off1:d,off2:p},b:h}}function AO(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 d=0;d<o;d++){let p=(d+1)%r;a+=Math.hypot(e.x[p]-e.x[d],e.y[p]-e.y[d])}let s=a/o,i=ip(e.x,s,n,t,!0),c=ip(e.y,s,n,t,!0),l=new Array(r),u=new Array(r);for(let d=0;d<r;d++){let p=n?(d-1+r)%r:Math.max(d-1,0),h=n?(d+1)%r:Math.min(d+1,r-1),f=i[h]-i[p],b=c[h]-c[p],g=Math.hypot(f,b)||1;l[d]=-b/g,u[d]=f/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 wO=6;function FO(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]),d=Math.hypot(e.x[u]-e.x[l],e.y[u]-e.y[l]);s[l]=d>1e-9?m/d:0}let i=Math.max(0,Math.round(wO/(e.ds[0]||1))),c=1-n;for(let l=0;l<o;l++){let u=0,m=0;for(let d=-i-1;d<=i;d++){let p=e.closed?((l+d)%o+o)%o:l+d;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 Jg(e,t={}){let r={...Zg,...t},n=wt(e,{dsTarget:r.lineStep}),o=AO(n,r.referenceReach),a=o.npts,s=P=>({x:o.x.map((S,w)=>S+o.nx[w]*P[w]),y:o.y.map((S,w)=>S+o.ny[w]*P[w])}),i=P=>{let S=Pc(P.x,P.y,o.closed),w=rw(P.x,P.y,o.closed),C=0;for(let L=0;L<S.length;L++)C+=S[L]*S[L]*w[L];return C},c=xO(n.curvature),l=rw(n.x,n.y,n.closed).reduce((P,S)=>P+S,0),u=new Array(a).fill(0),m=r.carHalfWidth+r.margin,d=new Array(a),p=new Array(a),h=0;for(let P=0;P<a;P++){let S=o.widthLeft[P]-m,w=-(o.widthRight[P]-m);if(S<w){h++;let C=(o.widthLeft[P]-o.widthRight[P])/2;d[P]=C,p[P]=C}else d[P]=S,p[P]=w}let f=[...d],b=[...p];FO(o,d,p,r.foldMargin);let g=P=>{let S=s(P),w=kO(e,o,P),C={name:`${e.name} \u2014 racing line`,x:S.x,y:S.y,closed:o.closed,widthLeft:f.map((B,V)=>Math.max(0,B-P[V])),widthRight:b.map((B,V)=>Math.max(0,P[V]-B)),...w,fit:"interpolate",turnReach:Qg},L=1e-6,E=P.filter((B,V)=>B>=d[V]-L||B<=p[V]+L).length,_=Pc(S.x,S.y,o.closed),O=B=>1/Math.max(...B.map(Math.abs),1e-9),I=0,z=o.closed?S.x.length:S.x.length-1;for(let B=0;B<z;B++){let V=(B+1)%S.x.length,j=S.x[V]-S.x[B],q=S.y[V]-S.y[B];I+=w.z?Math.hypot(j,q,w.z[V]-w.z[B]):Math.hypot(j,q)}return{offset:P,s:[...o.s],asset:C,curvatureRms:{centreLine:c,racingLine:Math.sqrt(i(S)/(l||1))},infeasibleSamples:h,atBoundary:a?E/a:0,length:{centreLine:n.length,racingLine:I},worstRadius:{centreLine:O(n.curvature),racingLine:O(_)}}},y=o.closed?0:1,x=o.closed?a-1:a-2,k=x-y+1,v=new Array(k),R=new Array(k);for(let P=0;P<k;P++)v[P]=p[y+P],R[P]=d[y+P];if(!o.closed&&k>0){let P=(S,w)=>{if(v[S]=Math.max(v[S],p[w]),R[S]=Math.min(R[S],d[w]),v[S]>R[S]){let C=.5*(v[S]+R[S]);v[S]=C,R[S]=C}};P(0,0),P(k-1,a-1),v[0]=R[0]=Math.min(R[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],F=M(u),T;for(let P=0;P<r.passes;P++){let S=s(A),{res:w,jac:C}=MO(S.x,S.y,o.nx,o.ny,o.closed),{M:L,b:E}=SO(C,w,y,x,o.closed),_=ew(L,E,v.map((z,B)=>z-A[y+B]),R.map((z,B)=>z-A[y+B]),{maxIter:r.iterations,bounds:T});T=_.bounds;let O=new Array(a).fill(0);for(let z=0;z<k;z++)O[y+z]=_.x[z];o.closed||(O[0]=O[1],O[a-1]=O[a-2]);let I=!1;for(let z of yO){let B=A.map((j,q)=>j+z*O[q]),V=M(B);if(V.integral<F.integral*(1-1e-6)){A=B,F=V,I=!0;break}}if(!I)break}return g(A)}function e0(e){let t=Math.max(re(e,"track_front"),re(e,"track_rear"));return(t>0?t/2e3:.6)+.1}function cp(e,t,r={}){if(!r.racingLine)return{asset:e,numerics:t,line:null};let n=r.params?e0(r.params):void 0,o=Jg(e,{...r.line,...n?{carHalfWidth:n}:{}});return{asset:o.asset,numerics:{...t,fitSpacing:0},line:o}}function Lc(e,t,r={}){let n=cp(e,t,r);return{track:wt(n.asset,n.numerics),line:n.line}}function t0(e=4,t=Lc){let r=new WeakMap;return(n,o,a={})=>{let s=a.racingLine===!0,i=s?[a.params?e0(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 nw={racingLine:!1,standingStart:!1},lp=256;function Dc(e,t,r,n,o=nw,a=Lc){let s=Ho(n),{racingLine:i,standingStart:c,lapCounts:l}=o;return e.map(u=>{let{track:m}=a(t,r,{racingLine:i,params:u});return _g(yc(u,s,{track:m,numerics:r,standingStart:c,lapCounts:l}))})}function r0(e,t){let r=Ho(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 n0(e,t,r){let n={};for(let o of Ho(e).metrics)n[o.key]=o.value(t,r);return n}var up=36;var s0=287.05287,TO=461.495,mp=9.80665/(s0*.0065),PO=101325/(s0*288.15),LO=273.15,DO=-500,EO=6e3,IO=400,_O=1100,pp={source:"car",altitudeM:0,pressure:{kind:"standard"},humidityPct:0};function NO(e){return 101325*Math.pow(1-.0065*e/288.15,mp)}function OO(e){return 288.15/.0065*(1-Math.pow(e/PO,1/(mp-1)))}function VO(e){return 288.15/.0065*(1-Math.pow(e/101325,1/mp))}function BO(e,t){return e*Math.pow(1-.0065*t/288.15,mp)}function $O(e){return 611.21*Math.exp((18.678-e/234.5)*(e/(257.14+e)))}function GO(e,t){switch(e.kind){case"standard":return NO(t);case"qnh":return BO(e.hPa*100,t);case"station":return e.hPa*100}}function Ec(e,t,r=0,n=VO(e)){let o=t+LO,a=Math.min(.5*e,Math.max(0,Math.min(100,r))/100*$O(t)),s=e-a,i=s/(s0*o)+a/(TO*o);return{altitudeM:n,p:e,pDry:s,T:o,rho:i,densityAltitudeM:OO(i)}}function ow(e,t){return Ec(GO(e.pressure,e.altitudeM),t,e.humidityPct,e.altitudeM)}var o0=(e,t,r)=>Math.min(r,Math.max(t,e)),a0=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function dp(e){if(!e||typeof e!="object")return structuredClone(pp);let t=e,r=t.pressure??{},n=o0(a0(r.hPa,1013.25),IO,_O),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:o0(a0(t.altitudeM,0),DO,EO),pressure:o,humidityPct:o0(a0(t.humidityPct,0),0,100)}}var Yo=e=>e?.source==="venue",fp="the air the session states, at its venue";var KO=Math.PI/180;function HO(){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 zO(){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 i0(e){let t=-e*KO;return te([0,Math.cos(t),Math.sin(t)])}function hp(){let e={rodType:"push",pushrodAttach:"lowerArm",steerMode:"rack",spinAxis:i0(-1),loadedRadius:230,springRate:35,rackAxis:[0,1,0]};return{hardpoints:HO(),config:e}}function Ic(){let e={rodType:"pull",pushrodAttach:"lowerArm",steerMode:"fixed",spinAxis:i0(-1.5),loadedRadius:232,springRate:40,rackAxis:[0,1,0]};return{hardpoints:zO(),config:e}}function bp(){let e=[-25,635,460],t=[-40,600,710],r={layout:"mcpherson",actuation:"direct",rodType:"push",pushrodAttach:"upright",steerMode:"rack",spinAxis:i0(-.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 c0(){return{front:hp(),rear:Ic(),config:{wheelbase:1600,trackFront:1200,trackRear:1220,frontAxleX:800}}}var YO=Math.PI/180;function aw(e){let t=-e*YO;return te([0,Math.cos(t),Math.sin(t)])}function l0(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:aw(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]=WO(o[l]);return{hardpoints:o,config:c}}function WO(e){return e.map(t=>Math.round(t*10)/10+0)}function Wo(e){return{name:e.name,front:l0(hp(),e.front),rear:l0(Ic(),e.rear),config:{wheelbase:e.wheelbase,trackFront:e.trackFront,trackRear:e.trackRear,frontAxleX:e.wheelbase/2}}}function ys(e,t,r){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:t}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:r}}}}var xs=600,jo=610,Rs=230,Uo=232;function Xo(){let e=c0();return{...e,name:"Formula Student",front:{...e.front,config:{...e.front.config,actuation:"rocker"}},rear:{...e.rear,config:{...e.rear.config,actuation:"rocker"}}}}function u0(){return Wo({name:"Formula 1",wheelbase:3600,trackFront:1600,trackRear:1600,front:{kx:1.3,ky:800/xs,kz:355/Rs,lowerInnerDz:-5,upperInnerDz:0,camberDeg:-3,loadedRadius:355,springRate:200},rear:{kx:1.3,ky:800/jo,kz:355/Uo,lowerInnerDz:35,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:220}})}function _c(){return ys(Wo({name:"GT car",wheelbase:2700,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/xs,kz:325/Rs,lowerInnerDz:18,upperInnerDz:5,camberDeg:-3.5,loadedRadius:325,springRate:110,actuation:"direct"},rear:{kx:1.2,ky:825/jo,kz:325/Uo,lowerInnerDz:36,upperInnerDz:15,camberDeg:-2,loadedRadius:325,springRate:120,actuation:"direct"}}),318.6,318.6)}function Nc(){return ys(Wo({name:"Sports car",wheelbase:2750,trackFront:1550,trackRear:1550,front:{kx:1.15,ky:775/xs,kz:320/Rs,lowerInnerDz:36,upperInnerDz:15,camberDeg:-.5,loadedRadius:320,springRate:55,actuation:"direct"},rear:{kx:1.15,ky:775/jo,kz:320/Uo,lowerInnerDz:57,upperInnerDz:25,camberDeg:-1,loadedRadius:320,springRate:60,actuation:"direct"}}),305.4,309)}function jO(e,t,r,n,o,a){let s=bp(),i=Object.fromEntries(Object.entries(s.hardpoints).map(([l,[u,m,d]])=>[l,[u,m+e,d]])),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:aw(n),springRate:o,rackTravel:a}}}function sw(){return ys({name:"Cup car",front:jO(55,-25,-23,-3.5,150,55),rear:l0(Ic(),{kx:1.15,ky:820/jo,kz:320/Uo,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 iw(){return{...ys(Wo({name:"Stock car",wheelbase:2794,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/xs,kz:355/Rs,lowerInnerDz:20,upperInnerDz:5,camberDeg:-2.5,loadedRadius:355,springRate:175,actuation:"direct"},rear:{kx:1.2,ky:825/jo,kz:355/Uo,lowerInnerDz:40,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:150,actuation:"direct"}}),343.8,345.3),chassis:{boxes:[],body:"nascar"}}}function cw(){let e=ys(Wo({name:"Hill-climb prototype",wheelbase:2550,trackFront:1580,trackRear:1540,front:{kx:1.1,ky:790/xs,kz:300/Rs,lowerInnerDz:10,upperInnerDz:5,camberDeg:-2.5,loadedRadius:300,springRate:90},rear:{kx:1.1,ky:770/jo,kz:300/Uo,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 lw(){let e=ys(Wo({name:"Race truck",wheelbase:3700,trackFront:2050,trackRear:1950,front:{kx:1.5,ky:1025/xs,kz:506/Rs,lowerInnerDz:40,upperInnerDz:10,camberDeg:-.5,loadedRadius:506,springRate:200,actuation:"direct"},rear:{kx:1.5,ky:975/jo,kz:506/Uo,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 yt=(e,t,r)=>({value:e,label:t,unit:r}),uw=(e,t)=>({...Er[e],value:t});function mw(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 qo(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 kn(e){let t={name:e.name,m:yt(e.m,"vehicle mass (with driver)","kg"),A:yt(e.A,"frontal area","m^2"),c_l:yt(e.cl,"downforce coefficient","-"),c_w:yt(e.cw,"drag coefficient","-"),l_to_d_ratio:yt(e.cw>0?e.cl/e.cw:0,"lift-to-drag ratio","-"),driven_wheels:yt(e.drivenWheels,"driven wheels","-"),fr_0:yt(-.012,"rolling-resistance coefficient","-"),front_aero_diss:yt(e.frontAero,"front aero distribution","-"),front_mass_diss:yt(e.frontMass,"front mass distribution","-"),r_dyn:yt(e.rDyn,"dynamic tyre radius","m"),rho:yt(1.2,"air density","kg/m^3"),gear_ratio:yt(e.gearRatio,"gear ratio","-"),effi_pgb:yt(e.drivetrainEfficiency,"drivetrain efficiency","-"),capacity:yt(e.capacityAh,"pack capacity","Ah"),soc:yt(1,"state of charge","-"),ocv:yt(e.ocv,"pack open-circuit voltage","V"),power_scale:yt(1,"power scaling factor","-"),power_limit_kw:uw("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]=uw(r,n);return t}var vs={name:"Formula Student",m:300,A:1,cl:3,cw:1.3,frontMass:.47,frontAero:.45,rDyn:.222,drivenWheels:2,gearRatio:11.5,motor:mw(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}},p0={name:"Formula 1",m:798,A:1.5,cl:3,cw:.9,frontMass:.46,frontAero:.44,rDyn:.35,drivenWheels:2,gearRatio:4.9,motor:qo(735,2e3,12500,2500,2),motorCount:1,driveline:{rear:Gt.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}},gp={name:"GT car",m:1300,A:2,cl:1.4,cw:.42,frontMass:.5,frontAero:.42,rDyn:.33,drivenWheels:2,gearRatio:3.43,motor:qo(410,2e3,8e3,2e3,2),motorCount:1,driveline:{rear:Gt.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}},yp={name:"Sports car",m:1600,A:2.2,cl:-.1,cw:.3,frontMass:.55,frontAero:.5,rDyn:.32,drivenWheels:2,gearRatio:3.14,motor:qo(220,1500,6500,1400,2),motorCount:1,driveline:{rear:Gt.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}},d0={name:"Cup car",m:1265,A:2.1,cl:.45,cw:.4,frontMass:.62,frontAero:.45,rDyn:.31,drivenWheels:2,gearRatio:3.5,motor:qo(250,2e3,7e3,1190,2),motorCount:1,motorPlacement:"front",driveline:{front:Gt.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}},f0={name:"Stock car",m:1620,A:2.2,cl:.6,cw:.45,frontMass:.53,frontAero:.45,rDyn:.35,drivenWheels:2,gearRatio:4.1,motor:qo(500,2500,9e3,1680,2),motorCount:1,driveline:{rear:Gt.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}},h0={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:qo(330,3e3,8500,1240,2),motorCount:1,driveline:{rear:Gt.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}},b0={name:"Race truck",m:5300,A:6.2,cl:-.1,cw:.65,frontMass:.6,frontAero:.6,rDyn:.502,drivenWheels:2,gearRatio:3.55,motor:qo(880,100,3e3,88e3,2),motorCount:1,driveline:{rear:Gt.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 m0(e,t,r){return kn(r({...structuredClone(e),name:t}))}var xp={[vs.name]:kn(vs),"Formula Student +15% downforce":m0(vs,"Formula Student +15% downforce",e=>({...e,cl:e.cl*1.15,cw:e.cw*1.08})),"Formula Student -15 kg":m0(vs,"Formula Student -15 kg",e=>({...e,m:e.m-15})),"Formula Student +15% power":m0(vs,"Formula Student +15% power",e=>({...e,motor:mw(25*1.15,15e3,2e4),powerLimitKw:80*1.15})),[p0.name]:kn(p0),[gp.name]:kn(gp),[yp.name]:kn(yp),[d0.name]:kn(d0),[f0.name]:kn(f0),[h0.name]:kn(h0),[b0.name]:kn(b0)},pw=Object.keys(xp),g0=pw.slice(0,4),y0=[vs.name,p0.name,gp.name,yp.name,d0.name,f0.name,h0.name,b0.name];var vae={"Touring car":gp.name,"Street car":yp.name};var UO={bg:"#11141b",panel:"#161b22",panel2:"#202d3a",border:"#334050",borderBright:"#526477",sunken:"#0b1219",ink:"#06090d"},XO={normal:"#eef3fa",dim:"#9baab9",bright:"#ffffff",white:"#ffffff"},qO={label:"#c8d2dc",grid:"#39424e",gridFaint:"#232b35",empty:"#1a2028"},QO={accent:"#6aa8ff",accentInk:"#0d1b30",warn:"#ffb454",good:"#4ec9a0",bad:"#ff6b6b",badSoft:"#ff8f8f"},ZO=["#f0e442","#7b68ee","#f7a8b8","#d55e00","#d8b4fe","#b5e48c"],Rp={front:"#a6e22e",rear:"#00b4d8"},dw=["#5b4bd6","#4aa3ff","#4ec9a0","#f0e442"],x0={power:"#ffb454",traction:"#f0845c",front:Rp.front,rear:Rp.rear,grip:"#73c9b3",braking:"#b48aff",crest:"#e88fd0",below:"rgba(214, 221, 230, 0.32)"},JO={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"},eV={x:"#ff6b6b",y:"#57c75a",z:"#4aa3ff"},tV={line:"#b4bfcb"},rV={compression:"#b48aff",tension:"#ff6b6b"},nV={fz:"#e7ecf3",fx:"#7ad7f0",fy:"#ff54c8"},oV={drivenLine:"#4d7cff",axis:"#eef3fa",slip:"#ffe81a",drive:x0.power,brake:x0.braking},aV={ground:"#101920",grid:"#1a2630",gridMajor:"#26343f",horizon:"#1d2833",bridge:"#6f7a86",coneLeft:"#2f63c9",coneRight:"#d9b51f",coneStart:"#ee7a2c"},sV={chassis:"#435160",volume:"#303b47",tyre:"#435160",tyreLine:"#39424e",tyreFace:"#1c232d"},iV={centreLine:"#4aa3ff",corridorFill:"rgba(74,163,255,0.10)",boundary:"#3d4956",racingLine:"#ffb454",start:"#e7ecf3",finish:"#ff6b6b",direction:"#8b96a3"},cV={SURFACE:UO,TEXT:XO,CHART:qO,ROLE:QO,SERIES:ZO,AXLE:Rp,LAP_SPEED:dw,LIMITER:x0,RIG:JO,AXIS:eV,CONSTRUCTION:tV,FORCE:rV,TYRE_FORCE:nV,REPLAY:oV,SCENERY:aV,BODY:sV,TRACK:iV},fw=e=>Object.fromEntries(Object.entries(e).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):Object.freeze({...r})])),vp=fw(cV),Ht=vp.SERIES,hw=(()=>{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 fw({SURFACE:{bg:"#f5f6f6",panel:"#fcfcfd",panel2:"#ffffff",border:"#d8dfe6",borderBright:"#b7c3ce",sunken:"#e8edf2",ink:"#ffffff"},TEXT:{normal:"#17212c",dim:"#606c79",bright:"#10171f",white:"#000000"},CHART:{label:"#3a424b",grid:"#c2c8cd",gridFaint:"#e2e5e7",empty:"#e8eae7"},ROLE:{accent:"#2162bd",accentInk:"#ffffff",warn:e,good:"#0f8a66",bad:t,badSoft:"#e2696d"},SERIES:["#b5a11a","#2844e3","#f47ec1","#9b3a1b","#764299","#58b977"],AXLE:r,LAP_SPEED:["#4b3bc4","#1a64c2","#0f8a66","#a87e00"],LIMITER:n,RIG:{chassis:"#1a64c2",ballJoint:"#c27200",arm:"#56616d",tie:"#24907b",pushrod:"#a3820f",rocker:"#6656b8",kingpin:"#8f7f10",arbBar:"#b04d77",arbArm:"#9a4767",arbLink:"#c27200",heaveSpring:"#1688ad",wheelCentre:"#15181c",contactPatch:t,ground:"#e2e6e8",groundFaint:"#edf0f1"},AXIS:{x:"#d93a3a",y:"#2f9d34",z:"#1a64c2"},CONSTRUCTION:{line:"#5a6570"},FORCE:{compression:"#7b55d0",tension:t},TYRE_FORCE:{fz:"#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 bw=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},Mae=(()=>{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=vp[r],o=hw[r];for(let a of Object.keys(n)){let s=bw(n[a]);s&&!e.has(s)&&e.set(s,o[a])}}return e})();var gw=(e,t)=>new Set(t.flatMap(r=>{let n=e[r];return Array.isArray(n)?[...n]:Object.values(n)}).map(bw).filter(r=>r!==null)),Sae=gw(hw,["SERIES","AXLE","LAP_SPEED","LIMITER","ROLE","RIG","FORCE","TYRE_FORCE","REPLAY","AXIS","TRACK","CONSTRUCTION"]),Aae=gw(vp,Object.keys(vp).filter(e=>e!=="SURFACE"));function R0(){return{kind:"simple",name:"Simple motor",rpm:[0,16e3,2e4],torque:[21,21,14],efficiency:.95}}function v0(){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 k0(){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 M0(){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 S0(){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 yw(){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 xw(){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 Rw(){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 vw(){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 kw(){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 Mw(){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 Sw(e){return Go(lV(e))}function lV(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 Oc(e,t){return{...t,fingerprint:Sw(e)}}var Aw="CC-BY-4.0",uV={title:"PaceDynamics built-in library",url:"https://pacedyn.dev/",licence:Aw},ww={fidelity:"generic",licence:Aw,sources:[uV]};var kp=e=>Oc(e,ww);var Fw=["raw.githubusercontent.com"],Cw=["tum-csv"],pV=/^[0-9a-f]{64}$/;function Bc(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"||!pV.test(r)||!Cw.includes(n))return!1;try{let o=new URL(t);return o.protocol==="https:"&&Fw.includes(o.hostname)&&!o.username&&!o.password&&!o.port}catch{return!1}}var Mp=e=>new URL(e.url).hostname;async function Tw(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 dV(e){let t=new URL(e).pathname.split("/").pop()??"";return decodeURIComponent(t).replace(/\.[^.]*$/,"")||"Linked track"}function fV(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 hV={"tum-csv":fV};function Pw(e,t){return hV[t.format](e,dV(t.url))}async function A0(e,t,r){let n=await Tw(e);if(n!==t.sha256)throw new Error(`${Mp(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=Pw(new TextDecoder().decode(e),t),a=await Sp(o);if(a!==r)throw new Error(`Linked track ${r} does not convert to its name (it is ${a}).`);return o}var w0=20,gV=new RegExp(`^[0-9a-f]{${w0}}$`),$c=e=>typeof e=="string"&&gV.test(e);async function Sp(e){let t=new TextEncoder().encode(Un(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,w0)}var F0=e=>`tracks/${e}.json`;var yV=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function C0(e){return{model:{name:e.name,source:e.source},...e.provenance?{provenance:e.provenance}:{}}}async function T0(e,t){if(!yV(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 Sp(e);if(r!==t)throw new Error(`Catalogue track ${t} does not match its name (it is ${r}).`);return e}var Qo=(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}),Xn=[Qo("suspensions","suspensionId","suspension"),Qo("tires","tireModelId","tyre",[{key:"tiresRear",ref:"tireModelIdRear",label:"rear tyre"}]),Qo("motors","motorModelId","motor"),Qo("aeros","aeroModelId","aero map"),Qo("batteries","batteryModelId","battery"),Qo("brakes","brakeModelId","brakes"),Qo("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 Ap(e){let t={...e};for(let r of Xn)for(let n of r.refs)delete t[n];return t}var wp=Ht,Gc=wp,P0=wp,qn=[...Ht.slice(3),...Ht.slice(0,3)],E0=[...Ht.slice(1),Ht[0]],L0=[...Ht.slice(2),...Ht.slice(0,2)],D0=[...Ht.slice(4),...Ht.slice(0,4)],I0=[...Ht.slice(5),...Ht.slice(0,5)],Kc=[...Ht.slice(2),...Ht.slice(0,2)];function _0(){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 N0(e,t,r){let n=xp[e];if(!n)throw new Error(`no preset vehicle named "${e}"`);return{id:t,params:{...zi(structuredClone(n)),energy:{...sn},suspensionId:"sus1"},visible:!0,color:Gc[r%Gc.length]}}function vV(){return g0.map((e,t)=>N0(e,`v${t+1}`,t))}function kV(){return[xi(),bh(),gh(),yh(),xh(),Rh(),vh(),kh(),Mh(),Sh()].map((t,r)=>({id:`t${r+1}`,color:P0[r%P0.length],model:t}))}function MV(){return[Xd(),qd(),Qd(),Zd(),Jd(),ef(),tf(),rf()].map((t,r)=>({id:`a${r+1}`,color:L0[r%L0.length],model:t}))}function SV(){return[Id(),_d(),Nd()].map((t,r)=>({id:`b${r+1}`,color:D0[r%D0.length],model:t}))}function AV(){return[{id:"brk1",color:I0[0],model:structuredClone(Hh)}]}function wV(){return[{id:"dmp1",color:Kc[0],model:structuredClone(Zu)}]}function FV(){return[R0(),v0()].map((t,r)=>({id:`m${r+1}`,color:qn[r%qn.length],model:t}))}function O0(e){let t=r=>({...r,provenance:kp(r.model)});return{...e,suspensions:e.suspensions.map(t),vehicles:e.vehicles.map(r=>({...r,provenance:kp(Ap(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 Hc(e="Untitled project"){let t=new Date().toISOString(),r=vV();return O0({schemaVersion:up,meta:{id:_0(),name:e,domain:"racecar",rulesetId:Ko,createdAt:t,updatedAt:t},suspensions:[{id:"sus1",color:E0[0],model:Xo()}],activeSuspensionId:"sus1",vehicles:r,activeVehicleId:r[0]?.id??null,tires:kV(),motors:FV(),aeros:MV(),batteries:SV(),brakes:AV(),dampers:wV(),tracks:[],activeTrackId:null,mathChannels:[],rulesets:[],studies:[],activeStudyId:null,loadCases:[],reportLayouts:[],tyreSheets:[],kinSheets:[],lapSheets:[],plans:[],results:[],settings:{numerics:{...ac},ggvMode:"twoTrack",quasiTransient:!1,motorThermal:!1,brakeFade:!1,airTempC:Ut,air:structuredClone(pp),diffYaw:!1,lapCounts:{},pathPlanId:null,useRacingLine:!0,standingStart:!1}})}var CV=["front","rear"],V0=9.81,TV=Math.PI/180;var Kr="*",B0=40,Lw=.8;function $0(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 Dw(e,t,r){let n=t.rows.map(c=>c.v),o=c=>ht(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/V0*100)/100+0,axG:Math.round(u/V0*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(B0/3.6,o(B0/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(Lw*s,o(Lw*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=Dw(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 K0(e,t){let r=e.speedKmh/3.6,n=e.ayG*V0;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)/TV}var Ew=e=>e.ayG<0?"L":"R";function H0(e,t=CV){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 z0=(e,t)=>e.travelMin===t.travelMin&&e.travelMax===t.travelMax&&e.rollMaxDeg===t.rollMaxDeg&&e.rollAtLimitDeg===t.rollAtLimitDeg;var Mn=Math.PI/180,PV=9.81,zc=.1,Y0=20,Iw=6,Vw=50;function _w(e,t,r){let n=e(0),o=0;for(let d=t;d<=r+1e-9;d+=t){let p=e(d);if(p>n)n=p,o=d;else if(d>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 d=0;d<14;d++)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 W0(e,t,r,n,o){let a=o*Mn;if(t==="side")return _w(i=>r*e.Fy(r*i*Mn,n,a),1,45);let s=t==="drive"?1:-1;return _w(i=>s*e.Fx(s*i,n,a),.02,.6)}function Cp(e){let t=e?bu(e)?.gamma:void 0,r=[t?.min,t?.max].filter(o=>o!==void 0&&Number.isFinite(o));if(!r.length)return{lo:-Iw,hi:Iw,stated:!1};let n=Math.max(...r.map(Math.abs))/Mn;return{lo:-n,hi:n,stated:!0}}function LV(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 f=0;f<n;f++){let b=t+f*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),d=e(u),p=e(m);for(let f=0;f<12;f++)d>p?(c=m,m=u,p=d,u=c-l*(c-i),d=e(u)):(i=u,u=m,d=p,m=i+l*(c-i),p=e(m));let h=d>=p?{g:u,v:d}:{g:m,v:p};return h.v>s?h.g:a}var Nw=250,Ow=new WeakMap;function DV(e,t,r,n,o,a,s){let i=Ow.get(e);i||Ow.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=h=>{let f=l.get(h);if(f===void 0){let b=Math.max(50,h*Nw);f=LV(g=>W0(r,n,o,b,g).force,s.lo,s.hi),l.set(h,f)}return f},m=Math.max(0,a)/Nw,d=Math.floor(m),p=m-d;return p<1e-9?u(d):u(d)*(1-p)+u(d+1)*p}function ks(e,t){return t==="front"?e.tireModel:e.tireModelRear??e.tireModel}var EV=new WeakMap,IV=new WeakMap,_V=new WeakMap,j0=(e,t,r)=>{let n=e.get(t);return n===void 0&&e.set(t,n=r()),n};function Tp(e,t){let r=ks(e,t);return r?j0(EV,r,()=>pi(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 U0(e,t){let r=ks(e,t);return r?j0(_V,r,()=>gu(r).none)?"This tyre file has no drive or brake grip.":j0(IV,r,()=>{let n=_e(r),o=r.kind==="magic"?r.fnomin:r.nominalLoad,a=n.Fx(.1,o,0),s=n.Fx(.1,o,3*Mn);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 Zo(e,t){return e==="side"||e==="ackermann"?Math.abs(t.ayG)>=zc?e==="ackermann"&&!(Bw(t)<=Y0)?`is a corner wider than ${Y0} m`:null:"does not corner":(e==="drive"?t.axG:-t.axG)>=zc?null:e==="drive"?"does not drive":"does not brake"}var NV=e=>e.axG>=zc?"drive":e.axG<=-zc?"brake":null;function Bw(e){let t=e.speedKmh/3.6,r=Math.abs(e.ayG)*PV;return r>1e-9?t*t/r:1/0}var Fp=(e,t)=>`${e==="front"?"F":"R"}${t}`,OV=e=>e==="L"?"R":"L",VV=(e,t,r)=>Math.min(r,Math.max(t,e));function X0({ev:e,params:t,input:r,state:n,pose:o}){let a=`${re(t,"grip_scale")}|${re(t,"stiffness_scale")}`,s=Bw(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,R,M,A)=>{let F=Fe(e,k),T=ks(t,k),P=Math.max(0,o.loads[v]),S=o.camber[v],w=VV(S,A.lo,A.hi),C=W0(F,R,M,P,w),L=P<Vw,E=T&&!L?DV(T,a,F,R,M,P,A):w,_=L?C.force:W0(F,R,M,P,E).force,O=.05;return{corner:v,Fz:P,lifted:L,camber:S,read:w,outside:w!==S,wants:E,atEdge:!L&&(E-A.lo<O||A.hi-E<O),peak:C.force,slip:C.at,best:_}},d=(k,v,R)=>{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:R}},p=new Map,h=k=>{if(p.has(k))return p.get(k)??null;let v=null;if(!Zo("side",n)){let R=Cp(ks(t,k));v=[m(k,Fp(k,o.outer),"side",1,R),m(k,Fp(k,OV(o.outer)),"side",-1,R)]}return p.set(k,v),v},f=new Map,b=new Map,g=new Map,y=(k,v,R)=>{let M=k==="front"?i:-c,A=(v?1:-1)*u(k),F=R*Mn;return Math.atan2(M+s*Math.sin(F),s*Math.cos(F)-A)/Mn},x=k=>(n.ayG<0?-1:1)*o.steer[k];return{side(k){if(f.has(k))return f.get(k)??null;let v=Tp(t,k)?null:h(k),R=v?d("side",v,Cp(ks(t,k))):null;return f.set(k,R),R},long(k){if(b.has(k))return b.get(k)??null;let v=NV(n),R=null;if(v&&!U0(t,k)){let M=Cp(ks(t,k));R=d(v,[m(k,Fp(k,"L"),v,1,M),m(k,Fp(k,"R"),v,1,M)],M)}return b.set(k,R),R},toeLoss(k){let v=g.get(k);if(v!==void 0)return v;let R=h(k),M=NaN;if(R&&R[0].peak+R[1].peak>0){let A=Fe(e,k),[F,T]=R,P=[{g:F,dt:1,inner:!1,steer:x(F.corner)},{g:T,dt:-1,inner:!0,steer:x(T.corner)}],S=_=>P.reduce((O,I)=>{let z=I.steer-y(k,I.inner,_);return O+I.dt*A.Fy(I.dt*z*Mn,I.g.Fz,I.g.read*Mn)},0),w=P.map(_=>_.steer-_.g.slip-y(k,_.inner,0)),C=Math.min(...w)-2,L=Math.max(...w)+2,E=BV(S,C,L,.25);M=Math.max(0,1-E/(F.peak+T.peak))}return g.set(k,M),M},ackermann(){if(Zo("ackermann",n))return NaN;let k=h("front");if(!k||k[0].lifted||k[1].lifted)return NaN;let[v,R]=k,M=Math.sqrt(Math.max(s*s-c*c,1e-6)),A=u("front"),F=(Math.atan(l/(M-A))-Math.atan(l/(M+A)))/Mn;if(!(F>.001))return NaN;let T=x(R.corner)-x(v.corner),P=F+(R.slip-v.slip);return 100*(T-P)/F}}}function BV(e,t,r,n){let o=-1/0,a=t;for(let p=t;p<=r+1e-9;p+=n){let h=e(p);h>o&&(o=h,a=p)}let s=a-n,i=a+n,c=.6180339887498949,l=i-c*(i-s),u=s+c*(i-s),m=e(l),d=e(u);for(let p=0;p<14;p++)m>d?(i=u,u=l,d=m,l=i-c*(i-s),m=e(l)):(s=l,l=u,m=d,u=s+c*(i-s),d=e(u));return Math.max(o,m,d)}var $V=9.81,$w=Math.PI/180,Yc={speed:20,ayG:1.2};function q0(e,t={}){let r=t.operating??Yc,n=t.assemble,o,a,s,i=new Map,c=new Map,l=new Map,u=new Map,m=new Map,d=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},h=()=>{if(a!==void 0)return a;try{a=Nr(e.params)}catch{a=null}return a},f=v=>{let R=d(v),M=`${R.speed}|${R.ayG}`,A=i.get(M);if(A!==void 0)return A;let F=h();if(!F)return i.set(M,null),null;let T={cornerStiffness:P=>F.corneringStiffness(P),ayG:R.ayG,speed:R.speed,fyAxle:(P,S)=>2*F.Fy(P,S/2),tire:F};return i.set(M,T),T},b=()=>{if(s!==void 0)return s;let v=p(),R=h();if(!v||!R)return s=null;try{s=So(R,v.massTotal*$V*1.2)}catch{s=null}return s},g=v=>{let R=d(v).speed,M=`${R}`,A=c.get(M);if(A!==void 0)return A;let F=p(),T=h(),P=null;if(F&&T)try{P=Ob(F,T,R,{steering:!1})}catch{P=null}return c.set(M,P),P},y=v=>{let R=`${v.speedKmh}|${v.ayG}|${v.axG}`,M=m.get(R);if(M!==void 0)return M;let A=null,F=p();try{let T=F?.kinFront,P=F?.kinRear;if(F&&T&&P){let S=K0(v,F.wheelbase),w=v.speedKmh/3.6,C=Vn(F,T,P,w)(v.ayG,v.axG,0,S),L={FL:C.FL.travel,FR:C.FR.travel},E=wo(F,S*$w,L),_=S?E.camber:null,O={},I={};for(let B of["FL","FR","RL","RR"]){let V=B[1]==="R"?C[B].camberRoad:0-C[B].camberRoad;O[B]=V+(_?.[B]??0),I[B]=E.steer[B]/$w+(B[1]==="R"?1:-1)*C[B].bumpToe}let z=$e(F,v.ayG,v.axG,w,0,S,L,C.steeringJacking);A={corners:C,rollDeg:C.FL.camberRoad-C.FL.camber,steerDeg:S,camber:O,outer:Ew(v),loads:z,steer:I}}}catch{A=null}return m.set(R,A),A},x=new Map;return{operating:r,dynAvailable:!!n,poseAt:y,tyreAt:v=>{let R=`${v.speedKmh}|${v.ayG}|${v.axG}`,M=x.get(R);if(M!==void 0)return M;let A=y(v),F=p(),T=h(),P=A&&F&&T?X0({ev:T,params:e.params,input:F,state:v,pose:A}):null;return x.set(R,P),P},operatingAt:d,dynInput:p,tyre:h,dynCtx:f,grip:b,ymd:g,ymdLimit:v=>{let R=`${d(v).speed}`,M=l.get(R);if(M!==void 0)return M;let A=g(v),F=A?yg(A):null;return l.set(R,F),F},reserves:(v,R)=>{let M=d(R),A=`${v}|${M.speed}|${M.ayG}`,F=u.get(A);if(F!==void 0)return F;let T=p(),P=f(R),S=null;if(T&&P)try{S=mc(T,P,v,b()??void 0)}catch{S=null}return u.set(A,S),S}}}var Gw=["widthLeft","widthRight","bank","mu"];function Wc(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 Q0(e){let t=Wc(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 Lp(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 d of Gw){let p=l[d];if(p===void 0)continue;let h=s[d],f=r[d];for(let b=0;b<o&&t[b]<l.from;b++)f=h[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;h[b]=u>0&&y<u?f+(p-f)*(y/u):p}}}return s}function Dp(e,t,r){if(!t.length)return e;let n=Wc(e),o=n.length,a={widthLeft:Pp(e.widthLeft,r.widthLeft),widthRight:Pp(e.widthRight,r.widthRight),bank:Pp(e.bank,r.bank),mu:Pp(e.mu,r.mu)},s={};for(let c of Gw){let l=e[c];Array.isArray(l)&&l.length===o&&(s[c]=l)}let i=Lp(t,n,a,s);return{...e,...i}}function Pp(e,t){return typeof e=="number"?e:t}var zw=1,Kw=4,Ip=Math.PI/180,Z0=e=>e===null||!Number.isFinite(e)||e===0?0:1/e;function J0(e){return e.kind==="arc"?Math.abs(e.radius)*Math.abs(e.angle)*Ip:e.length}function Ep(e,t){return e.kind==="straight"?0:e.kind==="arc"?Z0(e.radius):t}function Hw(e){return e.kind==="straight"?0:e.kind==="arc"?Z0(e.radius):Z0(e.endRadius)}var jc=(e,t,r,n,o)=>e+t*o+(n>0?(r-t)*o*o/(2*n):0);function Uc(e,t={}){let r=Math.max(.05,t.spacing??zw),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,w)=>S+J0(w),0),m=Math.max(n?3:2,Math.round(u/r)),d=u>0?u/m:r,p=o.x,h=o.y,f=o.heading*Ip,b=e.length?Ep(e[0],0):0,g=0,y=d,x=(S,w,C)=>{s.push(S),i.push(w),c.push(C)};x(p,h,0);let k=(S,w,C,L,E)=>{let _=E-L;if(_<=0)return;if(Math.abs(w-S)<1e-12){let I=jc(f,S,S,C,L);if(Math.abs(S)<1e-12)p+=_*Math.cos(I),h+=_*Math.sin(I);else{let z=I+S*_;p+=(Math.sin(z)-Math.sin(I))/S,h+=-(Math.cos(z)-Math.cos(I))/S}return}let O=_/Kw;for(let I=0;I<Kw;I++){let z=L+I*O,B=jc(f,S,w,C,z),V=jc(f,S,w,C,z+O/2),j=jc(f,S,w,C,z+O);p+=O/6*(Math.cos(B)+4*Math.cos(V)+Math.cos(j)),h+=O/6*(Math.sin(B)+4*Math.sin(V)+Math.sin(j))}};for(let S of e){let w=J0(S),C=Ep(S,b),L=Hw(S);if(l.push({from:g,to:g+w,...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}:{}}),w<=0){b=L;continue}let E=0;for(;y<=g+w+1e-9;){let _=Math.min(w,y-g);k(C,L,w,E,_),E=_,x(p,h,g+_),y+=d}k(C,L,w,E,w),f=jc(f,C,L,w,w),b=L,g+=w}let v=s.length>1?Math.hypot(s[0]-s[s.length-1],i[0]-i[i.length-1]):0,R=g;n&&s.length>1&&(s.pop(),i.pop(),c.pop());let M=e.length?Ep(e[0],b):0,A={gap:v,headingError:GV((f-o.heading*Ip)/Ip),curvatureError:b-M},F=[];for(let S=0;S<e.length;S++){let w=Hw(e[S]),C=S+1<e.length?e[S+1]:n?e[0]:null;if(!C)continue;let L=Ep(C,w);F.push({index:S,before:w,after:L,jump:Math.abs(L-w)})}let T=Lp(l,c,a);return{asset:{name:t.name??"Track",x:s,y:i,fit:"interpolate",...n?{}:{closed:!1},...T},sections:l,joints:F,closure:A,length:R}}function GV(e){let t=e%360;return t>180&&(t-=360),t<-180&&(t+=360),t}var KV={halfWidthM:1.5,spacingM:.5};function Xc(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 ${Ww(e).toFixed(0)} m`}}}function Ww(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 jw=e=>e.kind==="skidpad"||e.kind==="curves"&&e.closed===!0,Uw=e=>e.kind==="acceleration",Xw=1.5,qw=3;function HV(e,t){let r=e.offsetM,n=e.pitchM,o=Math.max(1,e.gates)*n,a=Math.max(0,e.leadInM),s=Xw*n,i=f=>{let b=Math.min(1,Math.max(0,f));return b*b*b*(b*(b*6-15)+10)},c=f=>Math.min(i(f/s),i((o-f)/s)),l=r*(Math.PI/n)**2,u=l>0?Math.max(.05,Math.min(t.spacingM,1/l*(qw*Math.PI/180))):t.spacingM,m=[],d=[],p=Math.max(1,Math.round(a/u));for(let f=0;f<p;f++)m.push(-a+a*f/p),d.push(0);let h=Math.max(8,Math.round(o/u));for(let f=0;f<=h;f++){let b=o*f/h;m.push(b),d.push(r*c(b)*Math.sin(Math.PI*b/n))}return{name:Xc(e),x:m,y:d,closed:!1,widthLeft:t.halfWidthM,widthRight:t.halfWidthM,fit:"interpolate"}}function zV(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 ey(e,t={}){let r={...KV,...t},n=Uw(e),o=zV(e);if(!o){let u=HV(e,r);return{asset:u,peakCurvature:Yw(u),worstJoint:0,standingStart:n}}let a=jw(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*(qw*Math.PI/180))):r.spacingM,c=Uc(o,{name:Xc(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:Yw(c.asset),worstJoint:l.reduce((u,m)=>Math.max(u,m.jump),0),standingStart:n}}function Yw(e){try{return Math.max(...wt(e).curvature.map(Math.abs))}catch{return NaN}}var Np={courses:[{id:"c1",course:{kind:"manoeuvre",spec:{kind:"skidpad",radiusM:8.375}}}],ggvMode:"twoTrack"};function ty(e){return e.course.kind==="project"?"the project\u2019s track":e.course.kind==="track"?e.course.name:Xc(e.course.spec)}var Qw=new WeakMap,_p=new Map;function Zw(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=_p.get(n);if(o)return{...o,numerics:r};let a=ey(e.spec),s={asset:a.asset,standingStart:a.standingStart};return _p.size>64&&_p.clear(),_p.set(n,s),{...s,numerics:r}}function ry(e,t,r={}){let n=r.lap??Np,o=r.simParams,a=r.numerics??{},s=n.courses.length?n.courses:Np.courses,i,c,l,u=new Map,m=new Map,d=new Map,p=new Map,h=k=>(k?.courseId?s.find(v=>v.id===k.courseId):void 0)??s[0],f=()=>{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=h(k);if(!v)return null;let R=m.get(v.id);if(R!==void 0)return R;let M=Zw(v.course,r,a),A=null;if(M)try{let F=JSON.stringify(M.numerics),T=Qw.get(M.asset);T||(T=new Map,Qw.set(M.asset,T));let P=T.get(F);P||(P=wt(M.asset,M.numerics),T.set(F,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=f();if(!k)return c=null;try{l=Xt(k),c=Vr(l,!1,n.ggvMode)}catch{c=null}return c},y=k=>{let v=b(k);if(!v)return null;let R=d.get(v.id);if(R!==void 0)return R;let M=g(),A=null;if(M)try{let F=l?Vo(l,M,[v.track],v.numerics,n.ggvMode,u):void 0,T=l?Wn(l,M.rows):void 0;A=Kt(M,v.track,v.numerics,{standingStart:v.standingStart,...F?{load:F}:{},...T?{shifts:T}:{}})}catch{A=null}return d.set(v.id,A),A};return{lapSettings:n,get lapAvailable(){return!!o&&s.some(k=>!!Zw(k.course,r,a))},lapParams:f,courses:()=>s,course:b,ggv:g,lap:y,lapReserve:k=>{let v=b(k);if(!v)return null;let R=p.get(v.id);if(R!==void 0)return R;let M=y(k),A=t.dynInput(),F=t.tyre(),T=null;if(M&&A&&F)try{let P=f();T=Bm(A,F,Um({...M,ds:v.track.ds,rows:g()?.rows,gradient:v.track.gradient,bank:v.track.bank,mu:v.track.mu}),P?{driven:ob(P)}:{})}catch{T=null}return p.set(v.id,T),T}}}var Jw=180/Math.PI,ny={rise:0,sinPitch:0,sinRoll:0};function eF(e){let t=e.kc;return t?tF(e.vehicle,r=>t.ground0[r]):ny}function tF(e,t){let r=e.config,n=En(r),o=0,a=0,s=0,i=0,c=0,l=0,u=0,m=0,d=0;for(let g of wr){let y=nt(g,r),x=y.axleX-n,k=y.sideSign*ar(e,y.isFront)/2,v=t(g);if(!Number.isFinite(v))return ny;o++,a+=x,s+=k,i+=v,c+=x*x,l+=k*k,u+=x*k,m+=x*v,d+=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 h=(i*(c*l-u*u)-a*(m*l-u*d)+s*(m*u-c*d))/p,f=(o*(m*l-u*d)-i*(a*l-u*s)+s*(a*d-m*s))/p,b=(o*(c*d-m*u)-a*(a*d-m*s)+i*(a*u-c*s))/p;return{rise:h,sinPitch:f,sinRoll:-b}}function qc(e,t){let r=e.kc,n=tF(e.vehicle,o=>(r?r.ground0[o]:0)+t[o]);return te([-n.sinPitch,n.sinRoll,1])}function oy(e,t,r,n){let o=te(qr(e,nt(t,r)));return-Math.asin(Math.max(-1,Math.min(1,J(o,n))))*Jw}function Op(e,t,r,n,o){let a=te(qr(n,nt(t,r))),s=te([1-a[0]*a[0],-a[0]*a[1],-a[0]*a[2]]),i=le(a,s),c=p=>[J(p,s),J(p,i),J(p,a)],l=p=>oe(oe(Q(s,p[0]),Q(i,p[1])),Q(a,p[2])),u=e.points,m=c(u.spinAxis),d=Hs({uprightUpper:c(u.uprightUpper),uprightLower:c(u.uprightLower),wheelCenter:c(u.wheelCenter),spinAxis:m,tieOuter:c(u.tieOuter),loadedRadius:o.loadedRadius,patchShift:o.patchShift&&YV(o.patchShift,e.metrics.toe/Jw,Math.atan2(m[0],m[1]))});return{caster:d.caster,kpi:d.kpi,scrubRadius:d.scrubRadius,mechanicalTrail:d.mechanicalTrail,scrubAtWheel:d.scrubAtWheel,trailAtWheel:d.trailAtWheel,kingpinOffset:d.kingpinOffset,casterOffset:d.casterOffset,kingpinGround:l(d.kingpinGround),contactPatch:l(d.contactPatch),elbow:l([d.contactPatch[0],d.kingpinGround[1],d.kingpinGround[2]]),kingpinAtHub:l(d.kingpinAtHub)}}function YV(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 Vp(e,t){let r=eF(t);if(r===ny)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 Qn(e,t,r){let n=Vp({heave:0,pitch:0,roll:0,steer:0},r);return e-gf(n,[t,0,0],En(r.vehicle.config))}var WV=180/Math.PI;function ay(e,t){return!e.valid||!e.ic?!1:Math.hypot(e.ic[0]-e.cp[0],e.ic[1]-e.cp[1])<=t}function Bp(e,t,r){let n=nt(t,e.vehicle.config),o=Vt(e,r),a=am(e,t,o[t]),s=a.at("uprightUpper"),i=a.at("uprightLower"),c=a.at("contactPatch"),l=a.at("wheelCenter"),u=w=>{let C=a.velocity(w);return[C[0],C[2]]},m=u(c),d=u(l),p=[c[0],c[2]],h=[l[0],l[2]];if(!a.solved)return{ic:null,line:null,cp:p,wc:h,road:[1,0],swingArmAngleDeg:NaN,tanTheta:NaN,tanThetaHub:NaN,valid:!1,unsolved:!0,sinAngle:0};let f=qc(e,{FL:o.FL.ground,FR:o.FR.ground,RL:o.RL.ground,RR:o.RR.ground}),b=Math.hypot(f[0],f[2]),g=[f[0]/b,f[2]/b],y=[g[1],-g[0]],x=w=>{let C=w[0]*g[0]+w[1]*g[1];return Math.abs(C)>1e-9?-(w[0]*y[0]+w[1]*y[1])/C:0},k=a.omega[1],v=Math.hypot(m[0],m[1]),R=Math.abs(k)*1e9>v?[p[0]+m[1]/k,p[1]-m[0]/k]:null,A=R?(w=>{let C=[s[0]-w[0],s[2]-w[1]],L=[i[0]-w[0],i[2]-w[1]];return Math.abs(C[0]*L[1]-C[1]*L[0])/(Math.hypot(...C)*Math.hypot(...L))})(R):0;if(!(Math.abs(m[0]*g[0]+m[1]*g[1])>1e-9))return{ic:R,line:null,cp:p,wc:h,road:y,swingArmAngleDeg:0,tanTheta:0,tanThetaHub:0,valid:!1,sinAngle:A};let F=[m[1]/v,-m[0]/v],T=R?[R[0]-p[0],R[1]-p[1]]:[n.isFront?-1:1,0],P=F[0]*T[0]+F[1]*T[1]<0?[-F[0],-F[1]]:F,S=x(m);return{ic:R,line:P,cp:p,wc:h,road:y,swingArmAngleDeg:Math.atan(S)*WV,tanTheta:S,tanThetaHub:x(d),valid:!0,sinAngle:A}}function rF(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 UV=180/Math.PI,XV=Math.PI/180,sy=.5,$p=2,iy=.25,qV={heave:0,pitch:0,roll:0,steer:0},QV={FL:"FR",FR:"FL",RL:"RR",RR:"RL"},Gp=e=>e.ok?e.state:{...e.nearest,converged:!1};function cy(e,t,r){return t.state?t.solved===!1?{...t.state,converged:!1}:t.state:Gp(we(e,t.travel,t.steer,void 0,r))}var nF=new WeakMap;function oF(e,t){let r=e.ctx[t],n=Qe(e.vehicle,t).config.loadedRadius,o=sr(n,e.kc,t),a=nF.get(r);a||(a=new Map,nF.set(r,a));let s=a.get(o);if(!s){let i=In(t,e.vehicle.config,qV,e.vehicle);s=Gp(we(r,i.travel,i.steer,void 0,o===n?void 0:{loadedRadius:o})),a.set(o,s)}return s}var Hr=(e,t)=>!e||!e.lo.converged||!e.hi.converged?NaN:(t(e.hi)-t(e.lo))/(2*e.step),aF=(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 iF(e,t,r,n,o){let a=e.vehicle.config,s=ka(r),i=Qe(e.vehicle,r),c=nt(r,a),l=e.ctx[r],u=Vt(e,t),m=u[r],d={travel:m.travel,steer:m.steer},p=m.rigid?void 0:{loadedRadius:m.loadedRadius},h=cy(l,m,p),f=oF(e,r),b={lo:Gp(we(l,d.travel-sy,d.steer,void 0,p)),hi:Gp(we(l,d.travel+sy,d.steer,void 0,p)),step:sy},g=c.isFront?{lo:qe(l,h.beta,d.steer-$p,void 0,p),hi:qe(l,h.beta,d.steer+$p,void 0,p),step:$p}:null,y=N=>{let Y=Vt(e,{...t,roll:t.roll+N*XV})[r];return cy(l,Y,Y.rigid?void 0:{loadedRadius:Y.loadedRadius})},x={lo:y(-iy),hi:y(iy),step:iy},k=JV(e,t,r,c.isFront,u,g),v=Wt(h.points.contactPatch,c),R=Wt(f.points.contactPatch,c),M=Math.abs(v[1])-Math.abs(R[1]),A=QV[r],F=u[A],T=cy(e.ctx[A],F,F.rigid?void 0:{loadedRadius:F.loadedRadius}),P=T.converged?M+Math.abs(T.points.contactPatch[1])-Math.abs(oF(e,A).points.contactPatch[1]):NaN,S=o??Ir(e,t,s),w=sm(S,Ot(i)),C=w?null:xM(S),L=c.sideSign>0?S.icRight:S.icLeft,E=L?Math.hypot(L[0]-v[1],L[1]-v[2]):1/0,_=Bp(e,r,t),O=_.ic?Math.hypot(_.ic[0]-_.cp[0],_.ic[1]-_.cp[1]):1/0,I=rF(_,s,a.wheelbase,n),z=-Hr(b,N=>N.points.damperLength),B=i.config.springRate,V=Hr(x,N=>N.metrics.camber),j=qc(e,{FL:u.FL.ground,FR:u.FR.ground,RL:u.RL.ground,RR:u.RR.ground}),q=e.kc?.loadCase,K=N=>q?Op(N,r,a,j,{loadedRadius:m.loadedRadius,patchShift:q.patchShift[r]}):N.metrics,D=K(h);return{id:r,converged:h.converged,travel:h.travel,camber:h.metrics.camber,camberRoad:oy(h.points.spinAxis,r,a,j),toe:h.metrics.toe,caster:D.caster,kpi:D.kpi,scrubRadius:D.scrubRadius,mechanicalTrail:D.mechanicalTrail,scrubAtWheel:D.scrubAtWheel,trailAtWheel:D.trailAtWheel,kingpinOffset:D.kingpinOffset,casterOffset:D.casterOffset,steeringArm:h.metrics.steeringArm,camberGain:Hr(b,N=>N.metrics.camber),bumpSteer:Hr(b,N=>N.metrics.toe),trackScrubRate:Hr(b,N=>Math.abs(Wt(N.points.contactPatch,c)[1])),casterGain:Hr(b,N=>K(N).caster),kpiGain:Hr(b,N=>K(N).kpi),scrubGain:Hr(b,N=>K(N).scrubRadius),trailGain:Hr(b,N=>K(N).mechanicalTrail),...c.isFront?{camberPerSteer:aF(g,N=>N.metrics.camber,N=>N.metrics.toe),steerJacking:-aF(g,N=>N.points.contactPatch[2],N=>N.metrics.toe),...k!==void 0?{steerLoad:k}:{}}:{},rollCamber:V,camberRecovery:-100*c.sideSign*V,rollSteer:c.sideSign*Hr(x,N=>N.metrics.toe),halfTrackChange:M,trackChange:P,longitudinal:v[0]-R[0],rollCentreHeight:C?C.heightAboveGround:S.heightAboveGround,rollCentreHeightChassis:(C?C.height:S.height)-Qn(0,c.axleX,e),rollCentreLateral:S.lateralAlongGround,rollCentreValid:S.valid,rollCentreUsable:w,rollCentreHeightUsable:w||C!==null,rollCentreSinAngle:S.sinAngle,fvsaLength:E,svsaLength:O,swingArmAngle:_.swingArmAngleDeg,svsaUsable:ay(_,a.wheelbase),svsaSinAngle:_.sinAngle,...s==="front"?{antiDive:I.brake,antiLift:I.drive}:{antiSquat:I.drive,antiLift:I.brake},decoupled:i.config.actuation==="decoupled",mcpherson:i.config.layout==="mcpherson",springRate:B,motionRatio:z,wheelRate:B*z*z,damperLength:h.points.damperLength,damperTravel:f.points.damperLength-h.points.damperLength,...ZV(i,f.points.damperLength,h.points.damperLength,e.kc?.curve[r].spring?.law),rockerAngle:i.config.actuation==="direct"?0:(h.points.rockerAngle-f.points.rockerAngle)*UV,groundDisplacement:m.rigid?h.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 ZV(e,t,r,n){if(e.config.actuation==="decoupled")return{};let o=n?{droop:n.droopStated?n.droop:null,bump:n.bump}:Sa(t,e.config.coilover),a=t-r;return{...o.droop!==null?{damperToExtended:a-o.droop}:{},...o.bump!==null?{damperToClosed:o.bump-a}:{}}}function JV(e,t,r,n,o,a){if(!a||!n)return;let s=jl(e,t,"front"),i=e.kc;if(!s||!i)return;let c=["FL","FR"],l=[0,0],u=[0,0],m={lo:[],hi:[]},d=0;for(let f=0;f<2;f++){let b=c[f],g=o[b],y=e.ctx[b],x=g.rigid?void 0:{loadedRadius:g.loadedRadius},R=(b==="FR"?1:-1)*(r==="FR"?1:-1)*$p,M=g.state?{q:[...g.state.pose.t,...g.state.pose.omega],phi:g.state.points.rockerAngle}:void 0,A=Lt(we(y,g.travel,g.steer-R,M,x)),F=Lt(we(y,g.travel,g.steer+R,M,x));if(!A||!F)return NaN;l[f]=F.points.contactPatch[2]-A.points.contactPatch[2],u[f]=Qr(i.curve[b],g.travel,F.points.damperLength)-Qr(i.curve[b],g.travel,A.points.damperLength),m.lo.push(A),m.hi.push(F),b===r&&(d=F.metrics.toe-A.metrics.toe)}let p=i.elements?.front;if(p){let f=[o.FL.travel,o.FR.travel],b=ei(p,f,[m.hi[0],m.hi[1]]),g=ei(p,f,[m.lo[0],m.lo[1]]);u[0]+=b[0]-g[0],u[1]+=b[1]-g[1]}return Math.abs(d)>1e-9?s([0,0],l,u)[r==="FL"?0:1]/d:NaN}function Qc(e,t,r,n,o){return iF(e,t,r==="front"?"FL":"RL",n,o)}function ly(e,t,r,n){let o=Qc(e,t,"front",r,n?.front),a=Qc(e,t,"rear",r,n?.rear);return{front:o,rear:a,wheelbaseChange:o.longitudinal-a.longitudinal}}function Kp(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),Qn(Math.min(n.zMin,n.zMax),i,t)],max:[s,Math.max(n.yMin,n.yMax),Qn(Math.max(n.zMin,n.zMax),i,t)]}})}var Jo=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],lr=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],xt=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],yr=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Zc=e=>Math.sqrt(yr(e,e));function e5(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 t5(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=>yr(r,e)>=yr(r,t)?e:t,samples:()=>Array.from({length:41},(r,n)=>lr(e,xt(Jo(t,e),n/40)))}}function r5(e,t,r,n){let o=xt(t,1/(Zc(t)||1)),a=n/2,s=o.map(i=>r*Math.sqrt(Math.max(0,1-i*i))+a*Math.abs(i));return{min:Jo(e,s),max:lr(e,s),support:i=>{let c=yr(i,o),l=Jo(i,xt(o,c)),u=Zc(l),m=u>1e-12?xt(l,r/u):[0,0,0];return lr(lr(e,xt(o,c>=0?a:-a)),m)},samples:()=>{let i=Math.abs(o[0])<.9?[1,0,0]:[0,1,0],c=Jo(i,xt(o,yr(i,o))),l=xt(c,1/Zc(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 d of[-1,-.5,0,.5,1]){let p=lr(e,xt(o,d*a));m.push(p);let h=Math.abs(d)===1?[.5,1]:[1];for(let f of h)for(let b=0;b<72;b++){let g=b/72*2*Math.PI;m.push(lr(p,lr(xt(l,f*r*Math.cos(g)),xt(u,f*r*Math.sin(g)))))}}return m}}}function n5(e){let t=e[0],r=e.slice(1).map(c=>Jo(c,t)),n=r.length;if(n===0)return{v:t,w:[1]};let o=r.map(c=>r.map(l=>yr(c,l))),a=r.map(c=>-yr(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 d=c;d<n;d++)o[u][d]-=m*o[c][d];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=lr(i,xt(r[c],s[c]));return{v:i,w:[1-s.reduce((c,l)=>c+l,0),...s]}}function o5(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=n5(a.map(c=>c.w));if(!s||s.w.some(c=>c<-1e-9))continue;let i=yr(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 a5(e,t){let r=s=>{let i=e.support(s),c=t.support(xt(s,-1));return{w:Jo(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=lr(c,xt(u.a,s.weights[m])),l=lr(l,xt(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=yr(i,i);if(c<1e-12)return n(a,0);let l=r(xt(i,-1));if(c-yr(i,l.w)<=1e-9*Math.max(1,c))return n(a,Math.sqrt(c));let u=o5([...a.keep,l]);if(u.keep.length===4)return n(u,0);if(yr(u.v,u.v)>=c-1e-12)return n(a,Math.sqrt(c));a=u}return n(a,Zc(a.v))}function s5(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 i5(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 uF={linkRadius:8,mountAllowance:15},c5=(e,t,r)=>e.z0+e.dzdx*t+e.dzdy*r;function l5(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 l5(Vp({heave:0,pitch:0,roll:0,steer:0},e),En(e.vehicle.config))}var u5=[{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 m5(e){return u5.filter(t=>t.name==="strut"?e.mcpherson:t.name==="pushrod"?!e.direct:!(e.mcpherson&&t.name.startsWith("upper")))}var p5=(e,t,r)=>e.every((n,o)=>n>=t.min[o]-r&&n<=t.max[o]+r);function cF(e,t,r){let n=Jo(t,e),o=Zc(n);return o>1e-9?lr(e,xt(n,r/o)):e}function lF(e,t){let r=null;for(let{shape:n,pad:o,part:a,pose:s}of t){if(r&&i5(e,n)-o>=r.distance)continue;let i=a5(e,n),c=i.distance>0?null:s5(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:cF(i.onB,i.onA,o),box:i.onA}:c?{part:cF(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 d5(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:xt(a.reduce((c,l)=>lr(c,l),[0,0,0]),1/a.length)}}function pF(e,t){return{...d5(e,r=>r[2]-c5(t,r[0],r[1])),road:t}}function dF(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 f5(e,t){let r=e.map(o=>({pose:o,part:`${o.corner} tyre`,pad:0,shape:r5(o.g.wheelCenter,o.g.spinAxis,o.corner[0]==="F"?t.tyreRadius.front:t.tyreRadius.rear,t.tyreWidth)})),n=e.flatMap(o=>m5(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:t5(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 h5(e,t,r){let n=e5(e.min,e.max),o=t.links.filter(a=>!p5(a.inboard,e,r.mountAllowance+r.linkRadius));return{tyre:lF(n,t.tyres),link:lF(n,o)}}function fF(e,t,r){let n=f5(t,r);return e.map(o=>({boxId:o.id,...h5(o,n,r)}))}var RF=152,vF={travelSteps:9,rackSteps:5},ea=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Sn=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Jc=(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]],xr=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]},kF=180/Math.PI,b5=[[1,0,0],[0,1,0],[0,0,1]],hF=(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]],g5=(e,t)=>[Sn(e[0],t),Sn(e[1],t),Sn(e[2],t)];function bF(e,t,r){let n=xr(ea(t,e)),o=xr(Jc(n,ea(r,e)));return[n,Jc(o,n),o]}function y5(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 uy(e,t,r,n){let o=xr(ea(t,e)),a=b=>{let g=ea(b,e),y=Sn(g,o);return[g[0]-y*o[0],g[1]-y*o[1],g[2]-y*o[2]]},s=xr(a(r)),i=xr(a(n)),c=Sn(Jc(s,i),o),u=Sn(s,i),m=c,d=1-u,[p,h,f]=o;return[[d*p*p+u,d*p*h+m*f,d*p*f-m*h],[d*p*h-m*f,d*h*h+u,d*h*f+m*p],[d*p*f+m*h,d*h*f-m*p,d*f*f+u]]}var x5=(e,t)=>Math.acos(Math.max(-1,Math.min(1,Sn(xr(e),xr(t)))))*kF;function R5(e,t){return{upright:y5(bF(e.uprightLower,e.tieOuter,e.wheelCenter),bF(t.uprightLower,t.tieOuter,t.wheelCenter)),uca:t.mcpherson?null:uy(t.ucaFront,t.ucaRear,e.uprightUpper,t.uprightUpper),lca:uy(t.lcaFront,t.lcaRear,e.uprightLower,t.uprightLower),rocker:t.direct?null:uy(t.rockerPivotA,t.rockerPivotB,e.rockerToPushrod,t.rockerToPushrod)}}function MF(e){let t=xr(e[0]),r=Math.abs(t[0])<.9?[1,0,0]:[0,1,0],n=xr(Jc(t,r)),o=Jc(t,n),a=e.map(h=>{let f=xr(h);return[Sn(f,n),Sn(f,o)]}),s=h=>{let f=Math.cos(h),b=Math.sin(h),g=0;for(let[y,x]of a)g=Math.max(g,Math.abs(y*f+x*b));return g},i=Math.PI/180,c=0,l=1/0;for(let h=0;h<180;h++){let f=s(h*i);f<l&&([c,l]=[h*i,f])}let u=c-i,m=c+i,d=(Math.sqrt(5)-1)/2;for(let h=0;h<30;h++){let f=m-d*(m-u),b=u+d*(m-u);s(f)<s(b)?m=b:u=f}let p=Math.min(l,s((u+m)/2));return Math.asin(Math.min(1,p))*kF}function gF(e){let t=null;for(let r of e)Number.isFinite(r.angle)&&(!t||r.angle>t.angle)&&(t=r);return t}var v5={upright:"upright",lowerArm:"lca",upperArm:"uca"};function SF(e,t,r,n){let o=t.map(m=>R5(e,m)),a=xr(ea(e.uprightUpper,e.uprightLower)),s=m=>Math.max(0,...o.map(d=>d[m]?x5(hF(d.upright,a),hF(d[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,d,p)=>{let h=[ea(e[d],e[m])];for(let f=0;f<t.length;f++){let b=p(o[f]);if(!b)return null;h.push(g5(b,ea(t[f][d],t[f][m])))}return h},l=[["tie rod, inner end",c("tieInner","tieOuter",()=>b5)],["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[v5[r]])]);let u=l.filter(m=>m[1]!==null).map(([m,d])=>({joint:m,angle:MF(d)}));return{ballJoint:gF(i),rodEnd:gF(u)}}function k5(e){let t=(r,n)=>{let o=sr(n,e.kc,r),a=e.kc?.input.corners[r];return a&&a.tyreRate>0&&Number.isFinite(a.tyreRate)?o+Math.max(0,a.staticLoad)/a.tyreRate:o};return{front:t("FL",e.vehicle.front.config.loadedRadius),rear:t("RL",e.vehicle.rear.config.loadedRadius)}}function AF(e,t){let r=xu(t);return{...uF,tyreRadius:k5(e),tyreWidth:r!==null?r*1e3:RF}}var yF={front:["FL","FR"],rear:["RL","RR"]},xF=(e,t,r)=>r<=1||t===e?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function my(e,t,r,n,o=vF){let a=e.vehicle,[s]=yF[t],i=nm(e,s,0,0)?.geometry;if(!i)return null;let c=Kp(a.chassis?.boxes??[],{vehicle:a,kc:e.kc}),l=t==="front"?Bt(a.front.config):0,u=l>0?xF(-l,l,Math.max(3,o.rackSteps|1)):[0],m=xF(Math.min(0,r.min),Math.max(0,r.max),Math.max(2,o.travelSteps)),d=[];for(let b of c.length?yF[t]:[s])for(let g of m)for(let y of u){let x=nm(e,b,g,y)?.geometry;x&&d.push({corner:b,travel:g,rack:y,g:x})}let p=null;if(c.length){for(let b of fF(c,d,AF(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 h=a[t].config,f=SF(i,d.filter(b=>b.corner===s).map(b=>b.g),h.pushrodAttach,h.rodType==="pull"?"pullrod":"pushrod");return{chassis:p,...f}}var Hp=Math.PI/180,el={travelSteps:9,heaveSteps:5,rollSteps:4,rackSteps:6},zp={travelMin:-25,travelMax:25,rollMaxDeg:3,rollAtLimitDeg:2.5};function M5(e){let t=e.params;return{cgHeight:t.cg_height?It({...t,surveyedRadiusFront:e.vehicle.front.config.loadedRadius,surveyedRadiusRear:e.vehicle.rear.config.loadedRadius}).cgHeight:300,...cb(t),drive:ab(t)}}function wF(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 py(e,t=el,r=zp,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=Jt(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=Jt(s)},m=C=>C==="front"?"FL":"RL",d=C=>{let L=u();if(!L.kc)return;let E=i(C).config.loadedRadius,_=sr(E,L.kc,m(C));return _===E?void 0:{loadedRadius:_}},p=(C,L)=>-ti(u(),m(C),L),h=new Map,f=new Map,b=new Map,g=new Map,y=new Map,x=new Map,k=new Map,v=new Map,R=new Map,M=null,A=()=>{if(M)return M;u();let C=M5(e);return M=l!==null&&Number.isFinite(l)?{...C,cgHeight:l}:C},F,T,P=()=>{if(T!==void 0)return T;let C=Jl(u().ctx.FL,Bt(s.front.config));return T=C?eu(C):null,T},S=(C,L,E)=>{if(C.has(L))return C.get(L)??null;let _=E();return C.set(L,_),_};return{car:e,density:t,envelope:r,get failure(){return o},axisLength:(C,L)=>{let E=i(C),_=E.hardpoints;return L==="uca"&&E.config.layout==="mcpherson"?NaN:L==="uca"?Ee(_.ucaFront,_.ucaRear):Ee(_.lcaFront,_.lcaRear)},linkLength:C=>{let L=i(C).hardpoints;return Ee(L.tieInner,L.tieOuter)},compliance:C=>S(f,C,()=>uh(i(C))??null),sweep:C=>S(h,C,()=>{let L;try{L=ot(i(C),{travelMin:r.travelMin,travelMax:r.travelMax,steps:t.travelSteps})}catch{return a(500,`the ${C} travel sweep threw`)}if(!L.covered){let _=L.samples.map(z=>z.travel),O=Math.max(..._)-Math.min(..._),I=r.travelMax-r.travelMin;return a(Math.max(0,I-O),`the ${C} linkage reaches only ${O.toFixed(0)} mm of the ${I.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(_=>!_.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 _=P();if(_)return a(_.violation,_.reason)}return L}),rcHeave:C=>S(b,C,()=>{let L=[],E=[],_=Math.max(2,t.heaveSteps);try{for(let I=0;I<_;I++){let z=r.travelMin+(r.travelMax-r.travelMin)*I/(_-1);L.push(z),E.push(Ir(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=wF(E,I=>Math.abs(L[I]-L[I-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=[],_=Math.max(2,t.rollSteps);try{for(let I=0;I<_;I++){let z=r.rollMaxDeg*I/(_-1);L.push(z),E.push(Ir(u(),{heave:0,pitch:0,roll:z*Hp,steer:0},C))}}catch{return a(500,`the ${C} roll-centre construction threw in roll`)}let O=wF(E,I=>Math.abs(E[I].cpLeft?.[0]??0)*Math.abs(L[I]-L[I-1])*Hp);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=Qn(0,nt(m(C),s.config).axleX,u()),y.set(C,L)),L},steer:()=>{if(F!==void 0)return F;try{F=zf(u(),{steerMax:Bt(s.front.config),steps:t.rackSteps})}catch{F=a(500,"the steering sweep threw")}let C=F?.filter(L=>!L.converged).length??0;if(F&&C>0){let L=P();F=L?a(L.violation,L.reason):a(100+10*C,`${C} of ${F.length} steering solves did not converge`)}return F??null},solveAt:(C,L,E=0)=>S(x,`${C}:${L}:${E}`,()=>{try{let _=we(u().ctx[m(C)],L,E,void 0,d(C));return _.ok?_.state:_.why==="unconverged"?a(100,`the ${C} corner did not solve at ${L.toFixed(0)} mm of travel`):a(100+Math.abs(_.travelMiss),`the ${C} corner reaches only ${(L+_.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 ly(u(),C,A())}catch{return a(500,"the derived readout threw")}}),readoutAtTravel:(C,L)=>S(R,`${C}:${L}`,()=>{try{return Qc(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*Hp),_=u();if(!_.kc)return E;try{let O=Vt(_,{heave:0,pitch:0,roll:L*Hp,steer:0}),I=C==="front"?Math.max(O.FL.travel,O.FR.travel):Math.max(O.RL.travel,O.RR.travel);return Number.isFinite(I)?I: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,_={min:r.travelMin,max:r.travelMax};return my(u(),C,_,E)??a(100,`the ${C} corner did not solve at its design ride`)}catch{return a(500,`the ${C} keep-outs threw`)}})}}var S5=t0();function dy(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=tp(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?Dc([c],a.track,a.numerics,Fc(s),a.settings,S5)[0]:yc(c,s,{numerics:a.numerics,standingStart:l,lapCounts:u});o={};for(let d of s.metrics)vl(d)&&(o[d.key]=d.value(m,void 0))}}catch{o=null}return r.set(n,o),o}}}var Yp=.01;function A5(e,t){return t.bump!==null&&e>t.bump-Yp?{at:"closed",past:Math.max(0,e-t.bump)}:t.droopStated&&e<t.droop+Yp?{at:"toppedOut",past:Math.max(0,t.droop-e)}:t.seat!==null&&e<t.seat+Yp?{at:"unseated",past:Math.max(0,t.seat-e)}:{at:"free",past:0}}var FF=e=>({droop:e.droop,droopStated:e.droopStated,bump:e.bump,seat:e.holdsLoad&&Number.isFinite(e.free)?e.free:null}),w5=[["front","FL","FR"],["rear","RL","RR"]];function hy(e,t){let r=[];for(let[n,o,a]of w5){let s=[t[o],t[a]];for(let m of[o,a]){let d=e.curve[m],p=d.spring?.law;if(!d.spring||!p)continue;let h=Sf(d,t[m]);h===null||!Number.isFinite(h)||r.push(fy(m,n,n,h,d.spring.length0-h,FF(p),!0))}let i=e.elements?.[n];if(!i)continue;let c=i.heave?.law;if(c){let m=ov(i,s),d=i.read.heave?.span0,p=n==="front"?"heaveFront":"heaveRear";r.push(fy(p,p,n,m,d!==void 0?d-m:null,FF(c),i.carriesLoad))}let l=i.rollStop,u=l?av(i,s):null;if(l&&u!==null){let m=l.length0-u,d=n==="front"?"rollFront":"rollRear",p={droop:l.droop??-1/0,droopStated:l.droop!==null,bump:l.bump,seat:null};r.push(fy(d,d,n,m,u,p,i.carriesLoad))}}return r}function fy(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,...A5(n,a),bumpStated:a.bump!==null,bounds:s}}var PF=Math.PI/180;function by(e,t,r,n){let o=t.speedKmh/3.6,a=af(e,o,t.axG,Pn(e,t.ayG,0));if(!a||!e.aero)return null;let s=e.wheelbase,i=Ra(e.aero,s),c=(f,b)=>Math.atan((b-f)/s)/PF,l={},u={};for(let f of wr)l[f]=r.corners[f].travel,u[f]=r.corners[f].ground;let m=n.kc?hy(n.kc,l):[],d=e.aero.model,p=a.downFront+a.downRear,h=d?{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:LF(d,s,a.hFront,a.hRear)}:null;return{front:{height:a.hFront,...CF(m,"front")},rear:{height:a.hRear,...CF(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:h,clearance:F5(n,u)}}function CF(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 LF(e,t,r,n){let o=(a,[s,i])=>Math.min(a-s,i-a);if(Qx(e)){let{x:a,y:s}=ba(e),i=[a[0],a[a.length-1]],c=[s[0],s[s.length-1]];return Cn(e)?TF(e.frame,t,i,c,r,n):Math.min(o(r,i),o(n,c))}return Fl(e)?TF(e.frame,t,e.range.h,e.range.pitch,r,n):Math.min(o(r,e.range.hFront),o(n,e.range.hRear))}function TF(e,t,r,n,o,a){let s=ga(e,t,o,a),i=l=>t*Math.tan(l*PF),c=a-o;return Math.min(s.h-r[0],r[1]-s.h,c-i(n[0]),i(n[1])-c)}function F5(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=ar(e.vehicle,!0)/2,c=ar(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 wr){let g=[1,l[b][0],l[b][1]];for(let y=0;y<3;y++){m[y]+=g[y]*t[b];for(let x=0;x<3;x++)u[y][x]+=g[y]*g[x]}}let d=dF(u,m);if(!d)return null;let p=mF(n),h={z0:p.z0+d[0],dzdx:p.dzdx+d[1],dzdy:p.dzdy+d[2]},f=null;for(let b of Kp(r,n)){let g=pF(b,h);(!f||g.height<f.height)&&(f={height:g.height,volume:b.name})}return f}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 C5={front:"front",rear:"rear",heaveFront:"front",heaveRear:"rear",rollFront:"front",rollRear:"rear"};function tl(e,t,r,n){let o=pm(e,t);return tm.some(s=>{if(C5[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 gy(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 jp=Math.PI/180,Up=1e-6;function EF(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 rl(e){let t=e.measured;if(t)return EF(t.travel,t.camber);let r=te(e.config.spinAxis);return-Math.asin(Math.max(-1,Math.min(1,r[2])))/jp}function nl(e){let t=e.measured;if(t)return EF(t.travel,t.toe);let[r,n]=e.config.spinAxis;return Math.atan2(r,n)/jp}function yy(e,t){let r=Math.abs(t.camber)>=Up,n=Math.abs(t.toe)>=Up;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=(rl(e)+t.camber)*jp,l=(nl(e)+t.toe)*jp,[u,m]=n?[Math.sin(l),Math.cos(l)]:[a/i,s/i],d=[u*Math.cos(c),m*Math.cos(c),-Math.sin(c)];return{...e,config:{...e.config,spinAxis:d}}}function Xp(e){let t=e&&typeof e=="object"?e.value:void 0;return typeof t=="number"&&Number.isFinite(t)?t:void 0}function T5(e,t){let r=t;return{front:Xp(r.camber_front_deg)??rl(e.front),rear:Xp(r.camber_rear_deg)??rl(e.rear)}}function P5(e,t){let r=t;return{front:Xp(r.toe_front_deg)??nl(e.front),rear:Xp(r.toe_rear_deg)??nl(e.rear)}}function L5(e){return{camber:{front:rl(e.front),rear:rl(e.rear)},toe:{front:nl(e.front),rear:nl(e.rear)}}}var DF=new WeakMap;function D5(e,t){let r=L5(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)<Up&&Math.abs(u.toe)<Up;if(o(n.front)&&o(n.rear))return e;let a=`${t.camber.front}|${t.camber.rear}|${t.toe.front}|${t.toe.rear}`,s=DF.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&&yy(m,n[ka(u)])])):void 0,l={...e,front:yy(e.front,n.front),rear:yy(e.rear,n.rear),...c?{corners:c}:{}};return s||DF.set(e,s=new Map),s.size>=16&&s.clear(),s.set(a,l),l}function Ms(e,t){return t?D5(e,{camber:T5(e,t),toe:P5(e,t)}):e}var E5=9.81;function Ss(e){let t=mo(e),r=Math.max(0,e.unsprungPerCorner)*E5,n=a=>{let s=a==="FL"||a==="FR",i=s?"front":"rear",c=lt(e,i),l=c>0?c:1/0,u=Bd(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:cr(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 IF=new WeakMap;function I5(e){let t=Ms(e.vehicle,e.params);if(t===e.vehicle)return e;let r=IF.get(e);return(!r||r.vehicle!==t)&&IF.set(e,r={...e,vehicle:t}),r}function Zn(e,t={}){let r=I5(e),n=q0(r,t),o=t.assemble?()=>{let m=n.dynInput();if(!m)throw new Error("the car did not assemble");return{kc:Ss(m),cgHeight:m.cgHeight}}:void 0,a=py(r,t.density,t.envelope,o),s=ry(r,n,t),i=dy(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(d=>d.id===m)??null,platformAt:m=>{let d=`${m.speedKmh}|${m.ayG}|${m.axG}`,p=l.get(d);if(p!==void 0)return p;let h=n.poseAt(m),f=n.dynInput(),b=null;if(h&&f)try{b=by(f,m,h,a.contexts())}catch{b=null}return l.set(d,b),b}}}var _5=["x","y","z"],N5=/^(line|plane)\((-?\d+),(-?\d+)\)([uv]?)$/,_F=Math.PI/18e3,NF=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],OF=(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]],O5=e=>Math.hypot(e[0],e[1],e[2]),xy=(e,t)=>[e[0]*t,e[1]*t,e[2]*t];function Ry(e){let t=O5(e);return t>1e-9?xy(e,1/t):null}function V5(e,t){let r=e*_F,n=t*_F;return[Math.cos(n)*Math.cos(r),Math.cos(n)*Math.sin(r),Math.sin(n)]}function ur(e){let t=e.lastIndexOf(".");if(t<0)return null;let r=N5.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:V5(Number(r[2]),Number(r[3]))},coord:n==="line"?"along":r[4]}}function VF(e){let t=Ry(OF([0,0,1],e))??[1,0,0];(t[0]<-1e-9||Math.abs(t[0])<=1e-9&&t[1]<0)&&(t=xy(t,-1));let r=Ry(OF(e,t))??[0,1,0];return(r[2]<-1e-9||Math.abs(r[2])<=1e-9&&r[1]<0)&&(r=xy(r,-1)),[t,r]}function vy(e){if(e.coord==="along")return e.shape.dir;let[t,r]=VF(e.shape.dir);return e.coord==="u"?t:r}function BF(e,t){let r=ur(t);if(!r)return;let n=_5.map(u=>e[`${r.point}.${u}`]);if(n.some(u=>!u))return;let o=vy(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=>NF(s(u),o),write:(u,m)=>{let d=s(u),p=m-NF(d,o),h=u;for(let f of a)h=n[f].write(h,d[f]+p*o[f]);return h},...c?{supersededBy:c}:{}}}var As=["x","y","z"];var B5=/^(?:hp\.(?:front|rear)\.\w+|(?:heave|roll)\.(?:front|rear)\.(?:outer|inner|anchor))$/;function ta(e){let t=e.lastIndexOf("."),r=e.slice(0,t);if(t<0||!B5.test(r))return null;let n=e.slice(t+1);if(n==="x"||n==="y"||n==="z")return{point:r,axis:n};let o=ur(e);return o?{point:r,axis:o.coord}:null}var ol="*";function ky(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 My=e=>e?.reads==="speed"||e?.reads==="operating",Sy=e=>e?.reads==="lateral"||e?.reads==="operating";function ra(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 qp(e,t){return e?.appliesAt?t.find(r=>!e.appliesAt(r)):t[0]}function ws(e,t,r){let n=r?.stateId?e.stateOf(r.stateId):qp(t,e.states)??null;return n&&!t.appliesAt?.(n)?n:null}function Ft(e,t,r){let n=`${t.id}@${ra(r)}`,o=e.values.get(n);if(o!==void 0)return o;let a;try{a=r?.courseId===ol&&t.reads==="course"?$5(e,t,r):r?.stateId===Kr&&t.reads==="state"?G5(e,t,r):t.read(e,r)}catch{a=NaN}return e.values.set(n,a),a}function $5(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:Ft(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 G5(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:Ft(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 Ay(e){let t={mean:"weighted mean",max:"highest",min:"lowest",span:"span"};return e?.acrossStates?`every state, ${t[e.acrossStates]}`:"every state"}function it(e){return`${e.quantity??e.groupShort??e.group} \xB7 ${e.label}`}var K5={front:"Front",rear:"Rear"},al={heave:0,pitch:0,roll:0,steer:0},$F="RC height (chassis) [mm]";function GF(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 H5(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 sl=e=>e.length?Math.max(...e)-Math.min(...e):NaN;function KF(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 HF(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 Fs(e,t,r){let n=e.stateOf(t?.stateId),o=n?e.poseAt(n):null;return o?r(o):NaN}var il=(e,t)=>`${e==="front"?"F":"R"}${t}`,zF=e=>e==="L"?"R":"L";function YF(e){let t=K5[e],r=R=>`kin.${e}.${R}`,n=(R,M)=>{let A=R.sweep(e);return A?{x:A.samples.map(F=>F.travel),y:A.samples.map(M)}:{x:[],y:[]}},o=R=>e==="front"?R.vehicle.front:R.vehicle.rear,a=R=>R.params[e==="front"?"heaveFrontDesign":"heaveRearDesign"],s=R=>R.params[e==="front"?"arbFrontDesign":"arbRearDesign"],i=e==="front"?"the front axle":"the rear axle";function c(R){return o(R).config.actuation==="decoupled"?`${i} is decoupled, with no corner damper \u2014 read its heave and roll elements`:null}function l(R){let M=a(R);return M&&M.design.kind!=="none"?null:`${i} has no heave element`}function u(R){let M=a(R);return M?.design.kind==="coil"&&M.linkage?null:`${i} has no heave element on a linkage`}function m(R){let M=s(R);return M&&M.design.kind!=="none"?null:`${i} has no roll element`}function d(R){let M=s(R);return M?.linkage&&M.design.kind!=="none"&&M.design.kind!=="direct"?null:`${i} has no roll element on a linkage`}let p=R=>{if(u(R.car))return null;let M=R.sweep(e);return M?Tf(o(R.car),a(R.car).linkage,M.samples):null},h=R=>{if(d(R.car))return null;let M=R.sweep(e);if(!M)return null;let A=s(R.car),F=wf(o(R.car),A.linkage,A.design.kind,M.samples),T=F.atDesign<0?-1:1;return{travel:F.travel,ratio:F.ratio.map(P=>P*T),atDesign:F.atDesign*T}},f=R=>R.readout(al)?.[e],b=R=>R.readoutAtTravel(e,R.envelope.travelMax),g=R=>{let M=n(R,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=R=>{let M=n(R,A=>A.metrics.toe);return M.x.length?{key:r("bumpSteer"),title:`${t} toe vs travel`,xLabel:"travel [mm]",yLabel:"toe [\xB0]",...M}:null},x=[{id:r("rcStatic"),group:`${t} roll centre`,label:"static height",unit:"mm",scale:30,scope:e,cost:"cheap",read:R=>R.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:R=>{let M=R.rcHeave(e);return M?H5(M.at,M.rc.map(A=>A.height)):NaN},curve:R=>{let M=R.rcHeave(e);return M?{key:r("rcHeaveWorst"),title:`${t} roll-centre height vs wheel travel`,xLabel:"travel [mm]",yLabel:$F,x:M.at,y:M.rc.map(A=>A.height-R.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:R=>{let M=R.rcRoll(e);return M?sl(M.rc.map(A=>A.height)):NaN},curve:R=>{let M=R.rcRoll(e);return M?{key:r("rcRollSpan"),title:`${t} roll-centre height vs body roll`,xLabel:"roll [\xB0]",yLabel:$F,x:M.at,y:M.rc.map(A=>A.height-R.roadUnder(e))}:null}},{id:r("rcLateralSpan"),group:`${t} roll centre`,label:"lateral migration over roll",unit:"mm",scale:50,scope:e,cost:"cheap",read:R=>{let M=R.rcRoll(e);return M?sl(M.rc.map(A=>A.lateral)):NaN},curve:R=>{let M=R.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:R=>{let M=R.rcHeave(e),A=R.rcRoll(e);return!M||!A?NaN:Math.min(...M.rc.map(F=>F.sinAngle),...A.rc.map(F=>F.sinAngle))},curve:R=>{let M=R.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:R=>f(R)?.fvsaLength??NaN},{id:r("complianceSteer"),group:`${t} compliance`,label:"compliance steer",unit:"\xB0/kN lateral",scale:.05,scope:e,cost:"readout",read:R=>(R.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:R=>(R.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:R=>(R.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:R=>(R.compliance(e)?.toePerMz??0)*1e5},{id:r("staticCamber"),group:`${t} camber & toe`,label:"static camber",unit:"\xB0",scale:1,scope:e,cost:"cheap",read:R=>{let M=R.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:R=>R.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:R=>f(R)?.camberGain??NaN,curve:R=>g(R)},{id:r("rollCamber"),group:`${t} camber & toe`,label:"camber gain in roll",unit:"\xB0/\xB0",scale:.2,scope:e,cost:"readout",read:R=>f(R)?.rollCamber??NaN},{id:r("rollCamberRecovery"),group:`${t} camber & toe`,label:"camber recovery in roll",unit:"%",scale:20,scope:e,cost:"readout",read:R=>f(R)?.camberRecovery??NaN},{id:r("bumpSteerDesign"),group:`${t} camber & toe`,label:"bump steer at design",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:R=>f(R)?.bumpSteer??NaN,curve:R=>y(R)},{id:r("rollSteer"),group:`${t} camber & toe`,label:"roll steer",unit:"\xB0/\xB0",scale:.1,scope:e,cost:"readout",read:R=>f(R)?.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:R=>{let M=n(R,A=>A.metrics.toe);return M.x.length?GF(M.x,M.y):NaN},curve:R=>y(R)},{id:r("camberGain"),group:`${t} camber & toe`,label:"camber gain, RMS over the travel",unit:"\xB0/mm",scale:.02,scope:e,cost:"cheap",read:R=>{let M=n(R,A=>A.metrics.camber);return M.x.length?GF(M.x,M.y):NaN},curve:R=>g(R)},{id:r("camberSpan"),group:`${t} camber & toe`,label:"camber range over travel",unit:"\xB0",scale:1,scope:e,cost:"cheap",read:R=>sl(n(R,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:R=>sl(n(R,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:R=>{let M=R.solveAt(e,R.travelAtRoll(e,R.envelope.rollAtLimitDeg)),A=R.solveAt(e,0);return!M||!A?NaN:Math.abs(M.metrics.camber-A.metrics.camber+R.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:(R,M)=>Fs(R,M,A=>A.camber[il(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:(R,M)=>Fs(R,M,A=>A.camber[il(e,zF(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:(R,M)=>Fs(R,M,A=>A.corners[il(e,A.outer)].bumpToe)},{id:r("caster"),group:`${t} upright`,label:"caster",unit:"\xB0",scale:5,scope:e,cost:"cheap",read:R=>R.solveAt(e,0)?.metrics.caster??NaN},{id:r("kpi"),group:`${t} upright`,label:"kingpin inclination",unit:"\xB0",scale:5,scope:e,cost:"cheap",read:R=>R.solveAt(e,0)?.metrics.kpi??NaN},{id:r("scrubRadius"),group:`${t} upright`,label:"scrub radius",unit:"mm",scale:20,scope:e,cost:"cheap",read:R=>R.solveAt(e,0)?.metrics.scrubRadius??NaN},{id:r("mechanicalTrail"),group:`${t} upright`,label:"mechanical trail",unit:"mm",scale:20,scope:e,cost:"cheap",read:R=>R.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:R=>R.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:R=>R.solveAt(e,0)?.metrics.casterOffset??NaN},{id:r("steeringArm"),group:`${t} upright`,label:"steering arm",unit:"mm",scale:20,scope:e,cost:"cheap",read:R=>R.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:R=>f(R)?.casterGain??NaN},{id:r("kpiGain"),group:`${t} upright`,label:"kingpin inclination gain in bump",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:R=>f(R)?.kpiGain??NaN},{id:r("scrubGain"),group:`${t} upright`,label:"scrub radius gain in bump",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:R=>f(R)?.scrubGain??NaN},{id:r("trailGain"),group:`${t} upright`,label:"mechanical trail gain in bump",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:R=>f(R)?.trailGain??NaN},{id:r("motionRatio"),group:`${t} rates`,label:"motion ratio at design",unit:"-",scale:.2,scope:e,cost:"cheap",unavailable:c,read:R=>{if(c(R.car))return NaN;let M=R.sweep(e);return M?HF(M.samples.map(A=>A.travel),M.samples.map(A=>A.metrics.motionRatio??NaN))??NaN:NaN},curve:R=>{if(c(R.car))return null;let M=n(R,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:R=>{if(c(R.car))return NaN;let M=R.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 F=A.reduce((T,P)=>T+P,0)/A.length;return F>0?(Math.max(...A)-Math.min(...A))/F:NaN}},{id:r("wheelRate"),group:`${t} rates`,label:"wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:c,read:R=>{if(c(R.car))return NaN;let M=R.sweep(e);return M?HF(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:R=>p(R)?.atDesign??NaN,curve:R=>{let M=p(R);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:R=>KF(p(R)?.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:R=>l(R.car)||!R.sweep(e)?NaN:rs(R.car.vehicle,R.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:d,read:R=>h(R)?.atDesign??NaN,curve:R=>{let M=h(R);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:d,read:R=>KF(h(R)?.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:R=>m(R.car)||!R.sweep(e)?NaN:To(R.car.vehicle,R.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:R=>R.axisLength(e,"uca")},{id:r("lcaAxisLength"),group:`${t} package`,label:"lower arm pivot-axis length",unit:"mm",scale:80,scope:e,cost:"geometry",read:R=>R.axisLength(e,"lca")},{id:r("linkLength"),group:`${t} package`,label:"tie/toe link length",unit:"mm",scale:100,scope:e,cost:"geometry",read:R=>R.linkLength(e)},{id:r("trackScrubRate"),group:`${t} package`,label:"track scrub rate",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:R=>R.readout(al)?.[e].trackScrubRate??NaN},{id:r("trackChange"),group:`${t} package`,label:"track change at full bump",unit:"mm",scale:2,scope:e,cost:"readout",read:R=>b(R)?.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:(R,M)=>Fs(R,M,A=>A.corners[il(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:(R,M)=>Fs(R,M,A=>A.corners[il(e,zF(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:R=>c(R.car)?NaN:sl(n(R,M=>M.metrics.damperLength).y),curve:R=>{if(c(R.car))return null;let M=n(R,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"&&x.push({id:r("camberPerSteer"),group:`${t} camber & toe`,label:"camber change with steer",unit:"\xB0/\xB0",scale:.05,scope:"front",cost:"readout",read:R=>f(R)?.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:R=>f(R)?.steerJacking??NaN}),e==="front"?x.push({id:r("antiDive"),group:`${t} anti geometry`,label:"anti-dive",unit:"%",scale:20,scope:"front",cost:"readout",read:R=>R.readout(al)?.front.antiDive??NaN}):x.push({id:r("antiSquat"),group:`${t} anti geometry`,label:"anti-squat (driving)",unit:"%",scale:20,scope:"rear",cost:"readout",read:R=>R.readout(al)?.rear.antiSquat??NaN},{id:r("antiLift"),group:`${t} anti geometry`,label:"anti-lift (braking)",unit:"%",scale:20,scope:"rear",cost:"readout",read:R=>R.readout(al)?.rear.antiLift??NaN});let k=R=>{let M=R.slice(t.length+1);return M.charAt(0).toUpperCase()+M.slice(1)};return[...new Set(x.map(R=>R.group))].flatMap(R=>x.filter(M=>M.group===R)).map(R=>({...R,quantity:`${t} \xB7 ${k(R.group)}`}))}function WF(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 z5=[{id:"kin.front.ackermannCentre",group:"Steering",label:"Ackermann near centre",unit:"%",scale:25,scope:"front",cost:"cheap",read:e=>WF(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=>WF(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}}],Y5=[{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)=>Fs(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}}],wy=[...YF("front"),...YF("rear"),...z5,...Y5];var W5={front:"Front",rear:"Rear"};function UF(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 jF(e){let t=W5[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=>UF(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 Fy=[...jF("front"),...jF("rear")];var JF={front:"Front",rear:"Rear"},XF=e=>Zo("side",e),j5=e=>Zo("drive",e)&&Zo("brake",e)?"neither brakes nor drives":null;function U5(e,t,r,n){let o=ws(e,t,r),a=o?e.tyreAt(o):null;return a?n(a):NaN}function Cs(e,t){let r={...e,read:(n,o)=>U5(n,r,o,t)};return r}var qF=e=>e?100*e.lossCamber:NaN,QF=e=>e&&!e.lifted?e.camber-e.wants:NaN;function ZF(e){let t=JF[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:XF,unavailable:s=>Tp(s.params,e)},a=[Cs({...o,id:r("camberErrorOuter"),label:"camber error at the outer wheel",unit:"\xB0",scale:.5},s=>QF(s.side(e)?.wheels[0])),Cs({...o,id:r("camberErrorInner"),label:"camber error at the inner wheel",unit:"\xB0",scale:.5},s=>QF(s.side(e)?.wheels[1])),Cs({...o,id:r("sideLossCamber"),label:"side grip lost to camber",unit:"%",scale:1},s=>qF(s.side(e))),Cs({...n,appliesAt:XF,id:r("sideLossToe"),label:"side grip lost to the toe split",unit:"%",scale:1},s=>100*s.toeLoss(e)),Cs({...n,appliesAt:j5,unavailable:s=>U0(s.params,e),id:r("longLossCamber"),label:"drive and brake grip lost to camber",unit:"%",scale:1},s=>qF(s.long(e)))];return e==="front"&&a.push(Cs({...n,appliesAt:s=>Zo("ackermann",s),id:r("ackermannError"),label:"Ackermann against the tyre",unit:"%",scale:25},s=>s.ackermann())),a}var Cy=[...ZF("front"),...ZF("rear")],X5=/^tyre\.(front|rear)\.(camberErrorOuter|camberErrorInner|sideLossCamber|longLossCamber)$/;function Ty(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=X5.exec(a.id);if(!i)continue;let c=i[1],l=i[2]==="longLossCamber",u=s?.stateId==="*"?e.states.filter(m=>!a.appliesAt?.(m)):[ws(e,a,s)].filter(m=>!!m);for(let m of u){let d=`${c}|${m.id}|${l}`;if(r.has(d))continue;let p=e.tyreAt(m),h=p?l?p.long(c):p.side(c):null;if(!h)continue;let{lo:f,hi:b,stated:g}=h.range,y=g?`the ${o(f)} \u2026 ${o(b)} its data covers`:`the \xB1${b.toFixed(0)}\xB0 read without a stated range`,x=M=>l?M===0?"left":"right":M===0?"outer":"inner",k=h.wheels.findIndex(M=>M.atEdge),v=h.wheels.findIndex(M=>M.outside&&!M.lifted),R=[];k>=0&&R.push(`the ${JF[c].toLowerCase()} ${x(k)} tyre wants ${o(h.wheels[k].wants)}, the edge of ${y}, and may want more`),v>=0&&R.push(`the ${x(v)} wheel has ${o(h.wheels[v].camber)}, past it, and is read at ${o(h.wheels[v].read)}`),R.length&&r.set(d,`In the ${n(m)} ${R.join("; ")}.`)}}return[...r.values()]}function Py(e,t){let r=e.appliesAt?.(t);return r?`is read at ${t.name}, which ${r}`:null}var q5={front:"Front",rear:"Rear"};function Q5(e,t,r,n){let o=ws(e,t,r),a=o?e.platformAt(o):null;return(a?n(a):null)??NaN}function mr(e,t){let r={...e,read:(n,o)=>Q5(n,r,o,t)};return r}var Ly={cost:"cheap",reads:"state"},Z5={unavailable:e=>Wp(e.params)};function eC(e){let t=q5[e],r=o=>`platform.${e}.${o}`,n={...Ly,group:`${t} platform`,quantity:`${t} \xB7 Platform`,scope:e};return[mr({...n,id:r("rideHeight"),label:"ride height at a state",unit:"mm",scale:5,acrossStates:"min"},o=>o[e].height),mr({...n,id:r("toBumpStop"),label:"travel left to the bump stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>tl(o.vehicle,o.params,e,"bump")},o=>o[e].toBump),mr({...n,id:r("toDroopStop"),label:"travel left to the droop stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>tl(o.vehicle,o.params,e,"droop")},o=>o[e].toDroop)]}var Qp={...Ly,group:"Platform",scope:"car"},cl={...Ly,...Z5,group:"Aero platform",groupShort:"Aero",scope:"car"},Dy=[...eC("front"),...eC("rear"),mr({...Qp,id:"platform.rake",label:"rake at a state",unit:"\xB0",scale:.2,acrossStates:"span"},e=>e.rakeDeg),mr({...Qp,id:"platform.pitch",label:"pitch at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.pitchDeg),mr({...Qp,id:"platform.roll",label:"body roll at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.rollDeg),mr({...Qp,id:"platform.groundClearance",label:"ground clearance at a state",unit:"mm",scale:5,acrossStates:"min",unavailable:e=>gy(e.vehicle)},e=>e.clearance?.height),mr({...cl,id:"platform.balance",label:"balance at a state",unit:"%",scale:1,acrossStates:"span"},e=>e.aero?.balance),mr({...cl,id:"platform.clA",label:"downforce Cl\xB7A at a state",unit:"m\xB2",scale:.1,acrossStates:"mean"},e=>e.aero?.clA),mr({...cl,id:"platform.cdA",label:"drag Cd\xB7A at a state",unit:"m\xB2",scale:.05,acrossStates:"mean"},e=>e.aero?.cdA),mr({...cl,id:"platform.dataMargin",label:"margin to the model\u2019s data",unit:"mm",scale:5,acrossStates:"min"},e=>e.aero?.dataMargin),mr({...cl,id:"platform.loopMargin",label:"aero-elastic margin, 1 \u2212 loop gain",unit:"-",scale:.1,acrossStates:"min"},e=>e.aero?.loopMargin)];var tC={understeer:"operating",yawFreq:"speed",yawZeta:"speed",yawStiffness:"operating",steeringTorque:"operating",steeringTorqueGradient:"operating"};function Rt(e,t,r,n="cheap"){let o=xg[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,...tC[e]?{reads:tC[e]}:{},read:(a,s)=>{let i=a.dynInput(),c=a.dynCtx(s);return i&&c?o.compute(i,c):NaN}}}var J5=[Rt("understeer","Handling \u2014 balance",.1),Rt("tlltdFront","Handling \u2014 balance",5),Rt("rollStiffFront","Handling \u2014 balance",5)],e3=[Rt("yawFreq","Handling \u2014 response",.5),Rt("yawZeta","Handling \u2014 response",.2),Rt("stabilitySpeed","Handling \u2014 response",50),Rt("yawStiffness","Handling \u2014 response",2e4,"trim")],t3=[Rt("steeringTorque","Steering feel",1,"trim"),Rt("steeringTorqueGradient","Steering feel",2,"trim")],r3=[Rt("rollGradient","Ride & body",.5),Rt("pitchGradient","Ride & body",.5),Rt("rideFreqFront","Ride & body",.5),Rt("rideFreqRear","Ride & body",.5),Rt("rollFreq","Ride & body",.5),Rt("pitchFreq","Ride & body",.5),Rt("zetaFront","Ride & body",.2),Rt("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}],Ey=[...J5,...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 Iy=[{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 rC=new WeakMap;function Zp(e){let t=rC.get(e);return t||(t=e.metrics.filter(vl).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}}),rC.set(e,t),t)}var _y=bs.flatMap(Zp);var Jp=[...wy,...Fy,...Cy,...Dy,...Ey,...Iy,..._y],Ts=Object.fromEntries(Jp.map(e=>[e.id,e]));var nC={all:Jp,byId:Ts},oC=new WeakMap;function Rr(e=[]){if(e.length===0)return nC;let t=oC.get(e);if(t)return t;let r=Yg(e).filter(n=>!gs(n.id)).flatMap(Zp);return t=r.length?{all:[...Jp,...r],byId:{...Ts,...Object.fromEntries(r.map(n=>[n.id,n]))}}:nC,oC.set(e,t),t}var l3=9.81;function ed(e,t=e.tireModel,r=e.tireModelRear){if(!t)return e;e=u3(e,t,r);let n=e.m.value*l3/4,o=Eo(e,t,r),a=_e(o.front).rollingRadius(n),s=o.rear===o.front?a:_e(o.rear).rollingRadius(n),i=m3(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 u3(e,t,r){let n=Eo(e,t,r),o=_e(n.front).verticalStiffness(),a=n.rear===n.front?o:_e(n.rear).verticalStiffness();if(!(o>0&&a>0))return e;let s=o===a?"the fitted tyre\u2019s own vertical rate":`the fitted tyres\u2019 own vertical rates: front ${aC(o)}, rear ${aC(a)} N/mm`;return{...e,...e.tire_vertical_rate?{tire_vertical_rate:{...e.tire_vertical_rate,value:o}}:{},readouts:{...e.readouts,tire_vertical_rate:s}}}var aC=e=>Math.round(e*10)/10;function m3(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 ll=180/Math.PI,Ps=Math.PI/180,p3=.2;function td(e,t){let r=G(t,e);return te(r[0]<0?cf(r):r)}var rd=e=>({side:Math.atan2(e[2],e[0])*ll,plan:Math.atan2(e[1],e[0])*ll}),nd=(e,t)=>te([1,Math.tan(t*Ps),Math.tan(e*Ps)]),ul=e=>Math.abs(e[0])>=p3,od=(e,t)=>Math.atan(t/Math.max(e,1))*ll,ad=(e,t)=>Math.tan(t*Ps)*Math.max(e,1);var Jn=["side","plan","clock","len"],rr={uca:{fore:"ucaFront",aft:"ucaRear",ball:"uprightUpper"},lca:{fore:"lcaFront",aft:"lcaRear",ball:"uprightLower"}},ml={uca:"upper arm",lca:"lower arm"},d3=1,sC=(e,t)=>td(e[rr[t].fore],e[rr[t].aft]);function iC(e){let t=te(G(sf,Q(e,J(sf,e))));return{e1:t,e2:le(e,t)}}function Ny(e,t){let r=sC(e,t);if(!ul(r))return`the ${ml[t]}'s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it`;let n=rr[t],o=Dn(e[n.ball],e[n.fore],r);return Math.hypot(...G(o,e[n.ball]))>=d3?null:`the ${ml[t]}'s ball joint sits on its own pivot axis, so the arm has no length to swing on`}function An(e,t){let r=rr[t],n=e[r.ball],o=sC(e,t),a=Dn(n,e[r.fore],o),s=G(a,n),i=Math.hypot(s[0],s[1],s[2]),{e1:c,e2:l}=iC(o),u=i>0?Q(s,1/i):c;return{...rd(o),clock:Math.atan2(J(u,l),J(u,c))*ll,len:i,sFront:J(G(e[r.fore],a),o),sRear:J(G(e[r.aft],a),o)}}function Oy(e,t){let r=nd(e.side,e.plan),{e1:n,e2:o}=iC(r),a=oe(Q(n,Math.cos(e.clock*Ps)),Q(o,Math.sin(e.clock*Ps))),s=oe(t,Q(a,e.len));return{fore:oe(s,Q(r,e.sFront)),aft:oe(s,Q(r,e.sRear))}}function cC(e,t,r,n){let o=rr[t],a={...An(e,t),[r]:n},{fore:s,aft:i}=Oy(a,e[o.ball]);return{...e,[o.fore]:s,[o.aft]:i}}function lC(e,t){return t==="clock"?e.len:Math.abs(e.sFront-e.sRear)/2}function sd(e,t,r){return t==="len"?r:od(lC(e,t),r)}function Vy(e,t,r){return t==="len"?r:ad(lC(e,t),r)}var na=["side","plan","atY","atZ"],zr={fore:"rockerPivotA",aft:"rockerPivotB"},f3=5,uC=e=>td(e.rockerPivotA,e.rockerPivotB);function Ls(e){return Math.hypot(...G(e.rockerPivotB,e.rockerPivotA))<f3?"the rocker\u2019s two pivots are the same point, so there is no axis to describe":ul(uC(e))?null:"the rocker\u2019s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it"}function eo(e){let t=uC(e),r=ul(t)?t:[1,0,0],n=e.rockerPivotA,o=oe(n,Q(r,-n[0]/r[0]));return{...rd(r),atY:o[1],atZ:o[2],sA:J(G(n,o),r),sB:J(G(e.rockerPivotB,o),r)}}function By(e){let t=nd(e.side,e.plan),r=[0,e.atY,e.atZ];return{a:oe(r,Q(t,e.sA)),b:oe(r,Q(t,e.sB))}}function mC(e,t,r){if(Ls(e))return e;let{a:n,b:o}=By({...eo(e),[t]:r});return{...e,rockerPivotA:n,rockerPivotB:o}}var pC=e=>Math.abs(e.sA-e.sB)/2;function $y(e,t,r){return t==="side"||t==="plan"?od(pC(e),r):r}function Gy(e,t,r){return t==="side"||t==="plan"?ad(pC(e),r):r}var kr={front:"Front",rear:"Rear"},vr=["x","y","z"],tt=(e,t)=>t==="front"?e.front:e.rear,pl=(e,t,r)=>t==="front"?{...e,front:r}:{...e,rear:r},dC=[{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"}]}],fC={damperChassis:"strut top mount",pushrodOuter:"strut lower mount"},oa=30;function h3(e){let t=[];for(let r of["front","rear"]){let n=tt(e.vehicle,r).config.layout==="mcpherson";for(let o of dC)for(let{key:a,label:s}of o.keys){let i=n&&fC[a]||s;for(let c=0;c<3;c++)t.push({id:`hp.${r}.${a}.${vr[c]}`,group:`${kr[r]} hardpoints \u2014 ${o.kind}`,label:`${i} ${vr[c]}`,scope:kr[r],unit:"mm",defaultSpan:oa,read:l=>tt(l.vehicle,r).hardpoints[a][c],write:(l,u)=>{let m=tt(l.vehicle,r),d=[...m.hardpoints[a]];d[c]=u;let p={...m.hardpoints,[a]:d};return{...l,vehicle:pl(l.vehicle,r,{...m,hardpoints:p})}}})}}return t}var b3={side:"axis side-view angle",plan:"axis plan-view angle",clock:"arm clock angle",len:"effective arm length"},g3={side:"\xB0",plan:"\xB0",clock:"\xB0",len:"mm"};function y3(e){let t=[];for(let r of["front","rear"]){let n=tt(e.vehicle,r).config.layout==="mcpherson";for(let o of["uca","lca"]){let a=tt(e.vehicle,r).hardpoints,s=Ny(a,o)?null:An(a,o);for(let i of Jn)t.push({id:`arm.${r}.${o}.${i}`,group:`${kr[r]} ${n?"arm axes":"wishbone axes"}`,label:`${ml[o]} \u2014 ${b3[i]}`,scope:kr[r],unit:g3[i],defaultSpan:s?sd(s,i,oa):oa,read:c=>An(tt(c.vehicle,r).hardpoints,o)[i],write:(c,l)=>{let u=tt(c.vehicle,r),m=cC(u.hardpoints,o,i,l);return{...c,vehicle:pl(c.vehicle,r,{...u,hardpoints:m})}}})}}return t}var x3={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"},R3={side:"\xB0",plan:"\xB0",atY:"mm",atZ:"mm"};function v3(e){let t=[];for(let r of["front","rear"]){let n=tt(e.vehicle,r).hardpoints,o=Ls(n)?null:eo(n);for(let a of na)t.push({id:`rocker.${r}.${a}`,group:`${kr[r]} rocker axis`,label:`rocker \u2014 ${x3[a]}`,scope:kr[r],unit:R3[a],defaultSpan:o?$y(o,a,oa):oa,read:s=>eo(tt(s.vehicle,r).hardpoints)[a],write:(s,i)=>{let c=tt(s.vehicle,r),l=mC(c.hardpoints,a,i);return{...s,vehicle:pl(s.vehicle,r,{...c,hardpoints:l})}}})}return t}var id={front:"heaveFrontDesign",rear:"heaveRearDesign"},Ky={front:"arbFrontDesign",rear:"arbRearDesign"};function k3(e,t){return{heave:e.config.actuation==="decoupled"?"heave element":"third spring",roll:t?.design.kind==="coil"?"roll shock":"anti-roll bar"}}var cd=e=>/^(heave|roll)\.(front|rear)\.(outer|inner|anchor)\.[xyz]$/.test(e);function M3(e){let t=[];for(let r of["front","rear"]){let n=tt(e.vehicle,r),o=e.params[id[r]],a=e.params[Ky[r]],s=k3(n,a),i=h=>h.params[id[r]],c=h=>h.params[Ky[r]],l=(h,f)=>({...h,params:{...h.params,[id[r]]:f}}),u=(h,f)=>({...h,params:{...h.params,[Ky[r]]:f}}),m={group:`${kr[r]} heave & roll elements`,scope:kr[r]},d=(h,f,b,g,y)=>{for(let x of b)t.push({...m,id:`${h}.${vr[x]}`,label:`${f} ${vr[x]}`,unit:"mm",defaultSpan:oa,read:k=>g(k)[x],write:(k,v)=>{let R=[...g(k)];return R[x]=v,y(k,R)}})},p=(h,f,b,g,y)=>{t.push({...m,id:h,label:f,unit:"N/mm",defaultSpan:Math.max(5,b*.4),read:g,write:y})};if(o?.design.kind==="coil"){if(o.linkage){let h=b=>i(b).linkage;d(`heave.${r}.outer`,`${s.heave} eye`,[0,1,2],b=>h(b).outer,(b,g)=>l(b,{...i(b),linkage:{...h(b),outer:g}})),o.linkage.mount?.kind==="chassis"&&d(`heave.${r}.anchor`,`${s.heave} chassis anchor`,[0,2],b=>h(b).mount.anchor,(b,g)=>l(b,{...i(b),linkage:{...h(b),mount:{kind:"chassis",anchor:g}}}))}if(typeof o.design.rate=="number"){let h=f=>i(f).design;p(`heave.${r}.rate`,`${s.heave} spring rate (@element)`,o.design.rate,f=>h(f).rate,(f,b)=>l(f,{...i(f),design:{...h(f),rate:b}}))}}if(a&&a.design.kind!=="none"){if(a.linkage&&a.design.kind!=="direct"){let f=x=>c(x).linkage,b=_n(n,a.linkage,a.design.kind),[g,y]=b?["left arm eye","right arm eye"]:["drop-link pickup","arm tip"];d(`roll.${r}.outer`,`${s.roll} ${g}`,[0,1,2],x=>f(x).outer,(x,k)=>u(x,{...c(x),linkage:{...f(x),outer:k}})),d(`roll.${r}.inner`,`${s.roll} ${y}`,[0,1,2],x=>f(x).inner,(x,k)=>u(x,{...c(x),linkage:{...f(x),inner:k}}))}let h=a.design;if(h.kind==="coil"&&typeof h.rate=="number"){let f=b=>c(b).design;p(`roll.${r}.rate`,`${s.roll} spring rate (@element)`,h.rate,b=>f(b).rate,(b,g)=>u(b,{...c(b),design:{kind:"coil",rate:g}}))}else h.kind==="direct"&&p(`roll.${r}.wheelRate`,`${s.roll} rate (@wheel)`,h.wheelRate,f=>c(f).design.wheelRate,(f,b)=>u(f,{...c(f),design:{kind:"direct",wheelRate:b}}))}}return t}var S3=[{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 A3(e){let t=[];for(let r of["front","rear"]){let n=tt(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:kr[r],unit:"N/mm",defaultSpan:Math.max(500,l*.4),read:u=>i(tt(u.vehicle,r).compliance??{})??l,write:(u,m)=>{let d=tt(u.vehicle,r),p={...d,compliance:c(d.compliance??{},Math.max(1,m))};return{...u,vehicle:pl(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}`,`${F3[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"},F3={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 C3(){return S3.map(e=>({id:`cfg.${e.axle}.${e.field}`,group:e.group,label:e.label,scope:kr[e.axle],unit:e.unit,defaultSpan:e.span(e.fallback),read:t=>tt(t.vehicle,e.axle).config[e.field]??e.fallback,write:(t,r)=>{let n=tt(t.vehicle,e.axle),o={...n,config:{...n.config,[e.field]:r}};return{...t,vehicle:pl(t.vehicle,e.axle,o)}}}))}function T3(e){let t=ho(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=>ho(c.params.steeringSystem)[n],write:(c,l)=>({...c,params:{...c.params,steeringSystem:ho({...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 P3(e){let t=Do(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=bm[`${n}.${s}`];return{id:`driveline.${n}.${s}`,group:"Differential",label:c.label.charAt(0).toLowerCase()+c.label.slice(1),scope:kr[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:hm({...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 L3(e){if(Di(e.params)!=="hydraulic")return[];let t=[{id:"brakeSetup.barFront",group:"Brakes",label:`${fb("barFront").toLowerCase()}, front share`,unit:"-",defaultSpan:.05,read:a=>an(a.params.brakeSetup).barFront,write:(a,s)=>({...a,params:{...a.params,brakeSetup:an({...an(a.params.brakeSetup),barFront:s})}})}];if(!e.params.brakeModel)return t;let r=Lr(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:db(a.circuit?`${a.circuit}.${String(a.key)}`:a.key),unit:s,defaultSpan:i,read:c=>n(Lr(c.params.brakeModel),a),write:(c,l)=>{let u=Lr(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:Lr(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 hC=e=>!!e&&typeof e=="object"&&"value"in e&&"label"in e;function bC(e){let t={...e};for(let r of Object.keys(t)){let n=t[r];hC(n)&&(t[r]={...n})}return t}function D3(e){let t=[];for(let r of YM(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 hC(s)?s.value:NaN},write:(a,s)=>{let i=bC(a.params);return vm(i,n.label,s),{...a,params:i}}})}return t}function gC(e){let t={};for(let i of["front","rear"]){if(!tt(e.vehicle,i).measured)continue;let l="this axle is described by measured curves, so its linkage is not solved";for(let u of dC)for(let{key:m}of u.keys)for(let d of vr)t[`hp.${i}.${m}.${d}`]={why:l};for(let u of["uca","lca"])for(let m of Jn)t[`arm.${i}.${u}.${m}`]={why:l};for(let u of na)t[`rocker.${i}.${u}`]={why:l};for(let u of["heave.outer","heave.anchor","roll.outer","roll.inner"]){let[m,d]=u.split(".");for(let p of vr)t[`${m}.${i}.${d}.${p}`]={why:l}}t[`cfg.${i}.springRate`]={why:"the measured curve set carries its own spring rate"}}let r=["rockerPivotA","rockerPivotB","rockerToPushrod","rockerToDamper"];for(let i of["front","rear"]){if(tt(e.vehicle,i).config.actuation!=="direct")continue;let c="this axle is direct-acting \u2014 there is no bell-crank";for(let l of r)for(let u of vr)t[`hp.${i}.${l}.${u}`]={why:c};for(let l of na)t[`rocker.${i}.${l}`]={why:c}}for(let i of["front","rear"]){let c=tt(e.vehicle,i);if(c.measured||c.config.actuation!=="decoupled")continue;let l="this axle is decoupled \u2014 the corner damper is out of circuit";for(let u of["rockerToDamper","damperChassis"])for(let m of vr)t[`hp.${i}.${u}.${m}`]={why:l,useInstead:`heave.${i}.outer.${m}`};t[`cfg.${i}.springRate`]={why:"a decoupled axle has no corner spring \u2014 its elements hold it up",useInstead:`heave.${i}.rate`}}for(let i of["front","rear"]){let c=tt(e.vehicle,i),l=e.params[id[i]]?.linkage;if(c.measured||!l||l.attach!=="rocker"||l.mount?.kind==="chassis")continue;let u=c.hardpoints,m=[0,1,2].map(p=>u.rockerPivotB[p]-u.rockerPivotA[p]),d=Math.hypot(m[0],m[1],m[2]);if(d>0)for(let p=0;p<3;p++)Math.abs(m[p]/d)<1-1e-12||(t[`heave.${i}.outer.${vr[p]}`]={why:`the rocker shaft runs along ${vr[p]} \u2014 this only slides the eye along it`})}for(let i of["front","rear"]){let c=tt(e.vehicle,i);if(c.measured||c.config.layout!=="mcpherson")continue;let l="this axle is a McPherson strut \u2014 there is no upper arm";for(let u of["ucaFront","ucaRear","uprightUpper"])for(let m of vr)t[`hp.${i}.${u}.${m}`]={why:l,useInstead:`hp.${i}.damperChassis.${m}`};for(let u of Jn)t[`arm.${i}.uca.${u}`]={why:l};for(let u of["link.ucaFront","link.ucaRear","bush.ucaFront","bush.ucaRear"])t[`kc.${i}.${u}`]={why:l}}for(let i of["front","rear"]){let c=tt(e.vehicle,i);if(c.measured)continue;for(let u of["uca","lca"]){if(u==="uca"&&c.config.layout==="mcpherson")continue;let m=Ny(c.hardpoints,u);if(m)for(let d of Jn)t[`arm.${i}.${u}.${d}`]={why:m,useInstead:`hp.${i}.${rr[u].fore}.z`}}let l=Ls(c.hardpoints);if(l&&c.config.actuation!=="direct")for(let u of na)t[`rocker.${i}.${u}`]={why:l,useInstead:`hp.${i}.${zr.fore}.z`}}let n=[["arbFrontDesign","param.arb_front","the front anti-roll bar design in Vehicle Dynamics","front","roll"],["arbRearDesign","param.arb_rear","the rear anti-roll bar design in Vehicle Dynamics","rear","roll"],["heaveFrontDesign","param.heave_spring_front","the front third-spring design","front","heave"],["heaveRearDesign","param.heave_spring_rear","the rear third-spring design","rear","heave"]];for(let[i,c,l,u,m]of n){let d=e.params[i];if(!d?.design||d.design.kind==="none")continue;let p=d.design.kind==="direct"?`${m}.${u}.wheelRate`:`${m}.${u}.rate`;t[c]={why:`computed from ${l}`,useInstead:p}}let o=e.params.aeroModelId||e.params.aeroModel?Zb:Jb;for(let[i,c]of Object.entries(o))t[`param.${i}`]={why:c};if(e.params.batteryModelId||e.params.batteryModel)for(let[i,c]of Object.entries(ym))t[`param.${i}`]={why:c};for(let[i,c]of Object.entries(xm(e.params)))t[`param.${i}`]={why:c};let a={...ed(e.params).readouts,...e.sessionAir?{rho:fp}:{}};for(let[i,c]of Object.entries(a)){let l=`param.${i}`;!(l in t)&&!(l in xC)&&(t[l]={why:c})}for(let[i,c]of Object.entries(eg(e.params)))t[`param.${i}`]={why:c};let s=Di(e.params)==="hydraulic";for(let[i,c]of Object.entries(Iu(e.params)))t[`param.${i}`]=s?{why:c,useInstead:"brakeSetup.barFront"}:{why:c};return t}function yC(e){let t={...xC,...gC(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[...h3(e),...y3(e),...v3(e),...M3(e),...C3(),...T3(e),...L3(e),...P3(e),...A3(e),...D3(e.params)].map(r)}var E3={spring_front:"cfg.front.springRate",spring_rear:"cfg.rear.springRate"},xC=Object.fromEntries(Object.entries(Qb).map(([e,t])=>[`param.${e}`,{why:t,useInstead:E3[e]}])),bt=e=>e.scope?`${e.scope} \xB7 ${e.label}`:e.label;function _t(e){let t={};for(let n of yC(e))t[n.id]=n;let r=(n,o)=>{if(typeof o!="string")return;let a=BF(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 Hy=e=>e.step!==void 0&&Number.isFinite(e.step)&&e.step>0?e.step:0,zy=e=>Hy(e)>0||(e.values?.length??0)>0,Yy=e=>e.some(zy),RC=e=>1e-9*Math.max(1,Math.abs(e.lo),Math.abs(e.hi));function vC(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=Hy(e);if(!r||!Number.isFinite(e.start))return t;let n=RC(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 kC=(e,t)=>t.map((r,n)=>e[n]&&zy(e[n])?vC(e[n],r):r);function Wy(e,t=1e3){if(e.values?.length)return e.values.length;let r=Hy(e);if(!r||!Number.isFinite(e.start))return 1/0;let n=RC(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 jy(e,t,r){let n=kC(e.variables,t),o=n.every((a,s)=>a===t[s]);return{x:n,score:o?r:tn(e,n)}}function qy(e,t){if(!e.variables.some(SC))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(AC(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 SC=e=>!!(e.fixed||e.around||e.follows)||AC(e),AC=e=>!!e.values?.length&&(e.lo!==Math.min(...e.values)||e.hi!==Math.max(...e.values));function Ct(e,t){if(!t.variables.some(SC))return t;let r=_t(e);return qy(t,n=>{let o=r[n];if(!o)return NaN;try{return o.read(e)}catch{return NaN}})}function Mr(e){return[...e.objectives,...e.constraints,...e.watches??[]]}var ud=e=>(e.metrics??Rr()).byId;function Qy(e,t){t=Ct(e,t);let r=_t(e),n=[];for(let o of t.variables){let a=r[o.id];a&&n.push({id:a.id,name:bt(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=Ct(e,t);let n=_t(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]))}),ex(e,o,t.followers,n)}function Zy(e,t,r={}){let n=t.states??[],o=n.some(c=>c.follows);if(!o&&!t.envelopeFollows)return t;let a=Zn(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,N3(r)))}catch{s=n}let i=t.envelope;if(t.envelopeFollows&&s.length){let c=s.map(f=>a.poseAt(f)).filter(f=>f!==null),l=ud(r),u=Jy(t,l),m=Mr(t).map(f=>({r:f,m:l[f.metricId]})).filter(({m:f})=>f&&f.id.startsWith("kin.")&&f.reads!=="state"&&(f.scope==="car"||u.includes(f.scope))),d=f=>{let b=Zn(e,{density:t.density,envelope:f,assemble:r.assemble,numerics:r.numerics});return m.every(({r:g,m:y})=>Number.isFinite(Ft(b,y,g.at)))},p=c.length===s.length?_3(e,H0(c,u),u):null,h=p&&m.length?I3(p,d):p;h&&!z0(h,t.envelope)&&(i=h)}return s===n&&i===t.envelope?t:{...t,states:s,envelope:i}}var ld=3;function I3(e,t){let r=(c,l)=>t({...e,travelMin:c,travelMax:l}),n=e.travelMin-ld,o=e.travelMax+ld;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+ld)),i=Math.max(1,Math.min(e.travelMax,o-ld));return s===e.travelMin&&i===e.travelMax?e:{...e,travelMin:s,travelMax:i}}function Jy(e,t){let r=new Set;for(let n of Mr(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 _3(e,t,r){if(!t)return null;let n=Ms(e.vehicle,e.params),{travelMin:o,travelMax:a}=t;for(let s of r.map(i=>n[i]))try{let i=ot(s,{travelMin:o,travelMax:a,steps:el.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 N3(e){let t=e.projectTrack?.();if(!t)return null;try{return $0(wt(t.asset,t.numerics))}catch{return null}}function ex(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 to(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 wC=(e,t="")=>t&&t!=="-"?`${e} ${t}`:`${e}`;function FC(e,t,r){let n=t??Ts[e.metricId],o=(n?it(n):e.metricId)+aa(e.at,n,r),a=s=>wC(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 aa(e,t,r){if(!e&&t?.reads!=="state")return"";e??={};let n=[];if(t?.reads==="state")if(e.stateId===Kr)n.push(Ay(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&&My(t)&&n.push(`${(e.speed*3.6).toFixed(0)} km/h`),e.ayG!==void 0&&Sy(t)&&n.push(`${e.ayG.toFixed(2)} g`),e.courseId===ol&&t?.reads==="course")n.push(ky(t));else if(e.courseId&&t?.reads==="course"){let o=r?.lap.courses.find(a=>a.id===e.courseId);o&&n.push(ty(o))}return n.length?` @ ${n.join(", ")}`:""}function CC(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 TC=5e-4;function PC(e,t){return e.cost!=="lap"&&e.cost!=="session"?0:Number.isFinite(t)?TC*Math.abs(t):0}function md(e,t,r={}){return Zn(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 pd(e,t,r={}){t=Ct(e,t);let n=Qy(e,t),o=_t(e),a=ud(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,d)=>{let p=0,h=[];for(let{spec:f,metric:b}of m){let g=Ft(d,b,f.at);if(!Number.isFinite(g))return{ok:!1,violation:d.failure?.violation??400,reason:d.failure?.reason??`${it(b)} could not be computed`};let y=to(f,g);y>0&&(p+=y/b.scale,h.push(`${FC(f,b,t)} (${wC(g.toFixed(3),b.unit)})`))}return h.length===0?Ri:{ok:!1,violation:p,reason:h.join("; ")}};return{name:"study",variables:n,build:m=>{let d=e;return t.variables.forEach((p,h)=>{let f=o[p.id];f&&(d=f.write(d,m[h]))}),d=ex(e,d,t.followers,o),{car:d,ev:md(d,t,r)}},feasible:({ev:m})=>{let d=u(i,m);if(!d.ok)return d;for(let{spec:p,metric:h}of c)Ft(m,h,p.at);for(let{spec:p,metric:h}of l)Ft(m,h,p.at);return m.failure?{ok:!1,violation:m.failure.violation,reason:m.failure.reason}:u(c,m)},terms:({ev:m})=>l.map(({spec:d,metric:p})=>{let h=Ft(m,p,d.at);return{name:it(p)+aa(d.at,p,t),raw:h,unit:p.unit,weight:d.weight,contribution:CC(d,p,h),resolution:Math.abs(d.weight)*PC(p,h)/p.scale}})}}function Uy(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 LC(e,t){if(e.variables.some(o=>o.id===t))return!0;let r=ta(t);if(!r||!As.includes(r.axis))return!1;if(e.variables.some(o=>ur(o.id)?.point===r.point))return!0;let n=Uy(t);return!!n&&e.variables.some(o=>/^(arm|rocker)\./.test(o.id)&&Uy(o.id)===n)}function O3(e,t){let r=e.followers??[],n=new Map(r.map(i=>[i.id,i.follows])),o=i=>{let c=t[i],l=ta(i);return c&&l&&As.includes(l.axis)?{name:bt({...c,label:c.label.replace(/ [xyz]$/,"")}),axis:l.axis}:{name:c?bt(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),d=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}${d(p)} cannot be moved: ${c.supersededBy.why}.`),!l)s(`no-lead:${u.name}:${i.follows}`,u.axis,p=>`${u.name}${d(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}${d(p)} cannot move with itself.`);else if(l.unit!==c.unit)s(`unit:${u.name}:${m.name}`,u.axis,p=>`${u.name}${d(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,h=>`${u.name}${d(h)} moves with ${m.name}, which itself moves with ${p.name}. Link it to ${p.name}.`)}else LC(e,i.follows)||s(`still:${u.name}:${m.name}`,u.axis,p=>`${u.name}${d(p)} moves with ${m.name}, which the study does not move${d(p)}. Free that one, or give this its own bound.`)}return[...a.values()].map(i=>i.text(i.axes.join(", ")))}function tx(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=Ct(e,t);let a=_t(e),s=[],i=ud(r),c=Mr(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=Mr(t).filter(y=>i[y.metricId]?.reads==="state");if(m.length){let y=t.states??[];if(!y.length)s.push("This study reads targets at a state and has none. Take the car\u2019s five under Conditions.");else{let x=new Set([...y.map(k=>k.id),Kr]);for(let k of m){let v=i[k.metricId];if(k.at?.stateId&&!x.has(k.at.stateId))s.push(`${it(v)} names a state this study no longer has. Point it at one of the states under Conditions.`);else if(k.at?.stateId===Kr&&!v.acrossStates)s.push(`${it(v)} is read at one state at a time, not over every state.`);else if(v.appliesAt){let R=k.at?.stateId&&k.at.stateId!==Kr?y.find(A=>A.id===k.at.stateId):void 0,M=R?Py(v,R):null;M?s.push(`${it(v)} ${M}. Point it at a state that does.`):!R&&!qp(v,y)&&s.push(`${it(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 d=new Set([...t.lap.courses.map(y=>y.id),ol]);for(let y of Mr(t))if(y.at?.courseId&&!d.has(y.at.courseId)){let x=i[y.metricId];s.push(`${x?it(x):y.metricId} names a course this study no longer has. Point it at one of the courses below.`)}u&&t.lap.ggvMode==="fast"&&t.variables.some(x=>/arb_|spring|heave_|front_mass_diss|cg_height|^hp\./.test(x.id.replace("param.","")))&&s.push("The fast grip envelope is a point mass: no load transfer, no trim. It cannot see bars, springs, roll centres or where the mass sits, and this study moves at least one of those."),n?s.push(o?"Every variable is fixed or moves with another \u2014 there is nothing to search.":"Every variable is fixed \u2014 there is nothing to search."):t.variables.length===0&&s.push("No variables selected \u2014 there is nothing to search."),t.objectives.length===0&&s.push("No objective selected. Constraints alone say which designs are legal, not which is better.");for(let y of t.variables){let x=a[y.id];if(!x){s.push(`\u201C${y.id}\u201D is not a variable this car has.`);continue}if(y.values&&y.values.length<2?s.push(`${bt(x)}: list two values or more, or fix it where it is.`):y.hi>y.lo?y.step!==void 0&&Wy({...y,start:x.read(e)})<2&&s.push(`${bt(x)}: a step of ${y.step} ${x.unit} leaves no other place to land in its box. Make the step finer or the box wider, or fix it.`):s.push(`${bt(x)}: the upper bound must be above the lower one (${y.lo} to ${y.hi}).`),x.supersededBy){let v=x.supersededBy.useInstead?a[x.supersededBy.useInstead]:void 0,R=v?bt(v):void 0;s.push(`${bt(x)} cannot be searched: ${x.supersededBy.why}.`+(R?` Use ${R} instead.`:""))}let k=x.read(e);Number.isFinite(k)&&(k<y.lo||k>y.hi)&&s.push(`${bt(x)} starts at ${k.toFixed(1)} ${x.unit}, outside its own bounds.`)}let p=t.followers??[],h=new Map;for(let y of[...t.variables.map(x=>x.id),...p.map(x=>x.id)]){let x=Uy(y);if(!x)continue;let k=h.get(x);k||h.set(x,k={arms:[],coords:[]}),(/^(arm|rocker)\./.test(y)?k.arms:k.coords).push(y)}for(let[y,x]of h){if(x.arms.length===0||x.coords.length===0)continue;let k=R=>a[R]?bt(a[R]):R,v=y.endsWith("rocker")?"rocker":`${y.endsWith("uca")?"upper":"lower"} arm`;s.push(`${y.startsWith("front")?"The front":"The rear"} ${v} is being moved two ways at once \u2014 as an axis (${x.arms.map(k).join(", ")}) and as pivot coordinates (${x.coords.map(k).join(", ")}). They describe the same ${v}, so whichever is applied second overwrites the other. Keep one.`)}let f=new Map,b=new Set(p.map(y=>y.id));for(let y of[...t.variables.map(x=>x.id),...b]){let x=ta(y);if(!x)continue;let k=ur(y),v=b.has(y)?"with":k?`${k.shape.kind}:${y.slice(y.lastIndexOf(".")+1).replace(/[uv]$/,"")}`:"axes",R=f.get(x.point);R||f.set(x.point,R=new Set),R.add(v)}for(let[y,x]of f){if(x.size<2||x.size===2&&x.has("axes")&&x.has("with"))continue;let k=[...x].map(F=>F.split(":")[0]),v=F=>k.filter(T=>T===F).length,R=[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?bt({...M,label:M.label.replace(/ x$/,"")}):y;s.push(`${A} is moved more than one way at once \u2014 ${R.join(" and ")}. Each write moves it off the other's, so keep one.`)}s.push(...O3(t,a));for(let y of t.constraints){let x=i[y.metricId];if(!x){s.push(`\u201C${y.metricId}\u201D is not a metric.`);continue}y.op==="band"&&!((y.limit2??y.limit)>y.limit)&&s.push(`${it(x)}: the band's upper limit must be above its lower one.`)}l&&!(t.operating.speed>0)&&s.push("Whole-car metrics need a speed to be read at; a yaw-moment diagram at rest is degenerate.");for(let y of Mr(t))if(y.at?.speed!==void 0&&!(y.at.speed>0)){let x=i[y.metricId];s.push(`${x?it(x):y.metricId} is asked for at rest, where a yaw-moment diagram is degenerate.`)}for(let y of t.watches??[])i[y.metricId]||s.push(`\u201C${y.metricId}\u201D is not a metric.`);let g=new Set;for(let y of Mr(t)){let x=i[y.metricId],k=x?.unavailable?.(e);!x||!k||g.has(x.id)||(g.add(x.id),s.push(`${it(x)} 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(`${it(i[y.metricId])}: \u201Chit a value\u201D needs a value.`):y.goal==="target"&&y.tolerance!==void 0&&!(y.tolerance>=0)&&s.push(`${it(i[y.metricId])}: the tolerance must be zero or more.`):s.push(`${it(i[y.metricId])}: weight must be positive.`):s.push(`\u201C${y.metricId}\u201D is not a metric.`);return s}var DC=.1,EC=2e3,Xy=3;function rx(e,t,r={},n=EC){t=Ct(e,t);let o=pd(e,t,r),a=ud(r),s=_t(e),i=o.variables.map(S=>S.start),c=S=>{let w=o.build(S);return o.feasible(w).ok&&o.terms(w),w},l=c(i),u=o.feasible(l),m=[...t.objectives,...t.constraints],d=(S,w=m)=>{let C={};for(let L of w){let E=a[L.metricId];E&&(C[`${L.metricId}@${ra(L.at)}`]=Ft(S.ev,E,L.at))}return C},p=S=>m.map(w=>S[`${w.metricId}@${ra(w.at)}`]).map(w=>Number.isFinite(w)?w.toFixed(9):"x").join("|"),h=d(l,Mr(t)),f=p(h),b=[],g=[],y={},x=[],k=0;t.variables.forEach((S,w)=>{let C=s[S.id];if(!C)return;if(x.length>=Xy&&k>n){g.push(C);return}let L=[...i];L[w]=i[w]+(S.hi-i[w])*.25||S.hi;let E=performance.now(),_=c(L),O=performance.now()-E;k+=O,x.push(O);let I=d(_);y[C.id]=I,p(I)===f&&b.push(C)});let v=t.variables[0],R=v?t.variables.indexOf(v):-1;for(let S=0;v&&x.length>0&&x.length<Xy;S++){let w=[...i];w[R]=i[R]+(v.hi-i[R])*(.4+.15*S)||v.hi;let C=performance.now();c(w),x.push(performance.now()-C)}let M=[...x].sort((S,w)=>S-w),A=M.length?M[M.length>>1]:0,F=[],T=Mr(t).map(S=>S.metricId);if(T.some(S=>S.startsWith("dyn.trim")||S==="dyn.ymdMaxAy")){let S=l.ev.ymdLimit();S?.onGridEdge&&F.push("The yaw-moment diagram peaks on the edge of its swept grid, so the trim readings are where the sweep stopped rather than where the car does. Widen the \u03B2/\u03B4 envelope before trusting them."),!S&&l.ev.dynAvailable&&F.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,w=S?Nn(S):null;w==="assumed"?F.push("This tyre carries no explicit Mz coefficient block. Its steering-aligning contribution uses Magic Formula defaults, so optimise the curve only as a qualitative placeholder until Mz is imported or fitted."):w==="none"&&F.push("This tyre model has no aligning-moment curve. Steering metrics contain contact-patch force and jacking, but not the pneumatic-trail signal that normally warns the driver at the tyre limit.")}let P=["lap.minStabil","lap.understeerFrac"];if(T.some(S=>P.includes(S))){let w=l.ev.lapReserve()?.beyondFrac;if(w!==void 0&&Number.isFinite(w)){let C=(w*100).toFixed(0);w>=DC?F.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.`):w>0&&F.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 F.push(...Ty(l.ev,Mr(t).map(S=>({m:a[S.metricId],at:S.at})).filter(S=>!!S.m))),{msPerEval:A,values:h,samples:x.length,times:x,dead:b,moves:y,unprobed:g,warnings:F,beyondFrac:T.some(S=>P.includes(S))?l.ev.lapReserve()?.beyondFrac:void 0,startFeasible:u.ok,startReason:u.reason}}var B3=[{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:$3.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 $3=["setup:m","characteristics:peak_power","characteristics:power_to_weight","characteristics:cla","characteristics:cda","characteristics:pack_energy","characteristics:maxAy","characteristics:top_speed"];var Tue=new Set(B3.map(e=>e.kind));var IC={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 nx=["FL","FR","RL","RR"],zt=(e,t,r)=>({input:e,from:r?r[0]:IC[e].from,to:r?r[1]:IC[e].to,n:t}),Eue=[{id:"sides",name:"Inside and outside",cards:[{id:"camber-roll",form:"curves",title:"Camber to the road through roll",sweep:zt("roll",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"toe-rack",form:"curves",title:"Wheel angle against the rack",sweep:zt("steer",25),wheels:["FL","FR"],y:["toe"]},{id:"camber-rack",form:"curves",title:"Camber to the road through the steer",sweep:zt("steer",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"load-roll",form:"curves",title:"Wheel loads through roll",sweep:zt("roll",25),wheels:nx,y:["wheelLoad"]},{id:"travel-roll",form:"curves",title:"Wheel travel through roll",sweep:zt("roll",25),wheels:nx,y:["travel"]},{id:"toe-roll",form:"curves",title:"Roll steer, all four",sweep:zt("roll",25),wheels:nx,y:["toe"]}]},{id:"maps",name:"Travel and steer together",cards:[{id:"camber-map",form:"surface",title:"Camber over travel and rack",sweep:zt("travel",17),second:zt("steer",13),wheels:["FL"],y:["camber"]},{id:"bump-steer-map",form:"map",title:"Bump steer over travel and rack",sweep:zt("travel",17),second:zt("steer",13),wheels:["FL"],y:["bumpSteer"]},{id:"bump-steer-family",form:"curves",title:"Bump steer through travel, at five rack positions",sweep:zt("travel",25),second:zt("steer",5,[-20,20]),wheels:["FL"],y:["bumpSteer"]},{id:"scrub-map",form:"surface",title:"Scrub radius over travel and rack",sweep:zt("travel",17),second:zt("steer",13),wheels:["FL"],y:["scrubRadius"]}]}];function ox(e){let t=Number(e);return Number.isFinite(t)?Math.min(Nh,Math.max(_h,t)):Ut}var NC=6e4;var Pme=[{within:60*6e4,every:NC},{within:1440*6e4,every:60*6e4},{within:720*60*6e4,every:1440*6e4},{within:1/0,every:10080*6e4}];var Z3=new Set(["color","visible","source","origin"]),Gme=["id",...Z3];var BC=.18/1.18,$C={induction:{kind:"natural"}},GC=e=>e.breathing??$C;function dd(e){switch(e?.kind){case"sae-j1349":return Ec(99e3,25);case"measured":return Ec(e.hPa*100,e.tempC);default:return Ec(101325,20)}}var eB=dd(void 0);function KC(e,t){let r=dd(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 HC(e,t){let r=e.induction;if(r.kind==="table"){let o=s=>Ue(r.densityAltitudeM,r.powerPct,s),a=o(dd(e.rated).densityAltitudeM);return a>0?Math.max(0,o(t.densityAltitudeM)/a):0}let n=e.frictionShare??BC;return Math.max(0,(KC(e,t)-n)/(1-n))}var VC=new WeakMap;function sx(e,t){let r=e.asRated??e,n=`${t.p}|${t.pDry}|${t.T}`,o=VC.get(r);o||VC.set(r,o=new Map);let a=o.get(n);if(a)return a;let s=HC(GC(r),t),i={...r,torque:r.torque.map(c=>c*s),asRated:r};return o.set(n,i),i}function oB(e){return JSON.parse(ix(cx(e,"public/laptime/index.json"),"utf8")).tracks}var aB=async e=>{let t=await fetch(e.url);if(!t.ok)throw new Error(`The track could not be read from ${Mp(e)} (${t.status}).`);return new Uint8Array(await t.arrayBuffer())};function zC(e,t=new Map,r=aB){let n=oB(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(!$c(o.address))throw new Error(`"${o.address}" is not a catalogue address`);if(!Bc(o.link))throw new Error("This track is linked to a source this version does not read from.");i=await A0(await r(o.link),o.link,o.address)}else if(o.kind==="catalogue"){if(!$c(o.address))throw new Error(`"${o.address}" is not a catalogue address`);let c=JSON.parse(ix(cx(e,"public/catalogue",F0(o.address)),"utf8"));i=await T0(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(ix(cx(e,"public/laptime",c),"utf8"))}return t.set(a,i),structuredClone(i)}}var sB=1e-6;function YC(e,t,r){let n=e.cgReference;if(!n||!e.cg_height)return e;let o=OM(e,t,r);if(o===void 0||Math.abs(o-n.standingRadius)<sB)return e;let a=n.typed??e.cg_height.value;return{...e,cg_height:{...e.cg_height,value:ns(e.cg_height.value,n.standingRadius,o)},cgReference:{...n,standingRadius:o,typed:a}}}function WC(e,t,r){let n=e.rcRoad,o=e.rc_front,a=e.rc_rear;if(!n||!o||!a)return e;let s=fm(e,t,r),i=gn(o.value,n.gainFront,n.radiusFront,s.front),c=gn(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 jC=e=>({brakeFade:e.brakeFade,airTempC:e.airTempC,diffYaw:e.diffYaw,...Yo(e.air)?{air:e.air}:{}});var sa=(e,t)=>t?e.find(r=>r.id===t)?.model:void 0;function ia(e){return{tire:t=>sa(e.tires,t),motor:t=>sa(e.motors,t),aero:t=>sa(e.aeros,t),battery:t=>sa(e.batteries,t),brake:t=>sa(e.brakes??[],t),damper:t=>sa(e.dampers??[],t),suspensionOf:t=>Ms(lx(e,t),t)}}function lx(e,t){let r=sa(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 ca(e,t,r){let n={front:t.tire(e.tireModelId),rear:t.tire(e.tireModelIdRear)};return ux(PM(t.suspensionOf(e),e,n),t,r)}function iB(e){return Yo(e.air)?ow(e.air,e.airTempC??Ut):void 0}function cB(e,t){return t?{...e,rho:{...e.rho,value:t.rho},readouts:{...e.readouts,rho:fp}}:e}function lB(e,t,r){if(!r)return{rho:e.rho,motorModel:t,readouts:e.readouts};let{rho:n,readouts:o}=cB(e,r);return{rho:n,motorModel:t&&pt(t)?sx(t,r):t,air:r,readouts:o}}function ux(e,t,r){let n=t.tire(e.tireModelId),o=t.tire(e.tireModelIdRear),a=WC(YC(ed(GM(VM(qM(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}=lB(a,t.motor(e.motorModelId),iB(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),...Ui(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 dB=e=>e!==!1,fB=(e,t,r)=>r&&t>0?(e%t+t)%t:Math.min(Math.max(e,0),t);function hB(e,t,r){let n=e.points.filter(o=>Number.isFinite(o.at)&&Number.isFinite(o.z)).map(o=>({...o,at:fB(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 bB(e,t,r){let n=hB(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,h,f)=>i[p]+i[h]>f?f*i[p]/(i[p]+i[h]):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,d=p=>!r&&p===o-1&&o>1&&n[p].at>=t-1e-9?s(p-1):s(p);return n.map((p,h)=>{let f=l(h),b=u(h),g=Math.min(i[h],f,b),y=!r&&g<i[h]&&(h===o-1&&g===f||h===0&&g===b);return{at:p.at,z:p.z,gIn:m(h),gOut:d(h),half:g,asked:i[h],atEnd:y}})}function gB(e,t,r,n){let o=t-e.at;return n&&r>0?o-r*Math.round(o/r):o}function yB(e,t,r,n){for(let s of e){let i=gB(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 UC(e,t,r,n){let o=dB(n),a=bB(e,r,o);return a.length?t.map(s=>yB(a,s,r,o)):t.map(()=>0)}function dl(e,t){if(!t?.points.length)return e;let r=Wc(e),{zSmoothing:n,...o}=e;return{...o,z:UC(t,r,Q0(e),e.closed)}}var fd={widthLeft:1.5,widthRight:1.5,bank:0,mu:1};function XC(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 fl(e,t){let r=XC(e.source);return qC(e,r?await t(r):void 0)}function qC(e,t){let{source:r}=e;if(r.kind==="segments"){let{segments:i,closed:c,spacing:l}=r,{asset:u}=Uc(i,{name:e.name,closed:c,spacing:l,base:fd});return dl(u,r.profile)}let n=r.sections??[];if(r.kind==="inline")return dl(Dp(r.asset,n,fd),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 dl(Dp({...t,...o!==void 0?{widthLeft:o}:{},...a!==void 0?{widthRight:a}:{},...s!==void 0?{closed:s}:{}},n,fd),r.profile)}var pfe=1/500;var dfe=5*Math.PI/180;var kfe=1/3;var kB=[4,2,1,.5,.25,.125];function QC(e,t,r={}){let n=[...r.steps??kB].sort((g,y)=>y-g),o=At(r.numerics),a=r.tolPct??.5,s=Xt(e),i=e.ggvMode??"twoTrack",c=Vr(s,!1,i),l={...o,dsTarget:n[0]??o.dsTarget},u=n.length?Vo(s,c,[wt(t,l)],l,i):void 0,m=Wn(s,c.rows),d=n.map((g,y)=>{let x={...o,dsTarget:g},k=Date.now(),v=wt(t,x),R=Kt(c,v,x,{...u?{load:u}:{},...m?{shifts:m}:{}});return r.onStep?.(y+1,n.length),{dsTarget:g,npts:v.npts,lapTime:R.laptime,ms:Date.now()-k}}),p=d[d.length-1]?.lapTime??NaN,h=d.map(g=>{let y=g.lapTime-p;return{...g,delta:y,deltaPct:p?100*y/p:NaN}}),f=h.filter(g=>Math.abs(g.deltaPct)<=a),b=f.length?Math.max(...f.map(g=>g.dsTarget)):null;return{points:h,reference:p,recommended:b,tolPct:a}}function la(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:ox(t.airTempC??r.airTempC),...Yo(dp(t.air??r.air))?{air:dp(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:At(r.numerics)}}async function hd(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 fl(r,t)}}function AB(e,t){let r=structuredClone(e);for(let[n,o]of Object.entries(t))if(!vm(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 mx=(e,t)=>{let r=e?.name;return typeof r=="string"&&r?r:t};function wB(e,t){let r={};for(let n of Xn){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:mx(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:mx(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:mx(i.model,i.id),byFallback:!0}:null;continue}r[n.doc]=null}return r}function FB(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 ZC(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 JC=e=>e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`;async function bd(e,t,r={}){let n=la(e,r.settings),{entry:o,asset:a}=await hd(e,t),s=ia(e),i=r.vehicleIds?.length?r.vehicleIds.map(h=>{let f=e.vehicles.find(b=>b.id===h);if(!f)throw new Error(`this project holds no vehicle "${h}"`);return f}):e.vehicles.filter(h=>h.visible);if(!i.length)throw new Error("no vehicle is visible in this project \u2014 name some in vehicleIds");let c=i.map(h=>{let f=r.overrides?.[h.id]?AB(h.params,r.overrides[h.id]):h.params;return ca(structuredClone(f),s,n)}),l=Fc(Ho(e.meta.rulesetId,e.rulesets)),u=Dc(c,a,n.numerics,l,{racingLine:n.racingLine,standingStart:n.standingStart,lapCounts:n.lapCounts}),m={};i.forEach((h,f)=>{m[h.id]=u[f]});let{scores:d,field:p}=r0(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:d!==null,vehicles:i.map((h,f)=>({id:h.id,name:u[f].name||String(h.params.name??h.id),events:FB(u[f]),metrics:n0(l,u[f],p?.[h.id]),fitted:wB(e,h.params),...d?.[h.id]?{score:{total:d[h.id].total,parts:{...d[h.id].parts}}}:{}})),raw:{results:m,scores:d,field:p}}}async function eT(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=la(e),{asset:a}=await hd(e,t),s=ca(structuredClone(n.params),ia(e),o);return QC(s,a,{...r.steps?{steps:r.steps}:{},numerics:o.numerics,...r.tolPct!==void 0?{tolPct:r.tolPct}:{},...r.onStep?{onStep:r.onStep}:{}})}var CB=(e,t)=>e[t]??[],TB=(e,t,r)=>r<=1?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function gd(e){return e.kind==="param"?TB(e.start,e.end,Math.max(1,Math.round(e.steps))):e.kind==="part"?[...e.partIds]:[...e.values]}var tT=e=>e.kind==="param"?e.label:e.kind==="part"?`${e.part} model`:e.setting;function PB(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=ca(structuredClone(r.params),ia(e),la(e)),o=UM(n,{geometry:!0}),a=Rm(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=Xn.find(l=>l.doc===i.part);if(!c)throw new Error(`"${i.part}" is not a library \u2014 it is one of ${Xn.map(l=>l.doc).join(", ")}`);for(let l of i.partIds)if(!CB(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*gd(c).length,1);if(s>lp)throw new Error(`that grid is ${s} runs, over the ${lp} cap \u2014 a run is a whole session. Drop an axis or use fewer steps.`)}var LB=e=>e.map(t=>String(typeof t=="number"?Number(t.toPrecision(4)):t)).join(" \xD7 ");function DB(e,t){let r=[...new Set(e.flatMap(o=>(o.didNotFinish??[]).map(a=>a.label)))],n=e.map(o=>({name:LB(o.at),events:r.map(a=>({label:a,incomplete:o.didNotFinish?.find(s=>s.label===a)}))}));return ZC(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`:JC(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 EB(e){let t=[[]];for(let r of e){let n=gd(r),o=[];for(let a of n)for(let s of t)o.push([...s,a]);t=o}return t}async function rT(e,t,r,n){PB(e,r);let o=EB(r.axes),a=[],s=!1;for(let[u,m]of o.entries()){let d=structuredClone(e),p=d.vehicles.find(k=>k.id===r.vehicleId),h={...r.settings},f={};r.axes.forEach((k,v)=>{let R=m[v];if(k.kind==="param")f[k.label]=R;else if(k.kind==="part"){let M=Xn.find(A=>A.doc===k.part);p.params[M.ref]=R}else h[k.setting]=R});let b=r.fleet?d.vehicles.filter(k=>k.visible||k.id===r.vehicleId).map(k=>k.id):[r.vehicleId],g=await bd(d,t,{vehicleIds:b,settings:h,...Object.keys(f).length?{overrides:{[r.vehicleId]:f}}:{}});s=g.fleetScored;let y=g.vehicles.find(k=>k.id===r.vehicleId),x=y.events.flatMap(k=>k.incomplete?[{label:k.label,...k.incomplete}]:[]);a.push({at:m,metrics:y.metrics,...x.length?{didNotFinish:x}:{}}),n?.(u+1,o.length)}let i=Object.keys(a[0]?.metrics??{}),c=[];r.axes.forEach((u,m)=>{if(gd(u).length<2)return;i.some(p=>{if(new Set(a.map(b=>`${b.at[m]}`)).size<2)return!1;let f=a.map(b=>b.metrics[p]).filter(Number.isFinite);return Math.max(...f)-Math.min(...f)>1e-9})||c.push(tT(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(...DB(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:tT(u),values:gd(u)})),runs:a,metricKeys:i,fleetScored:s,flat:c,caveats:l}}var Cbe=Math.PI/180;var yd=.5,jB=new Set(["lap","session"]);function UB(e){return bt({...e,label:e.label.replace(/ [xyz]$/,"")})}function oT(e){let t=ta(e);if(t)return[t.point];let r=ur(e);if(r)return[r.point];let n=/^arm\.(front|rear)\.(uca|lca)\./.exec(e);if(n){let a=rr[n[2]];return[`hp.${n[1]}.${a.fore}`,`hp.${n[1]}.${a.aft}`]}let o=/^rocker\.(front|rear)\./.exec(e);return o?[`hp.${o[1]}.${zr.fore}`,`hp.${o[1]}.${zr.aft}`]:[]}function aT(e,t){let r=Ct(e,t),n=_t(e),o=new Map;for(let a of[...r.variables,...r.followers??[]])for(let s of oT(a.id)){if(o.has(s))continue;let i=As.map(c=>`${s}.${c}`).filter(c=>n[c]&&!n[c].supersededBy);i.length&&o.set(s,{id:s,name:UB(n[i[0]]),coords:i})}return[...o.values()]}function px(e,t,r,n={},o=yd){let a=Ct(e,t),s=(n.metrics??Rr()).byId,i=Ds(e,a,r),c=aT(e,a),l=_t(i),u=[];a.objectives.forEach((S,w)=>{let C=s[S.metricId];C&&u.push({key:S.key??`target:${w}`,role:"target",metric:C,at:S.at})}),a.constraints.forEach((S,w)=>{let C=s[S.metricId];C&&u.push({key:S.key??`hold:${w}`,role:"hold",metric:C,at:S.at,hold:S})}),(a.watches??[]).forEach((S,w)=>{let C=s[S.metricId];C&&u.push({key:S.key??`watch:${w}`,role:"watch",metric:C,at:S.at})});let m=u.filter(S=>!jB.has(S.metric.cost)),d=S=>{let w=md(S,a,n),C=m.map(L=>Ft(w,L.metric,L.at));return w.failure?null:C},p=d(i)??m.map(()=>NaN),h=[],f=[],b=[],g=1,y=[...p],x=[...p],k=S=>S.forEach((w,C)=>{Number.isFinite(w)&&(w>=y[C]||(y[C]=w),w<=x[C]||(x[C]=w))}),v=S=>{g++;try{return d(S())}catch{return null}};for(let S of c)for(let w of S.coords){let C=l[w],L=C.read(i),E=w.slice(w.lastIndexOf(".")+1),_=v(()=>C.write(i,L+o)),O=v(()=>C.write(i,L-o));if(!_||!O){b.push(`${S.name} ${E}`);continue}h.push({id:w,def:C,now:L,point:S,axis:E}),f.push([_,O]),k(_),k(O)}let R=new Map,M=S=>{let w=S.join("");if(R.has(w))return;let C=v(()=>h.reduce((L,E,_)=>E.def.write(L,E.now+S[_]*o),i));R.set(w,C),C&&k(C)};h.length>1&&m.forEach((S,w)=>{let C=f.map(([L,E])=>L[w]-p[w]>=E[w]-p[w]?1:-1);Number.isFinite(p[w])&&(M(C),M(C.map(L=>-L)))});let A=[...R.values()].filter(S=>!S).length;A&&b.push(`${A} of ${R.size} corners`);let F=u.map(S=>{let w={key:S.key,role:S.role,name:it(S.metric)+aa(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{...w,value:NaN,lo:NaN,hi:NaN,skipped:"read off a lap"};let L=p[C],E=Number.isFinite(L)?y[C]:NaN,_=Number.isFinite(L)?x[C]:NaN,O=f.map(([V,j])=>Math.max(Math.abs(V[C]-L),Math.abs(j[C]-L))),I=O.filter(Number.isFinite).reduce((V,j)=>V+j,0),z;if(I>0){let V=O.indexOf(Math.max(...O.filter(Number.isFinite)));z={point:h[V].point.name,axis:h[V].axis,share:O[V]/I}}let B=S.hold?Math.max(to(S.hold,E),to(S.hold,_)):void 0;return{...w,value:L,lo:E,hi:_,...z?{most:z}:{},...B!==void 0?{excess:B}:{}}}),T=new Set(c.flatMap(S=>S.coords)),P=a.variables.filter(S=>!oT(S.id).length&&!T.has(S.id)).length;return{mm:o,points:c,rows:F,evaluations:g,unsolved:b,settings:P}}function dx(e){if(!e.chassis)return e;let{chassis:t,...r}=e;return t.boxes.length?{...r,chassis:{boxes:t.boxes}}:r}var aRe=180/Math.PI;var T$={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:Ko,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 Dve=T$.id;var hl=.02;function yT(e){let t=Math.max(hl,Math.abs(e.heaveMotionRatio)),r=Math.max(hl,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 L$=(e,t)=>({od:t,id:Math.min(e.id,t-.5)}),D$=(e,t)=>e/(2*t*t);function gT(e,t){switch(e.kind){case"ubar":case"blade":case"torsionTube":return{...e,section:L$(e.section,t)};default:return e}}function xT(e,t,r){let n=Math.max(hl,Math.abs(r));if(e?.kind==="coil"){let l=D$(t,n),u=e.rate;if(typeof u=="number")return{...e,rate:l};let m=hn(u,0);if(!(m>0))return{...e,rate:l};let d=l/m;return{...e,rate:{...u,y:u.y.map(p=>p*d)}}}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=>Zi(gT(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 gT(a,c)}function RT(e,t,r,n){let o=e?.design,a=xT(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 E$=Math.PI/180,xd=1e-6;function I$(e){return!(Ee(e.rockerPivotA,e.rockerPivotB)<xd||Ee(e.rockerToPushrod,e.rockerPivotA)<xd||Ee(e.rockerToDamper,e.rockerPivotA)<xd||Ee(e.rockerToDamper,e.damperChassis)<xd)}function ST(e){if(!I$(e.hardpoints))return!1;let t={...e,config:{...e.config,actuation:"rocker"}};try{let r=gt(t);for(let n of[-20,-1,0,1,20]){let o=we(r,n,0);if(!o.ok||!Number.isFinite(o.state.metrics.damperLength))return!1}return!0}catch{return!1}}function AT(e){if(e.config.actuation!=="direct"||ST(e))return;let{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}=N$(e);return{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}}var vT=40;function Rd(e,t={}){let r=e.hardpoints,n=r.pushrodOuter,o=r.damperChassis,a=Ee(n,o),s=oe(n,Q(G(o,n),_$)),i=t.armRod??Math.max(25,.15*a),c=t.armDamper??i,l=[s[0]-vT,s[1],s[2]],u=[s[0]+vT,s[1],s[2]],m=te(G(u,l)),d=G(n,s),p=te(G(d,Q(m,kT(d,m)))),h=nr(p,m,(t.armAngleDeg??60)*E$),f=oe(s,Q(h,i)),b=G(o,s),g=te(G(b,Q(m,kT(b,m)))),y=Q(te(le(m,g)),t.damperSide??1),x=oe(s,Q(y,c));return{...r,rockerPivotA:l,rockerPivotB:u,rockerToPushrod:f,rockerToDamper:x}}var _$=.72,kT=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2];function MT(e){let t=ot(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 N$(e,t={}){let r=t.target??MT(e),n=t.armAngleDeg,o=Rd(e,{armAngleDeg:n});if(!(r>0))return o;let a=Ee(e.hardpoints.pushrodOuter,e.hardpoints.damperChassis),s=Math.max(25,.15*a),i=(()=>{for(let p of[1,-1]){let h=Rd(e,{armRod:s,armAngleDeg:n,damperSide:p}),f={...e,config:{...e.config,actuation:"rocker"},hardpoints:h};try{let b=gt(f),g=we(b,15,0),y=we(b,-15,0);if(g.ok&&y.ok&&g.state.metrics.damperLength<y.state.metrics.damperLength)return p}catch{}}return 1})(),c=(p,h)=>{try{return MT({...e,config:{...e.config,actuation:"rocker"},hardpoints:Rd(e,{armRod:p,armAngleDeg:n,armDamper:h,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,d=1/0;for(let p of l){let h=.25*p,f=6*p,b=p;for(let y=0;y<24;y++){let x=(h+f)/2,k=c(p,x);if(!Number.isFinite(k))break;b=x,k<r?h=x:f=x}let g=Math.abs(c(p,b)-r);if(Number.isFinite(g)&&g<d&&(d=g,u=p,m=b),d<1e-4*Math.max(1,r))break}return Rd(e,{armRod:u,armAngleDeg:n,armDamper:m,damperSide:i})}var Wve=Array.from({length:19},(e,t)=>-45+5*t);var jve=Math.PI/180;function O$(e){let t=e.hardpoints,r=te(G(t.rockerPivotB,t.rockerPivotA)),n=Dn(t.rockerToDamper,t.rockerPivotA,r),o=.6*Ln(G(t.rockerToDamper,n)),a=le(r,bR),s=Ln(a)>1e-6?te(a):te(G(t.rockerToDamper,n));return{outer:oe(n,Q(s,o)),inner:oe(n,Q(s,-o)),attach:"rocker"}}var V$=(e,t)=>({...e,config:{...e.config,actuation:t}});function bx(e,t,r,n){let o=r==="front"?e.front:e.rear,a=lm(o),s=o.config.springRate*a*a,i=re(t,r==="front"?"damper_front":"damper_rear")*a*a,c=r==="front"?t.arbFrontDesign:t.arbRearDesign,l=To(e,t)[r]??re(t,r==="front"?"arb_front":"arb_rear"),u=rs(e,t)[r]??re(t,r==="front"?"heave_spring_front":"heave_spring_rear"),m=AT(o),d=V$(m?{...o,hardpoints:{...o.hardpoints,...m}}:o,"decoupled"),p=r==="front"?t.heaveFrontDesign:t.heaveRearDesign,h=n?.heave??wT(p?.linkage,F=>co(d,F).atDesign)??Lf(d,"rockerToRocker"),f=!c||c.design.kind==="none"||c.design.kind==="coil",b=f?"coil":"ubar",g=c?.linkage&&(c.design.kind==="none"||c.linkage.attach!=="rocker")?c.linkage:void 0,y=n?.roll??wT(f?g:c?.linkage,F=>Fa(d,F,{kind:b}).atDesign)??(f?O$(d):dM(d)),x=co(d,h).atDesign,k=Fa(d,y,{kind:b}).atDesign,v=mm(e,t),R=yT({cornerWheelRate:s,cornerDamper:i,arbWheelRate:l,heaveWheelRate:u,heaveWheelDamping:r==="front"?v.heaveFront:v.heaveRear,rollWheelDamping:r==="front"?v.rollFront:v.rollRear,heaveMotionRatio:x,rollMotionRatio:k}),M=!c||c.design.kind==="none"?{design:{kind:"coil",rate:1},linkage:y}:{...c,linkage:y},A=RT({design:p?.design??{kind:"none"},linkage:h,damper:p?.damper},M,R,k);return m?{...A,crank:m}:A}function wT(e,t){return e&&Math.abs(t(e))>=hl?e:void 0}var vd=[{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"]}],gx=()=>({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]}},$$={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]}},G$=()=>({outer:[0,189,486],attach:"rocker",mount:{kind:"chassis",anchor:[-225,0,486]}}),K$={rate:60,motionRatio:1},H$={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]}},z$=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]}},Y$={kind:"coil",rate:1560,motionRatio:1,gap:0,bothWays:!0},W$=40,j$={rockerPivotA:[50,130,440],rockerPivotB:[-50,130,440],rockerToPushrod:[10,170,460],rockerToDamper:[-20,64,440],damperChassis:[-20,64,215]},FT=()=>({outer:[-50,130,480],attach:"rocker",shaftStation:-50}),CT=()=>({outer:[50,130,400],inner:[50,130,480],attach:"rocker",shaftStationOuter:50,shaftStationInner:50}),U$=e=>[e[0],e[1],e[2]];function X$(e){let t=r=>({...r,hardpoints:{...r.hardpoints,...PT(j$)},config:{...r.config,actuation:"decoupled"}});return{...e,front:t(e.front),rear:t(e.rear)}}function PT(e){return Object.fromEntries(Object.entries(e).map(([t,r])=>[t,U$(r)]))}function LT(e,t=Xo(),r=e==="pull"?$$:B$){let n=(o,a)=>({...o,hardpoints:{...o.hardpoints,...PT(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 kd(e,t){let r=yx(e),n=Es(e);if(e==="heave")return{meta:r,vehicle:n,components:{...gx(),heaveFront:{design:{...Wb,...K$},linkage:G$()}}};if(e!=="decoupled")return{meta:r,vehicle:n,components:gx()};let o=bx(n,t,"front",{heave:FT(),roll:CT()}),a=bx(n,t,"rear",{heave:FT(),roll:CT()});return{meta:r,vehicle:n,components:{arbFront:o.arb,arbRear:a.arb,heaveFront:o.heave,heaveRear:a.heave}}}function Es(e){let{name:t}=yx(e);if(e==="direct")return{..._c(),name:t};if(e==="mcpherson"){let n=Nc(),o=bp();return{...n,front:{...o,config:{...o.config,loadedRadius:n.front.config.loadedRadius}},name:t}}let r=q$(LT(e==="pullrod"?"pull":"push"));return{...e==="decoupled"?X$(r):r,name:t}}var TT={front:221.7,rear:220.9};function q$(e){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:TT.front}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:TT.rear}}}}function yx(e){let t=vd.find(r=>r.id===e);if(!t)throw new Error(`Unknown suspension template: ${e}`);return t}function Md(){let e=t=>({design:{...Y$},linkage:z$(t),damper:W$});return{meta:yx("heave"),vehicle:LT("push",u0(),H$),components:{...gx(),heaveFront:e("front"),heaveRear:e("rear")}}}var DT=[10,25,50,100,200,300],Q$=[{id:"c1",label:"Soft",scale:.7},{id:"c2",label:"Medium",scale:1},{id:"c3",label:"Firm",scale:1.4}],ET=e=>Math.round(e*100)/100;function Z$(e,t,r){let n=DT.map(o=>ET(r*o));return{id:e,label:t,speedMmS:[...DT],bumpN:n,reboundN:[...n]}}function J$(e){return{name:e.name,body:{...e.body},curves:Q$.map(t=>Z$(t.id,t.label,ET(e.coefficient*t.scale)))}}function bl(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 Yr(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:Kc[e.dampers.length%Kc.length],model:J$(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 Tt=e=>`${e} (typical)`,xx={car:{name:Tt("Formula Student damper"),coefficient:2.5,body:{extended:249,stroke:55}}},Sd={car:xx.car,heave:{name:Tt("Formula Student heave damper"),coefficient:3.4,body:{extended:270,stroke:47}},roll:{name:Tt("Formula Student roll damper"),coefficient:3.7,body:{extended:322,stroke:100}}},Ad={car:{name:Tt("Formula 1 damper"),coefficient:6,body:{extended:240,stroke:40}},heave:{name:Tt("Formula 1 heave damper"),coefficient:40,body:{extended:240,stroke:40}}},IT={car:{name:Tt("GT damper"),coefficient:4.5,body:{extended:510,stroke:80}}},Rx={car:{name:Tt("Sports car damper"),coefficient:2.4,body:{extended:515,stroke:110}}},_T={car:{name:Tt("Sports car strut"),coefficient:2.4,body:{extended:310,stroke:120}},rear:Rx.car},NT={car:{name:Tt("Cup car strut"),coefficient:4,body:{extended:285,stroke:75}},rear:{name:Tt("Cup car rear damper"),coefficient:3.5,body:{extended:505,stroke:80}}},OT={car:{name:Tt("Stock car front damper"),coefficient:7.5,body:{extended:555,stroke:110}},rear:{name:Tt("Stock car rear damper"),coefficient:6.75,body:{extended:555,stroke:110}}},VT={car:{name:Tt("Hill-climb front damper"),coefficient:3,body:{extended:285,stroke:65}},rear:{name:Tt("Hill-climb rear damper"),coefficient:3.5,body:{extended:285,stroke:65}}},BT={car:{name:Tt("Race truck front damper"),coefficient:12,body:{extended:780,stroke:160}},rear:{name:Tt("Race truck rear damper"),coefficient:8.5,body:{extended:780,stroke:160}}};function _s(e){return e.vehicles=e.vehicles.slice(0,1),e.activeVehicleId=e.vehicles[0]?.id??null,e}function ro(e,t){let r=Hc(e);return r.meta.rulesetId=t,r}function ua(e,t,r,n){let o=ro(e,t);return o.suspensions=[{...o.suspensions[0],model:n()}],o.vehicles=[N0(r,"v1",0)],o.activeVehicleId="v1",o}var[,eG,tG,rG,nG,oG,aG,sG]=y0;function vx(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 $T(){return{...Es("decoupled"),name:Xo().name}}var iG=[{label:"Formula Student (decoupled)",vehicle:$T,components:e=>bl(kd("decoupled",e).components,Sd)},{label:"Formula 1 (third springs)",vehicle:()=>Md().vehicle,components:()=>bl(Md().components,Ad)}],kx={"direct-coilover":"direct",pushrod:"pushrod",pullrod:"pullrod","third-spring":"heave","mcpherson-strut":"mcpherson"},cG=[...iG.map(e=>e.vehicle),...Object.values(kx).map(e=>()=>Es(e))];function Is(e){let t=bl(kd("decoupled",e.vehicles[0].params).components,Sd);e.suspensions=[{...e.suspensions[0],model:$T()}];for(let r of e.vehicles)vx(r.params,t);return Yr(e,Sd),e}var ma={title:"OpenStreetMap",url:"https://www.openstreetmap.org/copyright",licence:"ODbL-1.0",credit:"\xA9 OpenStreetMap contributors"},wd={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"},GT={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]"},KT={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"},lG={id:"cota",name:"Circuit of the Americas, Austin",address:"e0c6ea889d708cf15f9c",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ma,wd,KT]}},uG={id:"laguna-seca",name:"Laguna Seca, Monterey",address:"185b5811b9c423ef44ef",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ma,wd,KT]}},mG={id:"nordschleife",name:"Nordschleife, N\xFCrburg",address:"74c49603c7b2f15985c6",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ma,GT]}},pG={id:"brands-hatch",name:"Brands Hatch, Kent",address:"c4953e3c25eaba4a5b7e",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ma,{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."}]}},dG={id:"bristol",name:"Bristol, Tennessee",address:"f0e23953669a414ad600",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ma,wd]}},fG={id:"pikes-peak",name:"Pikes Peak, Colorado",address:"3de137fe33b5c2875036",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ma,wd]},standingStart:!0},hG={source:"venue",altitudeM:3580,pressure:{kind:"standard"},humidityPct:0},bG=10,gG={id:"nurburg-sprint",name:"Sprintstrecke, N\xFCrburg",address:"1875636cdbb615aa2756",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ma,GT]}};function pa(e,t){let{id:r,name:n,address:o,provenance:a,standingStart:s}=t,i={kind:"catalogue",id:r,address:o},c=Oc(C0({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 no(e,t,r){let n=e.vehicles[0].params,o=`m${e.motors.length+1}`;e.motors=[...e.motors,{id:o,color:qn[e.motors.length%qn.length],model:t}];let a=IM({},{...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 yG=3.8,Fd={hubPlanetary:14.5,inboardChain:4,engineChain:3.4},xG="Hub motor, 35 kW (example)";function Mx(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 HT(e){let t=e.motors.find(r=>r.id==="m1");return t.model={...t.model,name:xG},t.id}function Cd(e,t,r){let n=_s(Is(ro(e,r)));return n.vehicles[0].params.name=t,n}function RG(){let e=Cd("Formula Student combustion car","Formula Student combustion","fs-cv");no(e,M0(),Fd.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 vG(){let e=Cd("Formula Student AWD car","Formula Student AWD","fs-ev");return Mx(e,HT(e),4,"awd",Fd.hubPlanetary,"hub"),e}function kG(){let e=Cd("Formula Student RWD hub-motor car","Formula Student RWD hub motors","fs-ev");return Mx(e,HT(e),2,"rear",Fd.hubPlanetary,"hub"),e}function MG(){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:qn[e.motors.length%qn.length],model:k0()}],Mx(e,t,1,"rear",Fd.inboardChain),e.vehicles[0].params.driveline={rear:structuredClone(Gt.clutch)},e}function SG(){let e=_s(Is(ro("Formula Student endurance energy","fs-ev"))),t=e.vehicles[0],r=structuredClone(t);if(r.id="v2",r.color=Gc[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 AG(){let e=Md(),t=ua("Formula 1 car","trackday",eG,()=>e.vehicle);return vx(t.vehicles[0].params,bl(e.components,Ad)),Yr(t,Ad),no(t,S0(),yG),pa(t,lG)}function zT(e="GT car",t=_c){let r=ua(e,"trackday",tG,t);return Yr(r,IT),no(r,yw(),r.vehicles[0].params.gear_ratio.value),pa(r,uG)}function YT(e="Sports car",t=Nc,r=Rx){let n=ua(e,"trackday",rG,t);return Yr(n,r),no(n,xw(),n.vehicles[0].params.gear_ratio.value),pa(n,mG)}function wG(){let e=ua("Cup car","trackday",nG,sw);return Yr(e,NT),no(e,Rw(),e.vehicles[0].params.gear_ratio.value),pa(e,pG)}function FG(){let e=ua("Stock car","trackday",oG,iw);return Yr(e,OT),no(e,vw(),e.vehicles[0].params.gear_ratio.value),pa(e,dG)}function CG(){let e=ua("Hill-climb prototype","trackday",aG,cw);return Yr(e,VT),no(e,kw(),e.vehicles[0].params.gear_ratio.value),e.settings.air=structuredClone(hG),e.settings.airTempC=bG,pa(e,fG)}function TG(){let e=ua("Race truck","trackday",sG,lw);return Yr(e,BT),no(e,Mw(),e.vehicles[0].params.gear_ratio.value),pa(e,gG)}function PG(e){let t=vd.find(o=>o.id===e);if(e==="direct")return zT(t.name,()=>Es(e));if(e==="mcpherson")return YT(t.name,()=>Es(e),_T);let r=_s(ro(t.name,"trackday")),n=kd(e,r.vehicles[0].params);return r.suspensions=[{...r.suspensions[0],model:n.vehicle}],vx(r.vehicles[0].params,n.components),Yr(r,xx),r}function gl(e,t,r){let n=kx[e],o=vd.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:()=>PG(n)}}var LG=[{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:()=>Is(ro("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:SG},{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:()=>_s(Is(ro("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:RG},{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:vG},{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:kG},{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:MG},{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:AG},{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:zT},{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:YT},{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:wG},{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:FG},{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:CG},{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:TG},{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:()=>_s(Is(ro("Suspension study","trackday")))},gl("direct-coilover","The GT car\u2019s wishbones driving coilovers straight into the towers, at Laguna Seca.","On the GT car, at Laguna Seca."),gl("pushrod","The FS car on pushrods: a rod from each lower wishbone works a rocker.","On the Formula Student car, at FSG."),gl("pullrod","The FS car on pullrods: a rod from each upper wishbone pulls a low rocker.","On the Formula Student car, at FSG."),gl("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."),gl("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:()=>_s(Is(ro("Tyre study","fs-ev")))}],WT=LG.map(e=>({...e,load:()=>O0(e.load())}));var jT={width:320,height:200},L1e=[.6*jT.width-9,.6*jT.height-9];var UT=new WeakMap,XT=new WeakMap,Sx=e=>JSON.stringify(e,(t,r)=>r===1/0?"Infinity":r);function qT(e,t){if(!t){let a=UT.get(e);return a||(a=Jt(e),UT.set(e,a)),a}let r=XT.get(e);r||(r=new Map,XT.set(e,r));let n=Sx(t),o=r.get(n);return o||(r.size>=4&&r.clear(),o=Jt(e,t),r.set(n,o)),o}var IG=Math.PI/180,_G=e=>e>1?e/100:e;function yl(e){let t=null;return()=>(t??={v:e()}).v}function QT(e){let t=ot(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 ZT=new WeakMap,Ax={heave:0,pitch:0,roll:0,steer:0},JT=[0,1,2,3,4],eP=[-20,-10,0,10,20];function rP(e,t){let r=bn(e,Ax),n=["front","rear"],o=c=>{let l=ec(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 JT){let l=c===0?null:bn(e,{...Ax,roll:c*IG});n.forEach((u,m)=>{let d=l?ec(l[u]):null,p=d&&Number.isFinite(a[m]);s[m].rc.push(p?t[m]+(d.left+d.right)/2-a[m]:t[m]),s[m].split.push(p?(d.left-d.right)/2:0)})}let i=n.map(()=>[]);for(let c of eP){let l=c===0?null:bn(e,{...Ax,heave:-c});n.forEach((u,m)=>{let d=l&&l[u].valid&&r[u].valid;i[m].push(d?t[m]+l[u].height-r[u].height:t[m])})}return{roll:{rollDeg:JT,rcFront:s[0].rc,rcRear:s[1].rc,rcSplitFront:s[0].split,rcSplitRear:s[1].split},heave:{drop:eP,rcFront:i[0],rcRear:i[1]}}}var tP=new WeakMap;function NG(e,t,r,n){let o=tP.get(e);o||(o=new Map,tP.set(e,o));let a=`${Sx(r)}|${n[0]}|${n[1]}`,s=o.get(a);if(!s){o.size>=4&&o.clear();try{s=rP(qT(e,r),n)}catch{s=t.rigidMigration(n)}o.set(a,s)}return s}function OG(e){let t=ZT.get(e);if(t)return t;let r=Jt(e),n=bn(r,{heave:0,pitch:0,roll:0,steer:0}),o=QT(e.front),a=QT(e.rear),s={wheelbase:e.config.wheelbase,trackFront:Ot(e.front),trackRear:Ot(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:ts(n.front),rcGainRear:ts(n.rear),rigidMigration:i=>rP(r,i),kinFront:yl(()=>Va(e.front)),kinRear:yl(()=>Va(e.rear))};return ZT.set(e,s),s}function nP(e,t,r,n){let o=OG(e),a=To(e,t),s=rs(e,t),i=FM(e,t),c=mm(e,t),l=CM(e,t),u=TM(t),m=pm(e,t),d=Co(e.front),p=Co(e.rear),h=Fo(t.damperModel,t.damperSetup,o.mrFront,o.mrRear,t.damperModelRear??t.damperModel),f={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,re(t,"cop_long"))),copHeight:re(t,"cop_height"),...t.aeroModel?{model:t.aeroModel}:{},rideHeightFront:re(t,"ride_height_front"),rideHeightRear:re(t,"ride_height_rear")},b=9.81,g=_G(t.front_mass_diss.value),y=Eo(t,r,n),x=_e(y.front),k=y.rear===y.front?x:_e(y.rear),v=n??t.tireModelRear??r,R=t.m.value*b*g/2,M=t.m.value*b*(1-g)/2,A=x.corneringStiffness(R),F=k.corneringStiffness(M),T=(r?x.verticalStiffness():0)||re(t,"tire_vertical_rate"),P=(v?k.verticalStiffness():0)||re(t,"tire_vertical_rate"),S=Pr(r)??0,w=Pr(v)??0,C=gm({freeRadius:S,staticLoad:R,tyreRate:T,surveyed:e.front.config.loadedRadius},{freeRadius:w,staticLoad:M,tyreRate:P,surveyed:e.rear.config.loadedRadius},g),L=cr(S,R,T,e.front.config.loadedRadius),E=cr(w,M,P,e.rear.config.loadedRadius),_=[gn(o.rcHeightFront,o.rcGainFront,e.front.config.loadedRadius,L),gn(o.rcHeightRear,o.rcGainRear,e.rear.config.loadedRadius,E)],O=yl(()=>oc(o.kinFront(),re(t,"camber_front_deg"))),I=yl(()=>oc(o.kinRear(),re(t,"camber_rear_deg"))),z=yl(()=>NG(e,o,Ss(j),_)),B=Ei({...t,wheelbase:{...t.wheelbase,value:o.wheelbase}}),V=nc(t),j={massTotal:t.m.value,frontMassFrac:g,steeringSystem:t.steeringSystem,tv:Qu(t),cgHeight:ns(re(t,"cg_height"),t.cgReference?.standingRadius,C),cgStandingRadius:C,wheelbase:o.wheelbase,trackFront:o.trackFront,trackRear:o.trackRear,wheelRateFront:d?0:o.wheelRateFront,wheelRateRear:p?0:o.wheelRateRear,decoupledFront:d,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&&!d?{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:re(t,"tire_vertical_damping"),arbFront:a.front??re(t,"arb_front"),arbRear:a.rear??re(t,"arb_rear"),brakeBalanceFront:B.balanceFront,brakes:B,...V?{driveline:V}:{},heaveSpringFront:s.front??re(t,"heave_spring_front"),heaveSpringRear:s.rear??re(t,"heave_spring_rear"),unsprungPerCorner:re(t,"unsprung_mass"),unsprungCgHeight:cr(S,R,T,o.unsprungCgHeight),tyreFreeRadius:S,...w!==S?{tyreFreeRadiusRear:w}:{},rcHeightFront:_[0],rcHeightRear:_[1],corneringStiffnessFront:A,corneringStiffnessRear:F,get kinFront(){return O()},get kinRear(){return I()},damperFront:d?0:h?.front?.rate??re(t,"damper_front")*o.mrFront*o.mrFront,damperRear:p?0:h?.rear?.rate??re(t,"damper_rear")*o.mrRear*o.mrRear,...h?.front&&!d?{damperCurveFront:h.front.curve}:{},...h?.rear&&!p?{damperCurveRear:h.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:re(t,"unsprung_mass"),get rollCentreCurve(){return z().roll},get rcHeaveCurve(){return z().heave},aero:f,yawInertia:re(t,"I_yaw"),rollInertia:re(t,"I_roll"),pitchInertia:re(t,"I_pitch"),get steerFront(){return dm(e.front,L)},ackermannPct:re(t,"ackermann_pct"),toeFrontDeg:re(t,"toe_front_deg"),toeRearDeg:re(t,"toe_rear_deg")};return j}var aP=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}),Fx={ggvMode:"twoTrack"},oP=new WeakMap;function Cx(e,t=Fx){let r=oP.get(e.vehicle);r||oP.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={...aP(e.params),suspensionOf:()=>e.vehicle};n.set(o,a=ca(e.params,s,t))}return a}var sP=(e=Fx)=>t=>Cx(t,e),iP=(e=Fx)=>t=>nP(t.vehicle,ux(t.params,aP(t.params),e),t.params.tireModel,t.params.tireModelRear);function VG(e,t){return Cx(e,t.switches)}var Tx=e=>Rr(e?.rulesets);function cP(e,t,r,n,o={},a=()=>r.standingStart){let s=Cx(n,r.switches),i=(l,u)=>{let m=cp(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 lP=e=>[...new Set(e.lap.courses.flatMap(t=>t.course.kind==="track"?[t.course.trackId]:[]))],uP=e=>{let t=e?.session;return t?{sessionParams:r=>VG(r,t),session:()=>t}:{}},Rl=e=>({metrics:Tx(e),assemble:iP(e?.switches),simParams:sP(e?.switches),projectTrack:()=>e?.course??null,libraryTrack:t=>e?.tracks?.[t]??null,numerics:e?.numerics,...uP(e)}),BG=(e,t)=>({density:e.density,envelope:e.envelope,states:e.states,operating:e.operating,assemble:iP(t)}),$G=(e,t)=>({...BG(e,t?.switches),lap:e.lap,simParams:sP(t?.switches),projectTrack:()=>t?.course??null,libraryTrack:r=>t?.tracks?.[r]??null,numerics:t?.numerics,...uP(t)}),mP="nelder-mead",pP=600,xl=[0,.15,.15];function dP(e,t,r,n=xl.length){let o=Dx(t);return xl.slice(0,Math.max(1,n)).map((a,s)=>({...e,seed:s+1,startJitter:a,car:o,...r?{lap:r}:{}}))}function fP(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 hP(e,t,r,n,o=.01){let a=Tx(n).byId;return GG(e,t,r,n).filter(s=>s.excess>-o*(a[s.metricId]?.scale??1))}function GG(e,t,r,n){let o;try{o=Zn(Ds(e,t,r),$G(t,n))}catch{return[]}return KG(o,t,Tx(n))}function KG(e,t,r){let n=[];for(let o of t.constraints){let a=r.byId[o.metricId];if(!a)continue;let s=Ft(e,a,o.at);if(!Number.isFinite(s))continue;let i=`${it(a)}${aa(o.at,a)}`;n.push({key:o.key,metricId:o.metricId,label:i,unit:a.unit==="-"?"":a.unit,value:s,excess:to(o,s)})}return n}var HG=.05;function zG(e,t){if(t.id.startsWith("hp.")||cd(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(eo(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 Vy(An(o.hardpoints,n[2]),n[3],1)}function bP(e,t,r){let n=r.filter(d=>d.score.feasible);if(n.length<2)return null;let o=t.map(d=>zG(e,d)),a=o.every(d=>d!==null)?"mm":null,s=0,i="",c=0,l=n.reduce((d,p)=>p.score.total<d.score.total?p:d);for(let d of n)if(d!==l)for(let p=0;p<t.length;p++){let h=Math.abs(d.x[p]-l.x[p])*(o[p]??1);c+=h*h,h>s&&(s=h,i=t[p].name)}let u=n.map(d=>d.score.total),m=l.score.terms.reduce((d,p)=>d+(p.resolution??0),0);return{distance:Math.sqrt(c),worst:s,worstName:i,scoreSpread:Math.max(...u)-Math.min(...u),tolerance:Math.max(HG,m),unit:a}}var YG={steeringSystem:!0,brakeSetup:!0,driveline:!0,heaveFrontDesign:!0,heaveRearDesign:!0,arbFrontDesign:!0,arbRearDesign:!0},gP=e=>Object.hasOwn(YG,e);function wx(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 WG(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":gP(t)||wx(e)?"block":null}function Px(e,t){t=Ct(e,t);let r=_t(e);return[...t.variables,...t.followers??[]].filter(n=>r[n.id]&&!r[n.id].supersededBy&&!WG(n.id)).map(n=>bt(r[n.id]))}function yP(e,t,r){t=Ct(e,t);let n=_t(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,d,p,h]=c.id.split(".");if(m==="rocker"){let f=`${d}.rocker`;if(i.has(f))continue;i.add(f);let b=d==="front"?o.vehicle.front:o.vehicle.rear;for(let g of[zr.fore,zr.aft]){let y=b.hardpoints[g];for(let x=0;x<3;x++)a.push({kind:"hardpoint",axle:d,key:g,axis:x,value:y[x]})}}else if(m==="arm"){let f=`${d}.${p}`;if(i.has(f))continue;i.add(f);let b=d==="front"?o.vehicle.front:o.vehicle.rear,g=rr[p];for(let y of[g.fore,g.aft]){let x=b.hardpoints[y];for(let k=0;k<3;k++)a.push({kind:"hardpoint",axle:d,key:y,axis:k,value:x[k]})}}else if(m==="hp"&&ur(c.id)){let f=`${d}.${p}`;if(i.has(f))continue;i.add(f);let b=(d==="front"?o.vehicle.front:o.vehicle.rear).hardpoints[p];for(let g=0;g<3;g++)a.push({kind:"hardpoint",axle:d,key:p,axis:g,value:b[g]})}else if(m==="hp")a.push({kind:"hardpoint",axle:d,key:p,axis:"xyz".indexOf(h),value:u});else if(m==="cfg")a.push({kind:"config",axle:d,field:p,value:u});else if(m==="kc"){if(s.has(`kc.${d}`))continue;s.add(`kc.${d}`);let f=d==="front"?o.vehicle.front:o.vehicle.rear;a.push({kind:"compliance",axle:d,value:f.compliance})}else if(m==="param")a.push({kind:"param",label:bt(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(gP(m)||wx(c.id)){let f=wx(c.id)??m;if(s.has(f))continue;s.add(f);let b=o.params[f];if(!b)throw new Error(`optimiser: "${c.id}" left the car with no ${f} to adopt`);a.push({kind:"block",key:f,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=Rl(e.lap),n=e.follow?Zy(e.car,e.spec,r):e.spec,{dead:o,unprobed:a,...s}=rx(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 xP(e){let t=performance.now();return{tolerance:px(e.car,e.spec,e.x,Rl(e.lap),e.mm),elapsedMs:performance.now()-t}}var Dx=e=>e.vehicle.chassis?{...e,vehicle:dx(e.vehicle)}:e;function RP(e,t){try{let r=Ex(e.car,e.spec,e.lap),n=Ga.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:rn(r.variables),score:tn(r,rn(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&&Yy(r.variables)?jy(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 Ex=(e,t,r)=>pd(e,t,Rl(r));function vP(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),...Ui(e,t.damper)}}function kP(e,t,r,n){let{tireModelRear:o,damperModelRear:a,heaveDamperModel:s,rollDamperModel:i,...c}=r;return{vehicle:e,params:{...t,...c,...o?{tireModelRear:o}:{},...a?{damperModelRear:a}:{},...s?{heaveDamperModel:s}:{},...i?{rollDamperModel:i}:{}},...Yo(n)?{sessionAir:!0}:{}}}var MP=e=>({ggvMode:e.ggvMode,quasiTransient:e.quasiTransient===!0&&e.ggvMode!=="fast",motorThermal:e.motorThermal===!0,...jC({brakeFade:e.brakeFade===!0,airTempC:e.airTempC,diffYaw:e.diffYaw===!0,...e.air?{air:e.air}:{}})});function jG(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 SP(e,t){let r=t.plannedPath!==void 0,n=jG(t);return{...cP(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 Ix(e,t){let r=e.vehicles.find(o=>o.id===t);if(!r)throw new Error(`this project holds no vehicle "${t}"`);let n=ia(e);return kP(structuredClone(lx(e,r.params)),structuredClone(r.params),vP(r.params,n),la(e).air)}var UG="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 _x(e,t,r,n){if(e.settings.pathPlanId)throw new Error(UG);let o=la(e),a=e.tracks.length?(await hd(e,t)).asset:null,s={};for(let i of n?lP(n):[]){let c=e.tracks.find(l=>l.id===i);c&&(s[i]=await fl(c,t))}return SP(r,{track:a,numerics:o.numerics,racingLine:o.racingLine,standingStart:o.standingStart,lapCounts:o.lapCounts??{},switches:MP(o),rulesets:e.rulesets??[],library:s,standingOf:i=>e.tracks.find(c=>c.id===i)?.standingStart===!0})}async function AP(e,t,r,n){let o=Ix(e,r),a=Ct(o,n),s=await _x(e,t,o,a);return Lx({id:0,car:o,spec:a,lap:s})}async function wP(e,t,r,n){let o=Ix(e,r),a=Ct(o,n),s=Px(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 _x(e,t,o,a)}catch(l){return{problems:[l instanceof Error?l.message:String(l)]}}let c=tx(o,a,{...Rl(i),metrics:Rr(e.rulesets)});return c.length?{problems:c}:{problems:[],msPerEval:Lx({id:0,car:o,spec:a,lap:i}).msPerEval,carFingerprint:Go(Dx(o))}}async function XG(e,t,r,n,o,a=[]){let s=dP(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 d=[],p=null,h=null;if(RP(m,y=>{y.kind==="progress"?(d.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}:h=y.message}),h)throw new Error(h);if(!p)throw new Error("the search stopped without a result");let{result:f,elapsedMs:b}=p,g={seed:m.seed,startJitter:m.startJitter,x:f.x,score:f.score,evaluations:f.evaluations,infeasible:f.infeasible,history:f.history,trace:d,elapsedMs:b,...f.snapped?{snapped:f.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 FP(e,t,r,n){let o=Ix(e,r.vehicleId),a=Ct(o,r.spec),s=Px(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 _x(e,t,o,a),c=r.method??mP;if(!Ga.some(x=>x.name===c))throw new Error(`unknown method "${c}" \u2014 it is one of ${Ga.map(x=>x.name).join(", ")}`);let l=r.budget??pP,u=Math.max(1,Math.min(r.seeds??xl.length,xl.length)),m=await XG(o,{spec:a,method:c,budget:l},i,u,n),d=Ex(o,a,i),p=m.runs.map(x=>({seed:x.seed,startScore:m.designScore.total,score:x.score.total,feasible:x.score.feasible,...x.score.reason?{reason:x.score.reason}:{},terms:x.score.terms,x:x.x,evaluations:x.evaluations,infeasible:x.infeasible,bounds:fP(d.variables,x.x),constraints:hP(o,a,x.x,i),...x.snapped?{onSteps:{x:x.snapped.x,score:x.snapped.score.total,feasible:x.snapped.score.feasible,...x.snapped.score.reason?{reason:x.snapped.score.reason}:{},terms:x.snapped.score.terms}}:{}})),h=m.runs.reduce((x,k)=>vi(k.score,x.score)?k:x),f=h.snapped?.score.feasible?h.snapped:null,b=f?f.x:h.x,g=r.tolerance??yd,y=h.score.feasible&&g>0?xP({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?bP(o,d.variables,m.runs.map(x=>({x:x.x,score:x.score}))):null,writes:yP(o,a,b),...h.snapped?{adopts:f?"on its steps":`as found: on its steps it breaks a hold (${h.snapped.score.reason??"not legal"})`}:{},...y?{asBuilt:y}:{}}}function TP(){if(typeof process.threadCpuUsage!="function")return performance.now();let e=process.threadCpuUsage();return(e.user+e.system)/1e3}async function QG(e,t){let r=zC(e.root);switch(e.kind){case"sweep":return rT(e.doc,r,e.req,t);case"convergence":return eT(e.doc,r,{vehicleId:e.vehicleId,...e.steps?{steps:e.steps}:{},...e.tolPct!==void 0?{tolPct:e.tolPct}:{},onStep:t});case"study":return FP(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 bd(e.doc,r,{...e.vehicleIds?{vehicleIds:e.vehicleIds}:{},...e.settings?{settings:e.settings}:{},...e.overrides?{overrides:e.overrides}:{}});case"probe":return AP(e.doc,r,e.vehicleId,e.spec);case"quote":return wP(e.doc,r,e.vehicleId,e.spec)}}if(CP){let e=CP,t=r=>e.postMessage(r);(async()=>{try{let r=await QG(qG,(n,o)=>t({type:"progress",done:n,total:o}));t({type:"done",result:r,cpuMs:TP()})}catch(r){t({type:"failed",message:r instanceof Error?r.message:String(r),cpuMs:TP()})}})()}export{QG as runJob,TP as threadCpuMs};
|