@pacedyn/mcp 1.57.1 → 1.57.3
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 +59 -59
- 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 mI,workerData as iY}from"node:worker_threads";import{readFileSync as w1}from"node:fs";import{join as C1}from"node:path";var Du=e=>e.format!=="points"&&!e.field;var kt=e=>e?.kind==="ice";var lv={packVoltageMax:600,segmentVoltageMax:120,powerLimitKw:80};var Je=e=>typeof e=="number"&&Number.isFinite(e);function pI(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 fI(e){return!e||typeof e!="object"?"The cell has no curve.":e.kind==="table"?pI(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 Eu(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=fI(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 Bo(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 et(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 Iu(e,t,r,n,o){let a=e.length,s=t.length;if(a===0||s===0)return 0;let i=Bo(e,n),c=Bo(t,o),l=Math.min(i.i+1,a-1),u=Math.min(c.i+1,s-1),d=r[c.i][i.i],p=r[c.i][l],m=r[u][i.i],f=r[u][l],h=d+i.t*(p-d),b=m+i.t*(f-m);return h+c.t*(b-h)}var as=[0,.05,.1,.2,.3,.4,.5,.6,.7,.8,.9,1],hh={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]},uv=[0,.05,.1,.2,.5,.8,1],mv=[2.2,1.55,1.3,1.12,1,.97,.98];function dv(e){return et(uv,mv,e)}var pv=[-20,-10,0,10,25,40,60],fv=[4,2.8,2,1.4,1,.82,.75];function bh(e){return et(pv,fv,e)}var hv=.5;function gh(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=hh[t]??hh.other,l=e.socAtNom??hv,u=as.includes(l)?[...as]:[...as,l].sort((h,b)=>h-b),d=et(as,c,l),p=d>0&&d<1?Math.log(i)/Math.log(d):1,m=[],f=[];for(let h of u){let b=et(as,c,h);m.push(o+s*Math.pow(b,p)),f.push(e.constantResistance?a:a*dv(h))}return{kind:"table",soc:u,ocv:m,r0:f}}function yh(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+=(et(t,r,s)+et(t,r,i))/2*(i-s)}return o}var ss=25,bv=new WeakMap;function An(e){let t=bv.get(e);if(t)return t;let r=Eu(e);if(r)throw new Error(r);let{cell:n,pack:o}=e,a=n.curve.kind==="table"?n.curve:gh(n.curve,n.chemistry),s=o.series,i=o.parallel,c=s/i,l=a.rTempC,u=a.rGrid,d=i*n.capacityAh,p=s*n.vMin,m=n.iMaxA>0?i*n.iMaxA:1/0,f=n.iMaxChargeA!==void 0&&n.iMaxChargeA>0?n.iMaxChargeA:n.iMaxA/4,h=f>0?i*f:1/0,b=S=>s*et(a.soc,a.ocv,S),g=(S,w=ss)=>{let F=l&&u?Iu(a.soc,l,u,S,w):et(a.soc,a.r0,S)*bh(w);return c*F+o.busResistance},y=(S,w,F)=>b(S)-w*g(S,F),x=(S,w,F)=>{if(!(S>0))return 0;let T=b(w),A=g(w,F);if(!(A>0))return S/T;let C=T*T-4*A*S;return C<0?NaN:2*S/(T+Math.sqrt(C))},v=(S,w,F)=>{if(!(S>0))return 0;let T=b(w),A=g(w,F);return A>0?2*S/(T+Math.sqrt(T*T+4*A*S)):S/T},k=S=>{let w=e.thermal;if(!w||w.derateFromC===void 0)return 1;let F=w.derateToC??w.derateFromC;return S<=w.derateFromC?1:!(F>w.derateFromC)||S>=F?0:1-(S-w.derateFromC)/(F-w.derateFromC)},R=(S,w,F=0)=>{let T=b(S),A=g(S,w),C=A>0?T/(2*A):1/0,P=$=>{if(!(A>0))return $*T;let N=Math.min($,C);return N*(T-N*A)},L=A>0?Math.max(0,(T-p)/A):1/0,E=F>0&&Number.isFinite(F)?F:1/0,_=A>0?P(L):1/0,D=Number.isFinite(m)?P(m):1/0,I=A>0?T*T/(4*A):1/0,V=[["rules",E],["voltage-floor",_],["current",D],["matched-load",I]],O=V[0][0],B=V[0][1];for(let[$,N]of V)N<B&&(B=N,O=$);let z=k(w??ss);z<1&&(B=Number.isFinite(B)?B*z:B,O="temperature");let j=Number.isFinite(B)?x(B,S,w):1/0;return{watts:B,binding:O,rules:E,voltageFloor:_,current:D,matchedLoad:I,derate:z,amps:j,volts:Number.isFinite(j)?T-j*A:T}},M={model:e,table:a,capacityAh:d,chargeC:d*3600,energyKwh:d*(s*yh(a))/1e3,socRange:[a.soc[0],a.soc[a.soc.length-1]],voltageAtFull:s*a.ocv[a.ocv.length-1],voltageCeiling:s*n.vMax,voltageFloor:p,currentCeiling:m,chargeCurrentCeiling:h,massKg:n.massKg!==void 0?s*i*n.massKg:null,thermal:e.thermal?{heatCapacityJPerK:s*i*e.thermal.heatCapacityJPerK,coolingWPerK:s*i*e.thermal.coolingWPerK,...e.thermal.startC!==void 0?{startC:e.thermal.startC}:{},entropicVPerK:s*(e.thermal.entropicVPerK??0)}:null,derateAt:k,ocv:b,resistance:g,terminalVoltage:y,currentFor:x,chargeCurrentFor:v,maxPower:R};return bv.set(e,M),M}function xh(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 gv={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},yv={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},xv={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 Rh(){return{name:"Formula Student accumulator",cell:xh(gv),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 vh(){return{name:"LFP pack",cell:xh(yv),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 kh(){return{name:"Road car pack",cell:xh(xv),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 Mh(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 _u(e){if(e.kind==="ice"){let n=e.gearbox.efficiency;return{model:e,maxTorque:o=>o>e.limitRpm?0:et(e.rpm,e.torque,o),efficiency:()=>n}}let t=n=>et(e.rpm,e.torque,n),r=e.kind==="simple"?()=>e.efficiency:(n,o)=>Iu(e.effRpm,e.effTorque,e.effGrid,n,o);return{model:e,maxTorque:t,efficiency:r}}function Sh(e){let t=e.resistanceAtC??20,r=e.torqueConstant,n=e.speedLossW??0,o=e.speedLossAtRpm??0,a=e.speedLossExponent??1.5,s=e.derateFromC,i=e.derateToC,c=f=>Math.max(0,e.terminalResistanceOhm*(1+.00393*(f-t))),l=f=>n>0&&o>0?n*Math.pow(Math.max(0,f)/o,a):0,u=(f,h,b)=>{let g=r>0?Math.abs(h)/r:0;return 1.5*c(b)*g*g+l(f)},d=(f,h)=>{let b=e.coolingWPerK*(h-e.coolantC)-l(f);return!(b>0)||r<=0?0:r*Math.sqrt(b/(1.5*c(h)))},p=e.coolingWPerK>0?e.heatCapacityJPerK/e.coolingWPerK:1/0,m=Number.isFinite(p)?.25*p:1/0;return{spec:e,startC:e.startC??e.coolantC,lossW:u,step(f,h,b){if(!(b>0)||!(e.heatCapacityJPerK>0))return f;let g=Number.isFinite(m)?Math.max(1,Math.ceil(b/m)):1,y=b/g,x=f;for(let v=0;v<g;v++)x+=(h-e.coolingWPerK*(x-e.coolantC))*y/e.heatCapacityJPerK;return x},continuousTorque:d,derate(f,h,b){if(s===void 0||i===void 0||!(i>s)||!(b>0)||h<=s)return 1;let g=Math.min(1,d(f,i)/b);return h>=i?g:1-(1-g)*(h-s)/(i-s)},equilibriumC(f){return e.coolingWPerK>0?e.coolantC+f/e.coolingWPerK:1/0}}}function yt(e,t){return t==="rear"&&e.tireRateRear!==void 0?e.tireRateRear:e.tireRate}function Ah(e,t){let r=e.tyreFreeRadiusRear;return(t==="rear"&&r!==void 0?r:e.tyreFreeRadius)??0}var Nu=9.81,Rv=(e,t)=>e*(t*t)/2*(Math.PI/180)/1e3,Ki=(e,t)=>e+t>0?e*t/(e+t):0,vv=.5;function Ou(e,t,r){if(!(r>0))return 1;let n=e*Nu*t*(Math.PI/180)/r;return 1/(1-Math.min(vv,n))}function kv(e,t,r,n){let o=r??0,a=e+t;if(!(o>0)||!Number.isFinite(o)||!(a>0))return null;let s=Math.max(0,Math.min(1,n)),i=e*t+o*a,c=a*(s*t+o)/i,l=a*((1-s)*e+o)/i;return{share:e/a*c,front:c,rear:l}}function wh(e,t,r){return r>0?e*Nu*t/(r*r):0}function Mv(e,t,r,n,o){if(!(n>0)||!(o>0))return 1;let a=wh(e,t,r)*(1/n+1/o);return 1/(1-Math.min(vv,a))}function Ge(e){let t=4*e.unsprungPerCorner,r=Math.max(0,e.massTotal-t),n=r*e.frontMassFrac,o=r*(1-e.frontMassFrac),a=yt(e,"front"),s=yt(e,"rear"),i=e.wheelRateFront+(e.heaveSpringFront??0),c=e.wheelRateRear+(e.heaveSpringRear??0),l=Ki(i,a),u=Ki(c,s),d=(B,z)=>{let j=z/2;return j>0?1/(2*Math.PI)*Math.sqrt(B*1e3/j):0},p=d(l,n),m=d(u,o),f=Ki(e.wheelRateFront+e.arbFront,a),h=Ki(e.wheelRateRear+e.arbRear,s),b=Rv(f,e.trackFront),g=Rv(h,e.trackRear),y=b+g,x=y>0?b/y:.5,v=e.rcHeightFront+(e.rcHeightRear-e.rcHeightFront)*(1-e.frontMassFrac),k=(e.cgHeight-v)/1e3,R=r*Nu*k,M=Ou(r,k,y),S=y>0?R/y*M:0,w=kv(b,g,e.chassisTorsion,e.frontMassFrac),F=w?w.share:x,T=w?S*w.front:S,A=w?S*w.rear:S,C=e.massTotal*Nu*e.cgHeight/e.wheelbase,P=2*l,L=2*u,E=Mv(r,e.cgHeight,e.wheelbase,P,L),D=(P>0&&L>0?(C/P+C/L)/e.wheelbase*E:0)*(180/Math.PI),I=e.wheelbase*e.wheelbase*Ki(P,L)*(Math.PI/180)/1e3,V=e.damperFront??2.5,O=e.damperRear??2.5;return{sprungMass:r,sprungFront:n,sprungRear:o,rideRateFront:l,rideRateRear:u,rideFreqFront:p,rideFreqRear:m,rollRateFront:b,rollRateRear:g,rollRateTotal:y,rollWheelRateFront:f,rollWheelRateRear:h,frontRollStiffFrac:x,frontElasticShare:F,rollGradient:S,rollGradientFront:T,rollGradientRear:A,pitchGradient:D,pitchRate:I,cgRollGain:M,cgPitchGain:E,rideDampingFront:V+(e.heaveDamperFront??0),rideDampingRear:O+(e.heaveDamperRear??0),rollDampingFront:V+(e.rollDamperFront??0),rollDampingRear:O+(e.rollDamperRear??0)}}var lo=["clFront","clRear","cd"],uo=e=>e.frame?.kind==="pitch";function is(e){return uo(e)?{x:e.axes.h,y:e.axes.pitch}:{x:e.axes.hFront,y:e.axes.hRear}}var Vu=e=>e.frame?.kind==="pitch",Sv=e=>e.kind==="map";var Bu=45,Mt=e=>typeof e=="number"&&Number.isFinite(e);function $u(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(Mt))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 Av(e,t){if(t===void 0)return null;for(let r of lo){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(Mt)||!n.factor.every(Mt))return`The ${e} correction of ${r} contains a value that is not a number.`;if(n.deg[0]<0)return`The ${e} correction of ${r} is against the absolute angle; it cannot start below zero.`;for(let o=1;o<n.deg.length;o++)if(!(n.deg[o]>n.deg[o-1]))return`The ${e} correction of ${r} must increase in angle (${n.deg[o-1]} then ${n.deg[o]}\xB0).`;if(n.factor.some(o=>o<0))return`The ${e} correction of ${r} has a negative factor.`}return null}function wv(e,t){return t===void 0?null:!Mt(t.dCl)||!Mt(t.dBalance)||!Mt(t.dCd)?`The ${e} slopes must be numbers.`:!Mt(t.maxDeg)||!(t.maxDeg>0)?`The ${e} response needs a positive angle to be valid to.`:null}function Hi(e){if(!e||typeof e!="object")return"Not an aero model.";if(!Mt(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=$u("front ride-height",e.axes?.hFront);if(i)return i;let c=$u("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(!Mt(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=$u("ride-height",e.axes?.h);if(i)return i;let c=$u("pitch",e.axes?.pitch,"\xB0","pitch");if(c)return c;let l=e.axes.pitch.find(u=>Math.abs(u)>=Bu);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 lo){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(Mt))return`${i} contains a value that is not a number.`}}return Av("yaw",e.attitude?.yaw)??Av("roll",e.attitude?.roll)}if(e.kind==="sensitivity"){let t;if(e.frame==null)t=["hFront","hRear"];else if(e.frame?.kind==="pitch"){if(!Mt(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||!Mt(r[t[0]])||!Mt(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 lo){if(!e.at||!Mt(e.at[s]))return`${s} at the reference must be a number.`;let i=n?.[s];if(!i||!Mt(i[t[0]])||!Mt(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||!Mt(i[0])||!Mt(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])>=Bu||Math.abs(i[1])>=Bu))return`A pitch range reaching ${Math.abs(i[0])>=Bu?i[0]:i[1]}\xB0 is not a car's attitude. Pitch is in degrees.`}return wv("yaw",e.attitude?.yaw)??wv("roll",e.attitude?.roll)}return`Unknown aero model kind "${e.kind}".`}var Cv=180/Math.PI;function cs(e,t,r,n){let o=(n-r)/t;return{h:r+e.refX*o,pitch:Math.atan(o)*Cv}}function ls(e,t,r,n){let o=Math.tan(n/Cv);return{hFront:r-e.refX*o,hRear:r+(t-e.refX)*o}}var jY=180/Math.PI,hI=["hFront","hRear"],bI=["h","pitch"],Th=e=>e?.kind==="pitch"?bI:hI,ar=(e,t)=>e[t],Gu=(e,t)=>e[t],Ch=(e,t)=>({[e[0]]:t(e[0]),[e[1]]:t(e[1])});function gI(e){if(!(!e.yaw&&!e.roll))return{...e.yaw?{yaw:{...e.yaw}}:{},...e.roll?{roll:{...e.roll}}:{}}}function Ph(e){let t=Th(e.frame),r=e.balanceFront,n=e.cl*r,o=e.cl*(1-r),a=Ch(t,c=>ar(e.dCl,c)*r+e.cl*ar(e.dBalance,c)),s=Ch(t,c=>ar(e.dCl,c)*(1-r)-e.cl*ar(e.dBalance,c)),i=gI(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:Ch(t,c=>ar(e.dCd,c))},range:{[t[0]]:[...Gu(e.range,t[0])],[t[1]]:[...Gu(e.range,t[1])]},provenance:{...e.provenance},...i?{attitude:i}:{}}}function Ku(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 Fh(e,t,r=11){let n=Array.from({length:r},(a,s)=>t.maxDeg*s/(r-1)),o=n.map(a=>Ku(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 Fv(e){if(!(!e.attitude?.yaw&&!e.attitude?.roll))return{...e.attitude.yaw?{yaw:Fh(e.at,e.attitude.yaw)}:{},...e.attitude.roll?{roll:Fh(e.at,e.attitude.roll)}:{}}}function Tv(e,t,r,n=0,o=0){let[a,s]=Th(e.frame),i=t-ar(e.ref,a),c=r-ar(e.ref,s),l={clFront:e.at.clFront+ar(e.slope.clFront,a)*i+ar(e.slope.clFront,s)*c,clRear:e.at.clRear+ar(e.slope.clRear,a)*i+ar(e.slope.clRear,s)*c,cd:e.at.cd+ar(e.slope.cd,a)*i+ar(e.slope.cd,s)*c},u=e.attitude?.yaw?Ku(e.at,e.attitude.yaw,n):{clFront:1,clRear:1,cd:1},d=e.attitude?.roll?Ku(e.at,e.attitude.roll,o):{clFront:1,clRear:1,cd:1};return{clFront:l.clFront*u.clFront*d.clFront,clRear:l.clRear*u.clRear*d.clRear,cd:l.cd*u.cd*d.cd}}function Lh(e){let[t,r]=Th(e.frame),n=[...Gu(e.range,t)],o=[...Gu(e.range,r)],a=i=>o.map(c=>n.map(l=>i(Tv(e,l,c)))),s=Fv(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 Dh=180/Math.PI,Pv=new WeakMap,Lv=new WeakMap,Eh=new WeakMap;function mo(e,t){let r=Lv.get(e);if(r)return r;let n=t?.wheelbase,o=n!==void 0?Eh.get(e)?.get(n):void 0;if(o)return o;let a=yI(e),s=a.map;if(!uo(s)){let l=xI(e,a);return Lv.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=RI(e,a,s.frame,n),c=Eh.get(e);return c||(c=new Map,Eh.set(e,c)),c.set(n,i),i}function yI(e){let t=Pv.get(e);if(t)return t;let r=Hi(e);if(r)throw new Error(r);let n=e.kind==="map"?e:Lh(e),{x:o,y:a}=is(n),s=o.length,i=a.length,c=n.attitude?.yaw,l=n.attitude?.roll,u=!!(c||l),d={clFront:1,clRear:1,cd:1,clamped:!1},p=(y,x)=>{let v=Math.abs(x),k=y.clFront.deg[y.clFront.deg.length-1];return{clFront:et(y.clFront.deg,y.clFront.factor,v),clRear:et(y.clRear.deg,y.clRear.factor,v),cd:et(y.cd.deg,y.cd.factor,v),clamped:v>k}},m=(y,x)=>{if(!u)return d;let v=c?p(c,y):d,k=l?p(l,x):d;return{clFront:v.clFront*k.clFront,clRear:v.clRear*k.clRear,cd:v.cd*k.cd,clamped:v.clamped||k.clamped}},f=(y,x,v=0,k=0)=>{let R=Bo(o,y),M=Bo(a,x),S=Math.min(R.i+1,s-1),w=Math.min(M.i+1,i-1),F=A=>{let C=A[M.i][R.i],P=A[M.i][S],L=A[w][R.i],E=A[w][S],_=C+R.t*(P-C),D=L+R.t*(E-L);return _+M.t*(D-_)},T=m(v,k);return{clFront:u?F(n.clFront)*T.clFront:F(n.clFront),clRear:u?F(n.clRear)*T.clRear:F(n.clRear),cd:u?F(n.cd)*T.cd:F(n.cd),clampedRide:R.clamped||M.clamped,clampedAttitude:T.clamped}},h={x:[o[0],o[s-1]],y:[a[0],a[i-1]]},b=(y,x,v=!1,k=0,R=0)=>{let M=m(k,R),S=Bo(o,v?Math.min(Math.max(y,h.x[0]),h.x[1]):y),w=Bo(a,v?Math.min(Math.max(x,h.y[0]),h.y[1]):x),F=Math.min(S.i+1,s-1),T=Math.min(w.i+1,i-1),A=F>S.i?o[F]-o[S.i]:0,C=T>w.i?a[T]-a[w.i]:0,P={};for(let L of lo){let E=n[L],_=E[w.i][S.i],D=E[w.i][F],I=E[T][S.i],V=E[T][F],O=S.clamped||A===0?0:((D-_)*(1-w.t)+(V-I)*w.t)/A,B=w.clamped||C===0?0:((I-_)*(1-S.t)+(V-D)*S.t)/C;P[L]=u?{x:O*M[L],y:B*M[L]}:{x:O,y:B}}return P},g={map:n,x:h.x,y:h.y,hasAttitude:u,factors:m,at:f,slopes:b};return Pv.set(e,g),g}function xI(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 d of lo)u[d]={hFront:l[d].x,hRear:l[d].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 RI(e,t,r,n){let o=r.refX,a=o/n,s=(l,u,d=0,p=0)=>{let m=(u-l)/n;return t.at(l+o*m,Math.atan(m)*Dh,d,p)},i=(l,u,d=!1,p=0,m=0)=>{let f=(u-l)/n,h=t.slopes(l+o*f,Math.atan(f)*Dh,d,p,m),b=Dh/(n*(1+f*f)),g={};for(let y of lo)g[y]={hFront:h[y].x*(1-a)-h[y].y*b,hRear:h[y].x*a+h[y].y*b};return g},c={frame:r,x:t.x,y:t.y,at:t.at,toAxles:(l,u)=>ls(r,n,l,u),fromAxles:(l,u)=>{let d=cs(r,n,l,u);return{x:d.h,y:d.pitch}}};return{model:e,map:t.map,area:t.map.area,grid:c,hasAttitude:t.hasAttitude,at:s,slopes:i,factors:t.factors}}function Ih(e){let t=e.clFront+e.clRear;return{cl:t,balanceFront:t!==0?e.clFront/t:.5}}var Se=(e,t)=>e*t/100,xt=e=>e/100,Dv={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:xt(-.3),hRear:xt(.15)},dCd:{hFront:Se(1.3,-.1),hRear:Se(1.3,.05)},yaw:{dCl:Se(3,-1),dBalance:xt(-.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."},Ev={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:xt(-.15),hRear:xt(.15)},dCd:{hFront:Se(.9,-.15),hRear:Se(.9,-.05)},yaw:{dCl:Se(3,-1.5),dBalance:xt(.2),dCd:Se(.9,.8),maxDeg:8},roll:{dCl:Se(3,-1),dBalance:xt(-.3),dCd:0,maxDeg:2},note:"Assumed class-level sensitivities for a ground-effect floor, ride height, yaw and roll; not measured."},Iv={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:xt(-.25),hRear:xt(.15)},dCd:{hFront:Se(.42,-.1),hRear:0},yaw:{dCl:Se(1.4,-.8),dBalance:xt(-.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."},_v={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."},Nv={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:xt(-.25),hRear:xt(.15)},dCd:{hFront:Se(.4,-.1),hRear:0},yaw:{dCl:Se(.45,-1.2),dBalance:xt(-.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."},Ov={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:xt(-.25),hRear:xt(.15)},dCd:{hFront:Se(.45,-.1),hRear:0},yaw:{dCl:Se(.6,-1),dBalance:xt(-.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."},Vv={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:xt(-.25),hRear:xt(.15)},dCd:{hFront:Se(.9,-.1),hRear:Se(.9,.05)},yaw:{dCl:Se(2.5,-1),dBalance:xt(-.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."},Bv={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 wn(e){return Ph({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 _h=()=>wn(Dv),Nh=()=>wn(Ev),Oh=()=>wn(Iv),Vh=()=>wn(_v),Bh=()=>wn(Nv),$h=()=>wn(Ov),Gh=()=>wn(Vv),Kh=()=>wn(Bv);function $o(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 Hu(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,yt(e,"front")))/r,rear:(t.sprungMass*(1-n)+o*a(t.rideRateRear,yt(e,"rear")))/r}}function zu(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 Hh(e,t){return e.wheelbase>0?e.massTotal*t*9.81/e.wheelbase:0}function us(e,t,r){let n=2*t.rideRateFront,o=2*t.rideRateRear;return!(n>0)||!(o>0)?0:Math.min(wh(t.sprungMass,r,e.wheelbase),.5*n*o/(n+o))}function zi(e,t,r,n,o){let a=e.cgHeight,s=Hh(e,r);if(n===0&&o===0&&s===0)return{height:a,forward:0,noseLoad:0,dropFront:0,dropRear:0};let i=Hu(e,t),c=2*t.rideRateFront,l=2*t.rideRateRear,u=a,d=0,p=0,m=0;for(let h=0;h<6;h++){m=us(e,t,u);let b=n-s*u,g=o+s*u;if(m>0){let v=c*l-m*(c+l);d=(b*(l-m)-m*g)/v,p=(g*(c-m)-m*b)/v}else d=c>0?b/c:0,p=l>0?g/l:0;let y=zu(a,i,d,p),x=Math.abs(y-u);if(u=y,x<1e-9)break}let f=d-p;return{height:u,forward:e.wheelbase>0?u*f/e.wheelbase:0,noseLoad:m*f,dropFront:d,dropRear:p}}var zh={yawDeg:0,rollDeg:0},$v=1e-4,vI=40,Gv=50;function po(e,t,r=0){let n=e.aero?.model;if(!(!n||!mo(n,e).hasAttitude))return{yawDeg:r,rollDeg:Ge(e).rollGradient*t}}function ms(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 ls(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=Vu(r)?n(r.frame,r.ref.h,r.ref.pitch):r.ref;else if(r){let{x:a,y:s}=is(r),i=(a[0]+a[a.length-1])/2,c=(s[0]+s[s.length-1])/2;o=uo(r)?n(r.frame,i,c):{hFront:i,hRear:c}}return{hFront:e.rideHeightFront??o.hFront,hRear:e.rideHeightRear??o.hRear}}var Kv=new WeakMap;function Cn(e,t,r=0,n){let o=e.aero;if(!o?.model)return null;let a=Kv.get(e);a||(a=new Map,Kv.set(e,a));let s=n&&mo(o.model,e).hasAttitude?n:zh,i=s===zh?`${t}|${r}`:`${t}|${r}|${s.yawDeg.toFixed(3)}|${s.rollDeg.toFixed(3)}`,c=a.get(i);if(c)return c;let l=kI(e,o,t,r,s);return a.size>4096&&a.clear(),a.set(i,l),l}function kI(e,t,r,n,o){let a=mo(t.model,e),s=Ge(e),i=2*s.rideRateFront,c=2*s.rideRateRear,l=ms(t,e.wheelbase),u=.5*t.rho*r*r,d=a.area,p=e.wheelbase>0?t.copHeight/e.wheelbase:0,m=Hu(e,s),f=Hh(e,n),h=(F,T)=>zu(e.cgHeight,m,l.hFront-F,l.hRear-T),b=(F,T)=>l.hFront-F-(l.hRear-T),g=(F,T)=>{let A=a.at(F,T,o.yawDeg,o.rollDeg),C=u*d*A.clFront,P=u*d*A.clRear,L=u*d*A.cd,E=L*p,_=h(F,T),D=f*_,I=us(e,s,_)*b(F,T),V=C-D-E+I,O=P+D+E-I,B=F-l.hFront+(i>0?V/i:0),z=T-l.hRear+(c>0?O/c:0);return{c:A,downFront:C,downRear:P,drag:L,rF:B,rR:z,norm:Math.hypot(B,z)}},y=(F,T,A=!1)=>{let C=a.slopes(F,T,A,o.yawDeg,o.rollDeg),P=i>0?u*d/i:0,L=c>0?u*d/c:0;return[[P*(C.clFront.hFront-p*C.cd.hFront),P*(C.clFront.hRear-p*C.cd.hRear)],[L*(C.clRear.hFront+p*C.cd.hFront),L*(C.clRear.hRear+p*C.cd.hRear)]]},x=l.hFront,v=l.hRear,k=g(x,v),R=0;for(;k.norm>=$v&&R<vI;){R++;let F=y(x,v),T=i>0?f/i:0,A=c>0?f/c:0,C=us(e,s,h(x,v)),P=i>0?C/i:0,L=c>0?C/c:0,E=1+F[0][0]-T*m.front-P,_=F[0][1]-T*m.rear+P,D=F[1][0]+A*m.front+L,I=1+F[1][1]+A*m.rear-L,V=E*I-_*D,O,B;Math.abs(V)>1e-9?(O=-(I*k.rF-_*k.rR)/V,B=-(-D*k.rF+E*k.rR)/V):(O=-.5*k.rF,B=-.5*k.rR);let z=Math.max(1,Math.abs(O)/Gv,Math.abs(B)/Gv);O/=z,B/=z;let j=1;for(let $=0;$<6;$++){let N=g(x+j*O,v+j*B);if(N.norm<=k.norm||$===5){x+=j*O,v+=j*B,k=N;break}j*=.5}}let M=y(x,v,!0),S=2+M[0][0]+M[1][1],w=(1+M[0][0])*(1+M[1][1])-M[0][1]*M[1][0];return{v:r,axG:n,hFront:x,hRear:v,cgHeight:h(x,v),cgForward:e.wheelbase>0?h(x,v)*b(x,v)/e.wheelbase:0,cgNoseLoad:us(e,s,h(x,v))*b(x,v),clFront:k.c.clFront,clRear:k.c.clRear,cd:k.c.cd,area:d,downforce:k.downFront+k.downRear,drag:k.drag,downFront:k.downFront,downRear:k.downRear,gain:MI(M),stable:w>0&&S>0,converged:k.norm<$v,iterations:R,clampedRide:k.c.clampedRide,yawDeg:o.yawDeg,rollDeg:o.rollDeg,clampedAttitude:k.c.clampedAttitude}}function MI(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 Yi(e,t,r=0,n){let o=Cn(e,t,r,n);return o?{downforce:o.downforce,drag:o.drag,downFront:o.downFront,downRear:o.downRear}:e.aero?$o(e.aero,t):{downforce:0,drag:0,downFront:0,downRear:0}}function SI(e,t,r,n){let o=$o(t,r),a=Ge(e),s=ms(t,e.wheelbase),i=e.wheelbase>0?o.drag*t.copHeight/e.wheelbase:0,c=zi(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 Yh(e,t,r=0,n){let o=Cn(e,t,r,n);return o||(e.aero?SI(e,e.aero,t,r):null)}function Yu(e,t=0,r=0,n,o){if(e.aero&&t>0){if(e.aero.model){let i=Cn(e,t,r,n);return{height:i.cgHeight,forward:i.cgForward,noseLoad:i.cgNoseLoad}}let a=$o(e.aero,t),s=e.wheelbase>0?a.drag*e.aero.copHeight/e.wheelbase:0;return zi(e,o??Ge(e),r,a.downFront-s,a.downRear+s)}return r===0?{height:e.cgHeight,forward:0,noseLoad:0}:zi(e,o??Ge(e),r,0,0)}var Hv=[0,1,0],Wh=[0,0,1],oe=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],H=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],X=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],jh=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]],AI=e=>J(e,e),qr=e=>Math.sqrt(J(e,e)),Wi=(e,t)=>AI(H(e,t)),Pe=(e,t)=>qr(H(e,t)),te=e=>{let t=qr(e);return t<1e-12?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]},zv=(e,t,r)=>[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r,e[2]+(t[2]-e[2])*r];var Fn=(e,t,r)=>{let n=te(r),o=H(e,t);return oe(t,X(n,J(o,n)))},Yv=(e,t,r)=>Pe(e,Fn(e,t,r));var CI=1e-6;function FI(e){if(e<CI){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 Dt(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]=FI(r),a=le(e,t),s=le(e,a);return oe(t,oe(X(a,n),X(s,o)))}function sr(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 Dt(X(o,r),e)}function Qr(e,t){let r=t.length,n=e.map(a=>a.slice()),o=t.slice();return jv(n,o,r,new Array(r).fill(0))}function Wv(e,t,r){return jv(e,t,t.length,r)}function jv(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 d=Math.abs(e[u][s]);d>c&&(c=d,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 d=t[s];t[s]=t[i],t[i]=d}let l=e[s][s];for(let u=s+1;u<r;u++){let d=e[u][s]/l;if(d!==0){for(let p=s;p<r;p++)e[u][p]-=d*e[s][p];t[u]-=d*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 Uv=e=>{let t=0;for(let r of e)t=Math.max(t,Math.abs(r));return t},Xv=e=>{let t=0;for(let r of e)t+=r*r;return t},TI=Math.sqrt(Number.EPSILON);function qv(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=Uv(c),u=Xv(c),d=.001,p=1,m=c.length,f=Array.from({length:m},()=>new Array(a).fill(0)),h=Array.from({length:a},()=>new Array(a).fill(0)),b=Array.from({length:a},()=>new Array(a).fill(0)),g=new Array(a).fill(0),y=new Array(a).fill(0),x=new Array(a).fill(0),v=new Array(a).fill(0),k=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:p};for(let F=0;F<a;F++){let T=TI*Math.max(Math.abs(i[F]),s[F]);for(let C=0;C<a;C++)v[C]=i[C];v[F]+=T;let A=e(v);for(let C=0;C<m;C++)f[C][F]=(A[C]-c[C])/T}let M=0;for(let F=0;F<a;F++){for(let A=0;A<a;A++){let C=0;for(let P=0;P<m;P++)C+=f[P][F]*f[P][A];h[F][A]=C}let T=0;for(let A=0;A<m;A++)T+=f[A][F]*c[A];g[F]=T,M=Math.max(M,h[F][F])}let S=Math.max(M,1e-9),w=!1;for(let F=0;F<18;F++){let T=d*S;for(let C=0;C<a;C++){let P=h[C],L=b[C];for(let E=0;E<a;E++)L[E]=C===E?P[E]+T:P[E];y[C]=-g[C]}let A=Wv(b,y,x);if(p=Math.max(p,A.condProxy),!A.singular){for(let L=0;L<a;L++)k[L]=i[L]+x[L];let C=e(k),P=Xv(C);if(P<u){for(let L=0;L<a;L++)i[L]=k[L];c=C,u=P,l=Uv(c),d=Math.max(d*.3,1e-12),w=!0;break}}d=Math.min(d*4,1e12)}if(!w)break}return{x:i,residualNorm:l,iterations:n,converged:l<o,condProxy:p}}function ji(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,d=l*t/a;return{c1:u,s1:d,c2:u,s2:d,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 Uh(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 Qv=e=>[e[0],-e[1],-e[2],-e[3]];function ds(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 Wu(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 Zv(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 Xh(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],d=r[2],p=n+i+d;if(p>=n&&p>=i&&p>=d){let h=Math.sqrt(1+p),b=.5/h;return[.5*h,(c-u)*b,(l-a)*b,(o-s)*b]}if(n>=i&&n>=d){let h=Math.sqrt(1+n-i-d),b=.5/h;return[(c-u)*b,.5*h,(s+o)*b,(l+a)*b]}if(i>=d){let h=Math.sqrt(1-n+i-d),b=.5/h;return[(l-a)*b,(s+o)*b,.5*h,(u+c)*b]}let m=Math.sqrt(1-n-i+d),f=.5/m;return[(o-s)*f,(l+a)*f,(u+c)*f,.5*m]}function Jv(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 ek(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 PI(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 LI(e){let t=e.hardpoints,r=te(H(t.damperChassis,t.pushrodOuter)),[n,o]=PI(r);return{top:t.damperChassis,lower0:t.pushrodOuter,axis0:r,e1:n,e2:o}}function qh(e){let t=e.hardpoints,r=t.wheelCenter,n=te(H(t.ucaRear,t.ucaFront)),o=H(t.uprightUpper,t.ucaFront),a=J(o,n),s=H(o,X(n,a)),i=J(s,s),c=te(H(t.lcaRear,t.lcaFront)),l=H(t.uprightLower,t.lcaFront),u=Wi(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:LI(e)}:{}}}function Rr(e,t,r){let n=[t[3],t[4],t[5]],o=[t[0],t[1],t[2]],a=H(r,e.c0);return oe(oe(Dt(n,a),e.c0),o)}function Qh(e,t){return oe(e.lcaFront,sr(e.lbjRel0,e.lcaDir,t))}function Go(e,t){return e.steerMovesRack?oe(e.tieInner0,X(e.rackAxis,t)):e.tieInner0}function Zh(e,t,r,n){let o=Rr(e,t,e.lbj0),a=Qh(e,r),s=o[0]-a[0],i=o[1]-a[1],c=o[2]-a[2],l,u;if(e.strut){let f=e.strut,h=[t[3],t[4],t[5]],b=H(f.top,Rr(e,t,f.lower0));l=J(b,Dt(h,f.e1)),u=J(b,Dt(h,f.e2))}else{let f=Rr(e,t,e.ubj0),h=H(f,e.ucaFront),b=J(h,e.ucaDir),g=H(h,X(e.ucaDir,b));l=b-e.ubjAxial0,u=(J(g,g)-e.ubjRadius2)/e.ubjRadiusRef}let d=Rr(e,t,e.tro0),p=Go(e,n),m=(Wi(d,p)-e.tieLen2)/e.tieLenRef;return[s,i,c,l,u,m]}var Ui=e=>Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]),ju=e=>{let t=Ui(e);return[e[0]/t,e[1]/t,e[2]/t]},DI=(e,t)=>H(e,X(t,J(e,t))),Jh=e=>ju(le(e,Math.abs(e[0])<.6?[1,0,0]:[0,1,0]));function EI(e,t){let r=e.ucaDir,n=oe(e.ucaFront,X(r,e.ubjAxial0)),o=Math.sqrt(e.ubjRadius2),a=DI(H(e.ubj0,e.ucaFront),r),s=Ui(a)>1e-9?ju(a):Jh(r),i=le(r,s),c=H(e.ubj0,e.lbj0),l=J(c,c);if(!(l>1e-18))return"free";let u=H(n,t),d=J(u,u),p=ji(2*o*J(s,u),2*o*J(i,u),l-d-o*o,2*o*Math.sqrt(d));if(p.free)return"free";let m=ju(c),f=(h,b)=>{let g=oe(n,oe(X(s,o*h),X(i,o*b))),y=ju(H(g,t));return{q1:Wu(m,y),k:y,margin:p.margin,ok:p.ok}};return p.margin>0?[f(p.c1,p.s1),f(p.c2,p.s2)]:[f(p.c1,p.s1)]}function II(e,t,r){let n=t.axis0,o=oe(t.lower0,X(n,J(H(e.lbj0,t.lower0),n))),a=H(o,e.lbj0),s=Ui(a),i=s>1e-9?X(a,1/s):Jh(n),c=H(t.top,r),l=Ui(c);if(!(l>1e-9))return"free";let u=X(c,1/l),d=s/l,p=1-d,m=p>=0?Math.sqrt((1-d)*(1+d)):0,f=Jh(u),h=b=>{let g=b*m,y=oe(X(u,g),X(f,Math.min(d,1))),x=H(X(u,Math.min(d,1)),X(f,g));return{q1:Uh(Xh(x,y,le(x,y)),Qv(Xh(i,n,le(i,n)))),k:u,margin:p,ok:p>=0}};return p>0?[h(1),h(-1)]:[h(1)]}function _I(e,t,r,n){let{k:o}=n,a=ds(n.q1,H(e.tro0,e.lbj0)),s=J(a,o),i=H(a,X(o,s)),c=Ui(i);if(!(c>1e-9))return"free";let l=X(i,1/c),u=le(o,l),d=oe(t,X(o,s)),p=H(d,r),m=J(p,p),f=ji(2*c*J(p,l),2*c*J(p,u),e.tieLen2-m-c*c,2*c*Math.sqrt(m));if(f.free)return"free";let h=(g,y)=>({q:Uh(Zv(o,g,y),n.q1)});return{roots:f.margin>0?[h(f.c1,f.s1),h(f.c2,f.s2)]:[h(f.c1,f.s1)],margin:f.margin,ok:f.ok}}function tk(e,t,r,n=[0,0,0,0,0,0]){let o=Qh(e,t),a=Go(e,r),s=Jv([n[3],n[4],n[5]]),i=h=>Math.abs(h[0]*s[0]+h[1]*s[1]+h[2]*s[2]+h[3]*s[3]),c=e.strut?II(e,e.strut,o):EI(e,o);if(c==="free")return{x:n.slice(),converged:!1,margin:0,free:!0};let l=null,u=null;for(let h of c){let b=_I(e,o,a,h);if(b==="free")return{x:n.slice(),converged:!1,margin:0,free:!0};let g=Math.min(h.margin,b.margin),y=b.ok&&h.ok;for(let{q:x}of b.roots){let v=i(x);y&&(!l||v>l.near)&&(l={q:x,margin:g,near:v}),!y&&(!u||v>u.near)&&(u={q:x,margin:g,near:v})}}let{q:d,margin:p}=l??u,m=ek(d),f=H(H(o,e.c0),Dt(m,H(e.lbj0,e.c0)));return{x:[f[0],f[1],f[2],m[0],m[1],m[2]],converged:l!==null,margin:p,free:!1}}function nk(e){let t=te(H(e.rockerPivotB,e.rockerPivotA));return{pivotA:e.rockerPivotA,axis:t,rprRel0:H(e.rockerToPushrod,e.rockerPivotA),rdmRel0:H(e.rockerToDamper,e.rockerPivotA),damperChassis:e.damperChassis,rodLen2:Wi(e.pushrodOuter,e.rockerToPushrod),damperLen0:Pe(e.rockerToDamper,e.damperChassis)}}var NI=(e,t)=>oe(e.pivotA,sr(e.rprRel0,e.axis,t)),eb=(e,t)=>oe(e.pivotA,sr(e.rdmRel0,e.axis,t));function ps(e,t){return{pushrod:NI(e,t),damper:eb(e,t)}}function ok(e,t,r=0){let n=J(e.rprRel0,e.axis),o=H(e.rprRel0,X(e.axis,n)),a=le(e.axis,o),s=H(oe(e.pivotA,X(e.axis,n)),t),i=J(o,o),c=J(s,s),l=ji(2*J(s,o),2*J(s,a),e.rodLen2-c-i,2*Math.sqrt(i*c));if(l.free){let m=Math.abs(e.rodLen2-c-i)<=1e-9*e.rodLen2;return{phi:r,damperLength:Pe(eb(e,r),e.damperChassis),converged:m,margin:0}}let u=rk(Math.atan2(l.s1,l.c1),r),d=rk(Math.atan2(l.s2,l.c2),r),p=Math.abs(d-r)<Math.abs(u-r)?d:u;return{phi:p,damperLength:Pe(eb(e,p),e.damperChassis),converged:l.ok,margin:l.margin}}function rk(e,t){let r=2*Math.PI;return e+r*Math.round((t-e)/r)}function ak(e,t,r,n){return oe(t,Dt(X(te(r),n),H(e,t)))}function sk(e,t,r,n){let o=te(n),a=p=>{let m=H(p,r);return H(m,X(o,J(m,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))),d=J(le(s,i),o)/(c*l);return Math.atan2(d,u)}function ik(e,t,r,n){return oe(t,Dt(X(te(r),n),H(e,t)))}var Uu=180/Math.PI,OI=(e,t,r)=>Math.max(t,Math.min(r,e)),ck=[NaN,NaN,NaN];function Xi(e){let t=te(e.spinAxis),r=te(H(e.uprightUpper,e.uprightLower)),n=-Math.asin(OI(t[2],-1,1))*Uu,o=Math.atan2(t[0],t[1])*Uu,a=Math.atan2(-r[0],r[2])*Uu,s=Math.atan2(-r[1],r[2])*Uu,i=te(oe([0,0,-1],X(t,t[2]))),c=oe(e.wheelCenter,X(i,e.loadedRadius)),l=e.patchShift?[c[0]+e.patchShift.x,c[1]+e.patchShift.y,c[2]]:c,u=e.uprightLower,d=Math.abs(r[2])>1e-9,p=w=>oe(u,X(r,(w-u[2])/r[2])),m=d?p(l[2]):ck,f=d?p(e.wheelCenter[2]):ck,h=l[1]-m[1],b=m[0]-l[0],g=te(le(t,[0,0,1])),y=le([0,0,1],g),x=H(l,m),v=J(x,y),k=-J(x,g),R=e.wheelCenter[1]-f[1],M=f[0]-e.wheelCenter[0],S=Yv(e.tieOuter,u,r);return{camber:n,toe:o,caster:a,kpi:s,scrubRadius:h,mechanicalTrail:b,scrubAtWheel:v,trailAtWheel:k,kingpinOffset:R,casterOffset:M,steeringArm:S,contactPatch:l,kingpinGround:m,kingpinAtHub:f}}function wt(e){return{corner:e,inv:qh(e),rocker:nk(e.hardpoints)}}var VI=[20,20,20,.2,.2,.2];function uk(e,t,r,n=[0,0,0,0,0,0]){let o=tk(e,t,r,n);if(!o.free)return o;let a=BI(e,t,r,n);return{x:a.x,converged:a.converged,margin:0}}function BI(e,t,r,n=[0,0,0,0,0,0]){return qv(o=>Zh(e,o,t,r),n,{scales:VI,tol:1e-10,maxIter:40})}var $I=.01,Xu=1.2,Ht=e=>e.ok?e.state:null,Et=e=>e.ok?e.state:e.nearest;function Ae(e,t,r,n,o){let a=0,s=tt(e,a,r,n,o);if(Math.abs(s.travel-t)<1e-4)return lk(s,t,!1);let c=(tt(e,.02,r,tb(s),o).travel-s.travel)/.02;(!Number.isFinite(c)||Math.abs(c)<1e-6)&&(c=1);let l=p=>Math.max(-Xu,Math.min(Xu,p)),u=l((t-s.travel)/c),d=tt(e,u,r,tb(s),o);for(let p=0;p<12&&!(Math.abs(d.travel-t)<1e-4);p++){let m=d.travel-s.travel,f=Math.abs(m)<1e-9?u:u-(d.travel-t)*((u-a)/m);a=u,s=d,u=l(f),d=tt(e,u,r,tb(s),o)}return lk(d,t,Math.abs(u)===Xu)}function lk(e,t,r){let n=e.travel-t,o=Math.abs(n)<=$I,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 tb(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 GI(e,t,r,n,o){switch(e){case"upright":return Rr(t,r,o.pushrodOuter);case"upperArm":{let a=Rr(t,r,t.ubj0),s=sk(t.ubj0,a,t.ucaFront,t.ucaDir);return ik(o.pushrodOuter,t.ucaFront,t.ucaDir,s)}default:return ak(o.pushrodOuter,t.lcaFront,t.lcaDir,n)}}function tt(e,t,r,n,o){let{inv:a,corner:s}=e,i=n?.q??[0,0,0,0,0,0],c=uk(a,t,r,i),l=c.x,u=[l[3],l[4],l[5]],d={t:[l[0],l[1],l[2]],omega:u},p=s.hardpoints,m=s.config,f=a.strut,h=f?f.top:Rr(a,l,p.uprightUpper),b=Rr(a,l,p.uprightLower),g=Rr(a,l,p.tieOuter),y=Rr(a,l,p.wheelCenter),x=te(Dt(u,m.spinAxis)),v=GI(f?"upright":m.pushrodAttach,a,l,t,p),k=f?f.top:p.damperChassis,R=f||m.actuation==="direct"?{phi:0,damperLength:Pe(v,k),converged:!0,margin:1}:ok(e.rocker,v,n?.phi??0),M=Xi({uprightUpper:h,uprightLower:b,wheelCenter:y,spinAxis:x,tieOuter:g,loadedRadius:o?.loadedRadius??m.loadedRadius,patchShift:o?.patchShift});return{pose:d,beta:t,travel:l[2],steer:r,points:{uprightUpper:h,uprightLower:b,tieOuter:g,wheelCenter:y,pushrodOuter:v,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 fs=e=>e==="FL"||e==="FR"?"front":"rear",dk=e=>e==="FL"||e==="RL"?"left":"right";function qe(e,t){return e.corners?.[t]??KI(e[fs(t)],dk(t))}function pk(e){let t=e.config.springSplit;return e.config.actuation==="decoupled"||t===void 0||!Number.isFinite(t)||Math.abs(t)>=1?0:t}var mk=new WeakMap;function KI(e,t){let r=pk(e);if(r===0)return e;let n=mk.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)},mk.set(e,n)}return n[t]}var Zr=["FL","FR","RL","RR"],qt=e=>2*e.hardpoints.wheelCenter[1],ir=(e,t)=>t?qt(qe(e,"FL"))/2+qt(qe(e,"FR"))/2:qt(qe(e,"RL"))/2+qt(qe(e,"RR"))/2;function ze(e,t){let r=e==="FL"||e==="FR";return{axleX:r?t.frontAxleX:t.frontAxleX-t.wheelbase,sideSign:e==="FR"||e==="RR"?1:-1,isFront:r}}function rt(e,t){return[t.axleX+e[0],t.sideSign*e[1],e[2]]}function Tn(e,t){return[e[0],t.sideSign*e[1],e[2]]}function fo(e){return e.frontAxleX-e.wheelbase/2}function rb(e,t,r){return t[2]+e.heave+(t[0]-r)*Math.sin(e.pitch)-t[1]*Math.sin(e.roll)}function ho(e,t,r,n){let o=ze(e,t),a=(n?ir(n,o.isFront):o.isFront?t.trackFront:t.trackRear)/2,s=o.sideSign*a,i=o.axleX-fo(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 HI={travelMin:-40,travelMax:40,steps:41,steer:0};function qi(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 ct(e,t={}){let r={...HI,...t},n=wt(e);return hs(n,r)}function hs(e,t){let r=t.steer,n=.01,o=tt(e,n,r),a=tt(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=[],d=tt(e,0,r);u.push({beta:0,travel:d.travel,warm:qi(d),converged:d.converged});let p=qi(d);for(let x=1;x<=l;x++){let v=c*x/l,k=tt(e,v,r,p);p=qi(k),u.push({beta:v,travel:k.travel,warm:p,converged:k.converged})}p=qi(d);for(let x=1;x<=l;x++){let v=-c*x/l,k=tt(e,v,r,p);p=qi(k),u.push({beta:v,travel:k.travel,warm:p,converged:k.converged})}u.sort((x,v)=>x.beta-v.beta);let m=u[u.length-1].travel>=u[0].travel,f=!1;for(let x=1;x<u.length;x++){let v=u[x].travel-u[x-1].travel;(m&&v<-1e-6||!m&&v>1e-6)&&(f=!0)}let h=u.filter(x=>x.converged).map(x=>x.travel),b=h.length?[Math.min(...h),Math.max(...h)]:[0,0],g=h.length>0&&b[0]<=t.travelMin+1e-6&&b[1]>=t.travelMax-1e-6,y=[];for(let x=0;x<t.steps;x++){let v=t.steps===1?t.travelMin:t.travelMin+(t.travelMax-t.travelMin)*x/(t.steps-1),k=zI(u,v,m),R=YI(u,k);y.push(tt(e,k,r,R))}return WI(y,e.corner.config.actuation==="decoupled"?0:e.corner.config.springRate),{samples:y,covered:g,reach:b,fold:f,unconverged:y.filter(x=>!x.converged).length}}function zI(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 YI(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 nb(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 WI(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=nb(n,r,s),c=nb(o,r,s),l=-nb(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 qu=e=>e!==void 0&&Number.isFinite(e)&&e>0;function jI(e){return e&&qu(e.helperRate)&&qu(e.helperTravel)?{rate:e.helperRate,travel:e.helperTravel}:null}function ob(e,t,r){let n=t/e;return r?n+Math.min(t/r.rate,r.travel):n}function Qi(e,t,r,n){if(!(e>0)||!Number.isFinite(e)||!(t>0)||!Number.isFinite(t))return null;let o=jI(n),a=-ob(e,t,o),s=bs(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 bs(e,t){if(!Number.isFinite(e))return{droop:null,bump:null};let r=qu(t?.extended)&&t.extended>e?t.extended:null,n=r!==null&&qu(t?.stroke)?r-t.stroke:null;return{droop:r!==null?e-r:null,bump:n!==null&&n<e?e-n:null}}function ab(e,t){if(!(e>0)||!Number.isFinite(e))return null;let r=bs(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 UI(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=ob(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 XI(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=ob(r,n,o)+t;return a<=0?0:a>=o.rate*o.travel/r+o.travel?r:r*o.rate/(r+o.rate)}function gs(e,t){let r=UI(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 sb(e,t){let r=XI(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 ib(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 Qu={min:-60,max:60,steps:61},cb=e=>({travel:[e.min,e.max],force:[0,0],motionRatio:[0,0],spring:null}),fk=new WeakMap;function qI(e,t){let r=fk.get(e.corner);r||fk.set(e.corner,r=new Map);let n=`${t.min}|${t.max}|${t.steps}`,o=r.get(n);return o||r.set(n,o=hs(e,{travelMin:t.min,travelMax:t.max,steps:t.steps,steer:0})),o}function Ji(e,t,r=Qu,n=e.corner.config.coilover){let o=e.corner.config;if(o.actuation==="decoupled")return cb(r);let a=qI(e,r),s=ZI(e,o.springRate,a.samples),i=[];for(let h of a.samples){let b=h.metrics.motionRatio;!h.converged||b===void 0||!Number.isFinite(b)||!Number.isFinite(h.metrics.damperLength)||i.length>0&&h.travel<=i[i.length-1].t+1e-6||i.push({t:h.travel,L:h.metrics.damperLength,mr:b})}if(i.length<2)return cb(r);let c=e2(i,0);if(!(Math.abs(c.mr)>1e-6))return cb(r);let l=t/c.mr,u=Qi(s,l,c.L,n),d=u?QI(i,ib(u).map(h=>c.L-h)):i,p=d.map(h=>(u?gs(u,c.L-h.L):l+s*(c.L-h.L))*h.mr-t),m=h=>h===null?null:d.find(b=>b.L===c.L-h)?.t??null,f=u?ib(u).map(m).filter(h=>h!==null):[];return{travel:d.map(h=>h.t),force:p,motionRatio:d.map(h=>h.mr),spring:{rate:s,preload:l,length0:c.L,law:u},...u?{stops:{droop:m(u.droop),bump:m(u.bump)}}:{},...f.length?{kinks:f}:{},length:d.map(h=>h.L)}}function lb(e,t){if(!e.spring)return null;let r=e.travel.length,n=e.length;if(n&&n.length===r&&r>=2){let s=Jr(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+=(Zi(e,i)+Zi(e,c))/2*(c-i)}return a}function QI(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 ZI(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:JI(e,n,r);return!(o>0)||!Number.isFinite(o)?t:t*o/(t+o)}function JI(e,t,r){let n;for(let d of r)d.converged&&(!n||Math.abs(d.travel)<Math.abs(n.travel))&&(n=d);if(!n)return t;let o=e.corner.hardpoints,a=ps(e.rocker,n.points.rockerAngle),s=te(H(o.rockerPivotB,o.rockerPivotA)),i=(d,p)=>Math.abs(J(s,le(H(d,o.rockerPivotA),te(H(p,d))))),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 Zi(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.motionRatio[0];let n=Jr(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 Pn(e,t,r){if(!e.spring)return Nr(e,t);let{rate:n,preload:o,length0:a,law:s}=e.spring,i=Zi(e,0),c=a-r;return(s?gs(s,c):o+n*c)*Zi(e,t)-o*i}function e2(e,t){let r=Jr(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 Jr(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 Nr(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.force[0];let n=Jr(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 ys(e,t){let r=e.travel.length;if(r<3)return ec(e,t);let n=Jr(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 ec(e,t){if(e.travel.length<2)return 0;let n=Jr(e.travel,t);return(e.force[n+1]-e.force[n])/(e.travel[n+1]-e.travel[n])}function Ye(e,t,r){let n=e.hardpoints;switch(t.attach){case"upright":{let o=H(t.outer,n.wheelCenter);return oe(oe(Dt(r.pose.omega,o),n.wheelCenter),r.pose.t)}case"lowerArm":{let o=te(H(n.lcaRear,n.lcaFront));return oe(n.lcaFront,Dt(X(o,r.beta),H(t.outer,n.lcaFront)))}case"rocker":{let o=te(H(n.rockerPivotB,n.rockerPivotA));return oe(n.rockerPivotA,sr(H(t.outer,n.rockerPivotA),o,r.points.rockerAngle))}}}function en(e,t,r){return e.config.actuation==="decoupled"&&t.attach==="rocker"&&r==="coil"}function ub(e,t,r){return en(e,t,r)?[t.inner[0],-t.inner[1],t.inner[2]]:t.inner}function xs(e,t,r){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return mb(e,t,r.kind,ct(e,{travelMin:n,travelMax:o,steps:a}).samples)}function mb(e,t,r,n){let o=te(H(t.outer,ub(e,t,r))),a=[],s=[],i=t.outer;for(let m of n)a.push(m.travel),s.push(J(H(Ye(e,t,m),i),o));let c=a.length,l=new Array(c).fill(0);for(let m=0;m<c;m++){let f=Math.max(0,m-1),h=Math.min(c-1,m+1),b=a[h]-a[f];l[m]=b!==0?(s[h]-s[f])/b:0}let u=l[0];for(let m=1;m<c;m++)if(a[m]>=0){let f=a[m]-a[m-1],h=f!==0?(0-a[m-1])/f:0;u=l[m-1]+h*(l[m]-l[m-1]);break}let d=l.filter(m=>Math.abs(m)>1e-9).map(Math.sign),p=d.length>0&&d.some(m=>m!==d[0]);return{travel:a,ratio:l,linkTravel:s,atDesign:u,reverses:p}}function db(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 pb(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 Ko=e=>e.mount??{kind:"rockerToRocker"},yk=e=>[e[0],0,e[2]],t2=e=>2*Math.abs(e[1]),r2=(e,t)=>Math.hypot(e[0]-t[0],e[2]-t[2]);function Ju(e,t){return t.kind==="chassis"?r2(e,t.anchor):t2(e)}function tc(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 Ho(e,t,r={}){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return fb(e,t,ct(e,{travelMin:n,travelMax:o,steps:a}).samples)}function fb(e,t,r){let n=Ko(t),o=f=>Ye(e,{...t,inner:t.outer},r[f]),a=[],s=[],i=[];for(let f=0;f<r.length;f++)a.push(r[f].travel),i.push(Ju(o(f),n));let c=bk(a,i,0);for(let f of i)s.push(c-f);let l=a.length,u=new Array(l).fill(0);for(let f=0;f<l;f++){let h=Math.max(0,f-1),b=Math.min(l-1,f+1),g=a[b]-a[h];u[f]=g!==0?(s[b]-s[h])/g:0}let d=hk(a,20),p=hk(a,-20),m=tc(o(d),o(p),n);return{travel:a,ratio:u,springTravel:s,atDesign:bk(a,u,0),installedLength:c,rollSensitivity:c-m}}function hk(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 bk(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 hb(e,t,r){let n={outer:t.outer,attach:t.attach},o=ct(e,{travelMin:-5,travelMax:5,steps:3}),a=f=>yk(Ye(e,{...n,inner:n.outer},o.samples[f])),s=a(1),i=a(2),c=a(0),l=i[0]-c[0],u=i[2]-c[2],d=Math.hypot(l,u),p=d>1e-9?[l/d,u/d]:[0,1],m=r??Math.max(80,2*Math.abs(t.outer[1])*.5);return[s[0]+p[0]*m,0,s[2]+p[1]*m]}function bb(e,t){let r=e.hardpoints,n=r.rockerPivotA,o=gk(Zu(r.rockerPivotB,r.rockerPivotA)),a=Math.max(30,.6*xk(Zu(r.rockerToDamper,n))),s=Zu(r.rockerToDamper,n),i=gk(Zu(s,n2(o,o2(s,o)))),c=a2(o,i),l=null,u=-1/0;for(let d=0;d<360;d+=10){let p=d*Math.PI/180,f={outer:[n[0]+a*(Math.cos(p)*i[0]+Math.sin(p)*c[0]),n[1]+a*(Math.cos(p)*i[1]+Math.sin(p)*c[1]),n[2]+a*(Math.cos(p)*i[2]+Math.sin(p)*c[2])],attach:"rocker"},h=t==="chassis"?{...f,mount:{kind:"chassis",anchor:hb(e,f)}}:f,b;try{b=Ho(e,h,{travelMin:-20,travelMax:20,steps:9})}catch{continue}let g=b.atDesign/(1+4*Math.abs(b.rollSensitivity));Number.isFinite(g)&&g>u&&(u=g,l=h)}return l??{outer:r.rockerToDamper,attach:"rocker"}}var Zu=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],n2=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],o2=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],xk=e=>Math.hypot(e[0],e[1],e[2]),gk=e=>{let t=xk(e)||1;return[e[0]/t,e[1]/t,e[2]/t]},a2=(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 gb=.001,s2=e=>({outer:e.outer,inner:e.outer,attach:e.attach}),Ck=(e,t,r)=>(Ju(e.at0,t)-Ju(r,t))/2,i2=(e,t)=>J(H(t,e.pickup.at0),e.axis);function yb(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 Rk(e,t){let r=[0,1,2].map(n=>yb(e,t.map(o=>o[n])));return t.map((n,o)=>[r[0][o],r[1][o],r[2][o]])}function xb(e){return{travel:e,heave:e.map(t=>t/2),heaveRatio:e.map(()=>.5),roll:[...e],rollRatio:e.map(()=>1)}}function vk(e,t,r,n){let o=e.corner;if(!t.heave&&!t.roll)return{side:xb([n.min,n.max]),pickups:{}};let a=Et(Ae(e,0,0)),s={};if(t.heave&&r){let h=s2(t.heave);s.heave={corner:o,link:h,at0:Ye(o,h,a)}}if(t.roll){let h=t.roll;s.roll={pickup:{corner:o,link:h,at0:Ye(o,h,a)},axis:te(H(h.outer,ub(o,h,t.rollKind??"coil")))}}let i=t.roll&&en(o,t.roll,t.rollKind??"coil")?{near:t.roll,far:{...t.roll,outer:t.roll.inner}}:null,c=hs(e,{travelMin:n.min,travelMax:n.max,steps:n.steps,steer:0}),l=[],u=[],d=[],p=[],m=[];for(let h of c.samples)!h.converged||l.length>0&&h.travel<=l[l.length-1]+1e-6||(l.push(h.travel),u.push(s.heave&&r?Ck(s.heave,r,Ye(o,s.heave.link,h)):h.travel/2),d.push(s.roll?i2(s.roll,Ye(o,s.roll.pickup.link,h)):h.travel),i&&(p.push(Ye(o,i.near,h)),m.push(Ye(o,i.far,h))));if(l.length<2)return{side:xb([n.min,n.max]),pickups:{}};let f={travel:l,heave:u,heaveRatio:yb(l,u),roll:d,rollRatio:yb(l,d)};return i&&(f.eyes={near:p,nearRatio:Rk(l,p),far:m,farRatio:Rk(l,m)}),{side:f,pickups:s}}function em(e,t,r){let n=Jr(e,r);return t[n]+(r-e[n])/(e[n+1]-e[n])*(t[n+1]-t[n])}function kk(e,t,r){let n=Jr(e,r);return(t[n+1]-t[n])/(e[n+1]-e[n])}function nt(e,t){return{h:em(e.travel,e.heave,t),dh:em(e.travel,e.heaveRatio,t),ddh:kk(e.travel,e.heaveRatio,t),r:em(e.travel,e.roll,t),dr:em(e.travel,e.rollRatio,t),ddr:kk(e.travel,e.rollRatio,t)}}function Mk(e,t,r,n){let o=Jr(e,n),a=e[o+1]-e[o],s=(n-e[o])/a,i=(u,d)=>[u[0]+s*(d[0]-u[0]),u[1]+s*(d[1]-u[1]),u[2]+s*(d[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 Rb=(e,t)=>Math.hypot(e[0]-t[0],e[1]+t[1],e[2]-t[2]);function vb(e,t){let r=e.side[0].eyes,n=e.side[1].eyes;if(!r||!n)return null;let o=Mk(e.side[0].travel,r.near,r.nearRatio,t[0]),a=Mk(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]],d=[-a.dd[0],a.dd[1],-a.dd[2]],p=J(c,l),m=J(c,u),f=(J(l,u)-p*m)/i;return{L:i,dL:[p,m],ddL:[[(J(l,l)-p*p)/i+J(c,o.dd),f],[f,(J(u,u)-m*m)/i+J(c,d)]]}}var Fk=(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,c2=(e,t)=>e.bump!==null&&t>e.bump||e.droop!==null&&t<e.droop?e.rate:0;function rc(e,t,r,n,o=0){let a=e.rollStop;if(!a)return r;let s=vb(e,t);if(!s)return r;let i=Fk(a,a.length0-(n??s.L+o));return i===0?r:[r[0]-i*s.dL[0],r[1]-i*s.dL[1]]}function tm(e,t){let r=xb(e.travel);return t==="heave"?{...e,heave:r.heave,heaveRatio:r.heaveRatio}:{...e,roll:r.roll,rollRatio:r.rollRatio}}var rm=(e,t)=>e?e.law?gs(e.law,t):e.preload+e.rate*t:0,Sk=(e,t)=>e?e.law?sb(e.law,t):e.rate:0;function nc(e,t,r,n,o){let a=rm(e.heave,n),s=rm(e.roll,o);return[a*t.dh+s*t.dr,a*r.dh-s*r.dr]}var Ak=(e,t)=>nt(e[0],t).h+nt(e[1],t).h;function l2(e,t){let r=e.gap>0?Ak(t,e.gap):0;return e.bothWays?{free:r,pull:e.gap>0?Ak(t,-e.gap):0}:{free:r,pull:null}}function u2(e,t,r){let n={...t,outer:t.inner},o=(u,d)=>{let p=Ht(Ae(e[0],u,0)),m=Ht(Ae(e[1],d,0));if(!p||!m)return NaN;let f=Ye(e[0].corner,t,p),h=Ye(e[1].corner,n,m);return Math.hypot(f[0]-h[0],f[1]+h[1],f[2]-h[2])},a=1,s=o(0,0),i=o(-a,a)-o(a,-a),c=nt(r[0],a).r-nt(r[1],-a).r-(nt(r[0],-a).r-nt(r[1],a).r),l=i/c;return Number.isFinite(s)&&s>0&&Number.isFinite(l)&&Math.abs(l)>gb?{length0:s,scale:l}:null}function Tk(e,t,r,n=Qu){let o=r.heave?Ko(r.heave):void 0,a=vk(e[0],r,o,n),s=e[1].corner===e[0].corner?a:vk(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,d=u?u.rate:(t[0].heaveRate+t[1].heaveRate)/2,p=(t[0].arbRate+t[1].arbRate)/2,m=i.map(C=>nt(C,0));c&&!(Math.abs(m[0].dh+m[1].dh)>gb)&&(i=[tm(i[0],"heave"),tm(i[1],"heave")],c=!1),l&&!(Math.abs(m[0].dr+m[1].dr)>gb)&&(i=[tm(i[0],"roll"),tm(i[1],"roll")],l=!1),m=i.map(C=>nt(C,0));let f=m[0].dh+m[1].dh,h=m[0].dr+m[1].dr,b=d>0?2*d/(f*f):0,g=p>0?2*p/(h*h):0,y=0,x=0;if(r.carriesLoad){let C=[t[0].springLoad,t[1].springLoad];if(b>0&&g>0){let P=-m[0].dh*m[1].dr-m[1].dh*m[0].dr;Math.abs(P)>1e-12&&(y=(-C[0]*m[1].dr-C[1]*m[0].dr)/P,x=(m[0].dh*C[1]-m[1].dh*C[0])/P)}else b>0?y=(C[0]+C[1])/f:g>0&&(x=(C[0]-C[1])/h)}let v={};if(c&&o){let C=[a.pickups.heave,s.pickups.heave];v.heave={pickups:C,mount:o,span0:tc(C[0].at0,C[1].at0,o)}}let k=v.heave?v.heave.span0:NaN,R=v.heave?r.coilover:void 0,M=r.carriesLoad?Qi(b,y,k,R):u?ab(b,{...l2(u,i),length0:k,coilover:R}):null,S=b>0?{rate:b,preload:y,...M?{law:M}:{}}:null;if(l&&(v.roll={pickups:[a.pickups.roll.pickup,s.pickups.roll.pickup],axes:[a.pickups.roll.axis,s.pickups.roll.axis]},r.roll&&en(e[0].corner,r.roll,r.rollKind??"coil"))){let C=u2(e,r.roll,i);C&&(v.roll.unit=C)}let w=g>0?{rate:g,preload:x}:null,F={side:i,heave:S,roll:w,force0:[0,0],carriesLoad:r.carriesLoad,read:v},T=v.roll?.unit,A=T&&g>0&&i[0].eyes&&i[1].eyes?bs(T.length0,r.rollCoilover):null;return T&&A&&(A.droop!==null||A.bump!==null)&&(F.rollStop={length0:T.length0,rate:1e3*g/(T.scale*T.scale),...A}),F.force0=rc(F,[0,0],nc(F,m[0],m[1],m[0].h+m[1].h,m[0].r-m[1].r)),F}function oc(e,t,r){let n=nt(e.side[0],t[0]),o=nt(e.side[1],t[1]),a=r?rc(e,t,nc(e,n,o,n.h+o.h+r.heave,n.r-o.r+r.roll),void 0,r.unit):rc(e,t,nc(e,n,o,n.h+o.h,n.r-o.r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function kb(e,t,r){let n=nt(e.side[0],t[0]),o=nt(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=Sk(e.heave,a),c=Sk(e.roll,s),l=rm(e.heave,a),u=rm(e.roll,s),d=i*n.dh*o.dh-c*n.dr*o.dr,p=[[i*n.dh*n.dh+l*n.ddh+c*n.dr*n.dr+u*n.ddr,d],[d,i*o.dh*o.dh+l*o.ddh+c*o.dr*o.dr-u*o.ddr]],m=e.rollStop,f=m?vb(e,t):null;if(!m||!f)return p;let h=m.length0-(r?f.L+r.unit:f.L),b=c2(m,h);if(b===0)return p;let g=Fk(m,h),y=(v,k)=>b*f.dL[v]*f.dL[k]-g*f.ddL[v][k],x=d+y(0,1);return[[p[0][0]+y(0,0),x],[x,p[1][1]+y(1,1)]]}function Mb(e,t,r){let n=kb(e,t);return n[r][0]+n[r][1]}function m2(e,t,r){let n=e.read.heave;if(!n)return nt(e.side[0],t[0]).h+nt(e.side[1],t[1]).h;let[o,a]=n.pickups;return n.span0-tc(Ye(o.corner,o.link,r[0]),Ye(a.corner,a.link,r[1]),n.mount)}function d2(e,t,r){let n=e.read.roll;if(!n)return nt(e.side[0],t[0]).r-nt(e.side[1],t[1]).r;let o=a=>J(H(Ye(n.pickups[a].corner,n.pickups[a].link,r[a]),n.pickups[a].at0),n.axes[a]);return o(0)-o(1)}function p2(e,t){let r=e.read.roll;if(!e.rollStop||!r)return;let[n,o]=r.pickups;return Rb(Ye(n.corner,n.link,t[0]),Ye(o.corner,{...o.link,outer:o.link.inner},t[1]))}function ac(e,t,r){let n=nt(e.side[0],t[0]),o=nt(e.side[1],t[1]),a=rc(e,t,nc(e,n,o,m2(e,t,r),d2(e,t,r)),p2(e,r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function Sb(e,t,r,n){let o=nt(e.side[0],r),a=nt(e.side[1],r),s=e.read.heave,i=s?.pickups[t],c=s&&i&&n?2*Ck(i,s.mount,Ye(i.corner,i.link,n)):o.h+a.h,l=e.rollStop&&n?e.read.roll?.pickups[t]:void 0,u=l&&n?Rb(Ye(l.corner,l.link,n),Ye(l.corner,{...l.link,outer:l.link.inner},n)):void 0;return rc(e,[r,r],nc(e,o,a,c,n?0:o.r-a.r),u)[t]-e.force0[t]}function Ab(e,t,r,n){let o=ys(e,r[n]);return t?.carriesLoad?o+Mb(t,r,n):o}function Pk(e,t){return nt(e.side[0],t[0]).h+nt(e.side[1],t[1]).h}function Lk(e,t){return vb(e,t)?.L??null}var wb=e=>e==="FR"||e==="RR"?1:0,nm=(e,t)=>e.elements?.[t==="FL"||t==="FR"?"front":"rear"]??null;var Dk=e=>Number.isFinite(e)&&e>0?1/e:0;var Ek=(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},f2=(e,t)=>[e[0][0]*t[0]+e[0][1]*t[1],e[1][0]*t[0]+e[1][1]*t[1]],Ik=1e-8,h2=40;function b2(e,t,r,n){return{force:(s,i)=>{if(r){let u=oc(r,s,n);return[Nr(t[0],s[0])+i[0]+u[0],Nr(t[1],s[1])+i[1]+u[1]]}let c=(s[0]+s[1])/2,l=(s[0]-s[1])/2;return[Nr(t[0],s[0])+i[0]+e[0].heaveRate*c+e[0].arbRate*l,Nr(t[1],s[1])+i[1]+e[1].heaveRate*c-e[1].arbRate*l]},stiffness:(s,i=ec)=>{if(r){let c=kb(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 Rs(e,t,r,n,o,a=[0,0],s=[0,0],i=null,c){let l=[Dk(r[0].tyreRate),Dk(r[1].tyreRate)],u=[r[0].staticLoad,r[1].staticLoad],d=b2(r,n,i,c),p=P=>d.force(P,a),m=d.stiffness([0,0]),f=[l[0]>0?l[0]:1/Math.max(1,Math.abs(m[0][0])),l[1]>0?l[1]:1/Math.max(1,Math.abs(m[1][1]))],h=(P,L)=>{let E=L===1?p(P):d.force(P,[a[0]*L,a[1]*L]),_=[E[0]+s[0]*L,E[1]+s[1]*L],D=[P[0]+t[0]*L+_[0]*l[0]-e[0]*L,P[1]+t[1]*L+_[1]*l[1]-e[1]*L],I=[f[0]*(u[0]+_[0]),f[1]*(u[1]+_[1])],V=[I[0]<D[0],I[1]<D[1]];return{f:_,on:D,off:I,lifted:V,r:[Math.min(D[0],I[0]),Math.min(D[1],I[1])]}},b=(P,L)=>[L[0]?[f[0]*P[0][0],f[0]*P[0][1]]:[1+P[0][0]*l[0],P[0][1]*l[0]],L[1]?[f[1]*P[1][0],f[1]*P[1][1]]:[P[1][0]*l[1],1+P[1][1]*l[1]]],g=P=>Math.max(Math.abs(P[0]),Math.abs(P[1])),y=(P,L)=>{let E=[P[0],P[1]],_=h(E,L),D=!1,I=0;for(;I<h2;I++){if(g(_.r)<Ik){D=!0;break}let V=Ek(b(d.stiffness(E),_.lifted),[-_.r[0],-_.r[1]]);if(!V)break;let O=1,B=[E[0]+V[0],E[1]+V[1]],z=h(B,L);for(let j=0;j<8&&g(z.r)>g(_.r);j++)O/=2,B=[E[0]+O*V[0],E[1]+O*V[1]],z=h(B,L);E=B,_=z}return!D&&g(_.r)<Ik&&(D=!0),{t:E,b:_,converged:D,it:I}},x=y(o?[o[0],o[1]]:[e[0]-t[0],e[1]-t[1]],1),v=x.it;if(!x.converged){let P=0,L=[0,0],E=.25;for(;P<1&&E>=1/256;){let _=Math.min(1,P+E),D=y(L,_);v+=D.it,D.converged?(P=_,L=D.t,_===1&&(x=D)):E/=2}}let{t:k,b:R,converged:M}=x,S=R.lifted,w=[S[0]?-u[0]:R.f[0],S[1]?-u[1]:R.f[1]],F=[S[0]?Math.max(0,R.on[0]):0,S[1]?Math.max(0,R.on[1]):0],T=d.stiffness(k,ys),A=b(T,S);return{t:k,dF:w,lifted:S,clearance:F,converged:M,iterations:v,respond:(P,L,E=[0,0])=>{let _=[S[0]?-f[0]*E[0]:P[0]-L[0]-E[0]*l[0],S[1]?-f[1]*E[1]:P[1]-L[1]-E[1]*l[1]],D=Ek(A,_);if(!D)return[NaN,NaN];let I=f2(T,D);return[S[0]?0:I[0]+E[0],S[1]?0:I[1]+E[1]]}}}var zo=e=>!(Number.isFinite(e.tyreRate)&&e.tyreRate>0);function vr(e,t,r){return t?.input.corners[r].staticLoadedRadius??e}var Cb=["FL","FR","RL","RR"],Ok={front:["FL","FR"],rear:["RL","RR"]},g2=512,y2=5e-4,x2=8;function om(e,t){let r={},n={},o=new Map;for(let s of Cb){let i=e.ctx[s],c=t.corners[s],l=c.staticLoadedRadius;n[s]=Et(Ae(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"],d=`${Cb.findIndex(m=>qe(e.vehicle,m)===qe(e.vehicle,s))}|${c.springLoad}|${u?`${u.extended}/${u.stroke}`:""}`,p=o.get(d);p?r[s]=p:(r[s]=u?Ji(i,c.springLoad,void 0,u):Ji(i,c.springLoad),o.set(d,r[s]))}let a={front:null,rear:null};for(let s of["front","rear"]){let i=t.elements?.[s];if(!i)continue;let c=Ok[s];a[s]=Tk([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 Vk(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 R2=e=>`${e.heave}|${e.pitch}|${e.roll}|${e.steer}`;function Fb(e,t,r){return{travel:r.travel,steer:r.steer,ground:r.travel,tyreDeflection:0,load:NaN,loadedRadius:vr(qe(e.vehicle,t).config.loadedRadius,e.kc,t),lifted:!1,contactLength:0,converged:!0,rigid:!0,rideRate:NaN,wheelRateAtLoad:NaN}}var v2=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 _k(e,t,r,n){let o=Ok[n],a=e.vehicle.config,s=o.map(w=>ho(w,a,r,e.vehicle)),i=[t.input.corners[o[0]],t.input.corners[o[1]]],c=t.loadCase;if(!c&&i.every(zo))return{corners:[Fb(e,o[0],s[0]),Fb(e,o[1],s[1])],respond:null};let l=o.map(w=>t.curve[w]),u=t.elements?.[n]??null,d=o.map(w=>vr(qe(e.vehicle,w).config.loadedRadius,t,w)),p=[s[0].travel+(c?.ground[o[0]]??0),s[1].travel+(c?.ground[o[1]]??0)],m=[c?.linkLoad[o[0]]??0,c?.linkLoad[o[1]]??0],f=[c?.patchShift[o[0]],c?.patchShift[o[1]]],h=[0,0],b=[0,0],g,y=Rs(p,h,i,l,void 0,void 0,m,u),x=[void 0,void 0],v=[!0,!0],k=[0,0],R=!1;for(let w=0;w<x2;w++){w>0&&(y=Rs(p,h,i,l,g,b,m,u)),k=[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 F=[0,0],T=[0,0];for(let C=0;C<2;C++){let P=Ae(e.ctx[o[C]],y.t[C],s[C].steer,v2(x[C]),{loadedRadius:d[C]-k[C],patchShift:f[C]}),L=Et(P);x[C]=L,v[C]=P.ok,F[C]=L.points.contactPatch[2]-t.ground0[o[C]]-y.t[C]-k[C],T[C]=Pn(l[C],y.t[C],L.points.damperLength)-Nr(l[C],y.t[C])}if(u){let C=ac(u,y.t,[x[0],x[1]]),P=oc(u,y.t);T[0]+=C[0]-P[0],T[1]+=C[1]-P[1]}let A=Math.max(Math.abs(F[0]-h[0]),Math.abs(F[1]-h[1]),Math.abs(T[0]-b[0])/Math.max(1,i[0].tyreRate),Math.abs(T[1]-b[1])/Math.max(1,i[1].tyreRate));if(h=F,b=T,g=y.t,A<y2){R=!0;break}}let M=y.respond([1,1],[0,0]);return{corners:[0,1].map(w=>{let F=x[w];return{travel:y.t[w],steer:s[w].steer,ground:p[w],tyreDeflection:k[w],load:i[w].staticLoad+y.dF[w],loadedRadius:d[w]-k[w],lifted:y.lifted[w],clearance:y.clearance[w],contactLength:Vk(d[w]-k[w],i[w].staticLoad+y.dF[w],i[w].tyreRate),converged:y.converged&&R&&v[w],rigid:!1,state:F,solved:v[w],rideRate:M[w],wheelRateAtLoad:Ab(l[w],u,y.t,w)}}),respond:y.respond}}function Bk(e,t){let r=e.kc,n=R2(t),o=r.memo.get(n);if(o)return o;let a=_k(e,r,t,"front"),s=_k(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>=g2&&r.memo.clear(),r.memo.set(n,i),i}function Qt(e,t){if(!e.kc){let r={};for(let n of Cb)r[n]=Fb(e,n,ho(n,e.vehicle.config,t,e.vehicle));return r}return Bk(e,t).corners}function am(e,t,r){return e.kc?Bk(e,t).respond[r]:null}function sc(e,t,r,n=0){let o=e.kc;if(!o)return r;let a=o.input.corners[t];if(zo(a))return r;let s=ho(t,e.vehicle.config,{heave:0,pitch:0,roll:0,steer:n},e.vehicle).steer,i=vr(qe(e.vehicle,t).config.loadedRadius,o,t),c=o.loadCase,l=c?.linkLoad[t]??0,u=c?.patchShift[t],d=Et(Ae(e.ctx[t],r,s,void 0,{loadedRadius:i,patchShift:u})),p=nm(o,t),m=Pn(o.curve[t],r,d.points.damperLength)+(p?Sb(p,wb(t),r,d):a.heaveRate*r),h=Math.max(m+l,-a.staticLoad)/a.tyreRate;return(h===0?d:Et(Ae(e.ctx[t],r,s,void 0,{loadedRadius:i-h,patchShift:u}))).points.contactPatch[2]-o.ground0[t]-(c?.ground[t]??0)}var k2=180/Math.PI,M2=[0,0,1];function S2(e,t){let r=Tn(e,t),n=X(le(M2,r),-t.sideSign);return-Math.atan2(n[1],n[0])*k2}var $k=e=>1/Math.tan(e*Math.PI/180),Gk=.05,Kk=.001;function Hk(e,t,r){if(!Number.isFinite(e)||!Number.isFinite(t))return NaN;if(!(Math.abs(e)<Kk&&Math.abs(t)<Kk))return e>0&&t>0?100*($k(t)-$k(e))/r:NaN}function A2(e,t){let r=ir(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=[Gk,-Gk].map(l=>{let{inner:u,outer:d}=a(t("FL",l).deg-n,t("FR",l).deg-o);return Hk(u,d,r)??NaN});s=(c[0]+c[1])/2}return s};return c=>{let l=t("FL",c),u=t("FR",c),{left:d,inner:p,outer:m}=a(l.deg-n,u.deg-o),f=Hk(p,m,r);return{steerL:l.deg,steerR:u.deg,inner:p,outer:m,toeDiff:p-m,ackermannPct:f??i(),inside:f===void 0?null:d?"left":"right",converged:l.ok&&u.ok}}}function Tb(e,t){let r=e.vehicle.config,n={FL:ze("FL",r),FR:ze("FR",r)},o=t.travel??0,a=A2(e,(i,c)=>{let l=Ht(Ae(e.ctx[i],o,n[i].sideSign*c));return{deg:l?S2(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 zk=35,Yk=55,It=e=>e.rackTravel&&e.rackTravel>0?e.rackTravel:zk,Pb=e=>e.rackRatio&&e.rackRatio>0?e.rackRatio:Yk;var Lb=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 Wk(e,t,r,n,o){let a=Ae(e,n,0,void 0,o),s=Et(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=m=>{let f=[l],h=Lb(s);for(let b=1;b<=r;b++){let g=m*(t*b)/r,y=tt(e,s.beta,g,h,o),x=Ht(Ae(e,n,g,Lb(y),o));if(!x||!y.converged){i++,f.push({...f[f.length-1]});continue}f.push({steer:x.metrics.toe,camber:x.metrics.camber,lift:-(y.points.contactPatch[2]-c),contactPatch:y.points.contactPatch,spinAxis:y.points.spinAxis,yaw:-y.metrics.toe*Math.PI/180}),h=Lb(y)}return f},d=u(1),p=u(-1);return{travelMm:n,unsolved:i,centre:l,positive:d,negative:p}}function w2(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=X(H(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 jk(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:w2(o,t)});return{travelMm:e.travelMm,inner:n(r?e.positive:e.negative),outer:n(r?e.negative:e.positive)}}function C2(e){return e.positive[1].steer-e.centre.steer<0}function F2(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:Pb(e.config),innerJacobian:r.inner.jacobian,outerJacobian:r.outer.jacobian}}function Db(e,t,r=13,n=-40,o=40,a=5,s){let i=wt(e),c=Array.from({length:r+1},(b,g)=>t*g/r),l=Wk(i,t,r,0,s),u=C2(l),d=jk(l,c,u),p=Math.max(2,Math.floor(a)),m=Array.from({length:p},(b,g)=>n+(o-n)*g/(p-1));m.some(b=>Math.abs(b)<1e-9)||m.push(0),m.sort((b,g)=>b-g);let f=l.unsolved,h=m.map(b=>{if(Math.abs(b)<1e-9)return d;let g=Wk(i,t,r,b,s);return f+=g.unsolved,jk(g,c,u)});return{...F2(e,c,d),...Uk(l.unsolved),travelSurface:{rackMm:c,rows:h,...Uk(f)}}}var Uk=e=>e>0?{unsolved:e}:{};function tn(e,t,r){let n=e.length;if(n===0)return 0;if(r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0,a=n-1;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function sm(e,t,r){let n=e.length;if(n===0)return{longitudinal:0,lateral:0,vertical:0,yaw:0};let o,a;if(r<=e[0])o=a=0;else if(r>=e[n-1])o=a=n-1;else for(o=0,a=n-1;a-o>1;){let l=o+a>>1;e[l]<=r?o=l:a=l}let s=t[o];if(o===a)return{longitudinal:s.longitudinal,lateral:s.lateral,vertical:s.vertical,yaw:s.yaw};let i=t[a],c=(r-e[o])/(e[a]-e[o]);return{longitudinal:s.longitudinal+c*(i.longitudinal-s.longitudinal),lateral:s.lateral+c*(i.lateral-s.lateral),vertical:s.vertical+c*(i.vertical-s.vertical),yaw:s.yaw+c*(i.yaw-s.yaw)}}function Xk(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 Yo=(e,t,r)=>e+r*(t-e);function vs(e,t,r,n,o){let a=tn(e.rackMm,e.rows[n.lo][t][r],o);if(n.lo===n.hi)return a;let s=tn(e.rackMm,e.rows[n.hi][t][r],o);return Yo(a,s,n.t)}function qk(e,t,r,n){let o=sm(e.rackMm,e.rows[r.lo][t].jacobian,n);if(r.lo===r.hi)return o;let a=sm(e.rackMm,e.rows[r.hi][t].jacobian,n);return{longitudinal:Yo(o.longitudinal,a.longitudinal,r.t),lateral:Yo(o.lateral,a.lateral,r.t),vertical:Yo(o.vertical,a.vertical,r.t),yaw:Yo(o.yaw,a.yaw,r.t)}}function ks(e,t,r,n){let o=e.travelSurface;if(!o||o.rackMm.length<2||o.rows.length===0)return Ms(e,t);let a=Xk(o,r),s=Xk(o,n),i=(m,f,h)=>{let b=o.rows[f.lo][m].steerDeg[h];return f.lo===f.hi?b:Yo(b,o.rows[f.hi][m].steerDeg[h],f.t)},c=new Array(o.rackMm.length);for(let m=0;m<c.length;m++)c[m]=.5*(i("inner",a,m)+i("outer",s,m));let l=Math.max(0,t),u=c.length-1,d=o.rackMm[u],p=l>c[u];if(l<=c[0])d=o.rackMm[0],p=!1;else if(!p){let m=1;for(;m<c.length-1&&c[m]<l;)m++;let f=m-1,h=c[m]-c[f],b=Math.abs(h)>1e-12?(l-c[f])/h:0;d=Yo(o.rackMm[f],o.rackMm[m],b)}return{innerDeg:vs(o,"inner","steerDeg",a,d),outerDeg:vs(o,"outer","steerDeg",s,d),innerCamber:vs(o,"inner","camberDeg",a,d),outerCamber:vs(o,"outer","camberDeg",s,d),innerLift:vs(o,"inner","liftMm",a,d),outerLift:vs(o,"outer","liftMm",s,d),innerJacobian:qk(o,"inner",a,d),outerJacobian:qk(o,"outer",s,d),atLock:p}}function Ms(e,t){let r=e.meanDeg.length-1;return{innerDeg:tn(e.meanDeg,e.innerDeg,t),outerDeg:tn(e.meanDeg,e.outerDeg,t),innerCamber:tn(e.meanDeg,e.innerCamber,t),outerCamber:tn(e.meanDeg,e.outerCamber,t),innerLift:e.innerLift?tn(e.meanDeg,e.innerLift,t):0,outerLift:e.outerLift?tn(e.meanDeg,e.outerLift,t):0,...e.innerJacobian&&e.outerJacobian?{innerJacobian:sm(e.meanDeg,e.innerJacobian,t),outerJacobian:sm(e.meanDeg,e.outerJacobian,t)}:{},atLock:r>=0&&t>e.meanDeg[r]}}var T2=()=>({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 Ss(e,t,r=Ge(e),n){let o=e.steerFront;if(!o?.innerLift||!o.outerLift||o.meanDeg.length<2||Math.abs(t)<1e-12)return T2();let a=Math.abs(t),s=t>0,i=n&&o.travelSurface?ks(o,a,s?n.FL:n.FR,s?n.FR:n.FL):null,c=i?.innerLift??tn(o.meanDeg,o.innerLift,a),l=i?.outerLift??tn(o.meanDeg,o.outerLift,a),u=s?c:l,d=s?l:c,p=.5*(u+d),m=r.rollWheelRateFront,f=r.rollWheelRateRear,h=e.trackFront,b=e.trackRear,g=m*h*h+f*b*b,y=P2(e,m,f,h,b);if(y){let k=(d-u)/h,R=k/(1/y.front+1/y.rear+1/y.chassis),M=k-R/y.front,S=R/y.rear,w={FL:u-p+.5*h*M,FR:d-p-.5*h*M,RL:.5*b*S,RR:-.5*b*S},F=Math.max(0,Math.min(1,e.frontMassFrac)),T=A=>-Math.atan(A)*180/Math.PI;return{lift:{FL:u,FR:d,RL:0,RR:0},travel:w,load:{FL:m*w.FL,FR:m*w.FR,RL:f*w.RL,RR:f*w.RR},rollDeg:T(F*M+(1-F)*S),ends:{front:T(M),rear:T(S)}}}let x=g>0?m*h*(d-u)/g:0,v={FL:u-p+.5*h*x,FR:d-p-.5*h*x,RL:.5*b*x,RR:-.5*b*x};return{lift:{FL:u,FR:d,RL:0,RR:0},travel:v,load:{FL:m*v.FL,FR:m*v.FR,RL:f*v.RL,RR:f*v.RR},rollDeg:x===0?0:-Math.atan(x)*180/Math.PI}}function P2(e,t,r,n,o){let a=e.chassisTorsion??0,s=.5*t*n*n,i=.5*r*o*o;return!(a>0)||!Number.isFinite(a)||!(s>0)||!(i>0)?null:{front:s,rear:i,chassis:a*1e3*180/Math.PI}}function Eb(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 ic=9.81;function As(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?Cn(e,t,r,po(e,n,o)):$o(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 Ib(e,t,r=0,n=0,o=0){if(!e.aero?.model||t<=0)return!1;let a=Cn(e,t,r,po(e,n,o));return a!=null&&(a.clampedRide||a.clampedAttitude)}function Wo(e){let t=e.loadFactor===void 0?e.massTotal*ic:e.massTotal*ic*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 Qk(e,t=Ge(e),r=e.cgHeight){let n=e.trackFront/1e3,o=e.trackRear/1e3,a=e.rcHeightFront/1e3,s=e.rcHeightRear/1e3,i=(e.rcHeightFront+(e.rcHeightRear-e.rcHeightFront)*(1-e.frontMassFrac))/1e3,c=r/1e3-i,l=2*e.unsprungPerCorner,u=e.unsprungCgHeight/1e3,d=t.sprungMass*c*Ou(t.sprungMass,c,t.rollRateTotal),p=(d*t.frontElasticShare+t.sprungFront*a+l*u)/n,m=(d*(1-t.frontElasticShare)+t.sprungRear*s+l*u)/o;return{cf:p,cr:m}}function cc(e){let{cf:t,cr:r}=Qk(e);return t+r>0?t/(t+r):.5}var Zk=e=>1-e.frontMassFrac;function Jk(e,t,r,n=e.cgHeight){return n-(t+(r-t)*Zk(e))}function eM(e,t){if(!Number.isFinite(t.rcFront)||!Number.isFinite(t.rcRear)||!Number.isFinite(t.arm))return NaN;let r=t.arm+t.rcFront+(t.rcRear-t.rcFront)*Zk(e);return cc({...e,rcHeightFront:t.rcFront,rcHeightRear:t.rcRear,cgHeight:r})}function tM(e,t,r){if(e.FL>=0&&e.FR>=0&&e.RL>=0&&e.RR>=0)return{loads:{FL:Math.max(0,e.FL),FR:Math.max(0,e.FR),RL:Math.max(0,e.RL),RR:Math.max(0,e.RR)},lifted:{FL:!1,FR:!1,RL:!1,RR:!1},overturned:!1};let n=e.FL+e.FR+e.RL+e.RR;if(!(n>0))return{loads:{FL:0,FR:0,RL:0,RR:0},lifted:{FL:!0,FR:!0,RL:!0,RR:!0},overturned:!0};let o=!1,a=e.FL+e.FR,s=e.RL+e.RR;a<0?(a=0,s=n,o=!0):s<0&&(s=0,a=n,o=!0);let i=(e.FR-e.FL)*t+(e.RR-e.RL)*r,c=Math.min(a,Math.max(-a,e.FR-e.FL)),l=Math.min(s,Math.max(-s,e.RR-e.RL)),u=i-(c*t+l*r);if(u!==0){let p=u>0?1:-1,m=(p*a-c)*t;p*u>=p*m?(c=p*a,u-=m):(c+=u/t,u=0);let f=(p*s-l)*r;u!==0&&(p*u>=p*f?(l=p*s,u-=f):(l+=u/r,u=0)),Math.abs(u)>1e-9*(Math.abs(i)+n*(t+r))&&(o=!0)}let d={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:d,lifted:{FL:d.FL===0,FR:d.FR===0,RL:d.RL===0,RR:d.RR===0},overturned:o}}function We(e,t,r,n=0,o=0,a=0,s,i){return im(e,t,r,n,o,a,s,i).loads}function im(e,t,r,n=0,o=0,a=0,s,i){let c=Wo(e),l=Ge(e),u=Yu(e,n,r,po(e,t,o),l),{cf:d,cr:p}=Qk(e,l,u.height),m=d*t*ic,f=p*t*ic,h=e.massTotal*(r*ic)*u.height/e.wheelbase-u.noseLoad,b=As(e,n,r,t,o),g=(i??Ss(e,a,l,s)).load,y={FL:c.FL-m-h/2+b.FL+g.FL,FR:c.FR+m-h/2+b.FR+g.FR,RL:c.RL-f+h/2+b.RL+g.RL,RR:c.RR+f+h/2+b.RR+g.RR};return tM(y,e.trackFront,e.trackRear)}var _b=Math.PI/180;function lm(e,t){let r=8*_b,n=0,o=0;for(let a=1;a<=90;a++){let s=a*.5,i=Math.abs(e.Fy(s*_b,t,0));if(i>n&&(n=i,r=s*_b,o=a),a>o+12&&i<.995*n)break}return{aPeak:r,fyPeak:n}}function rM(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 uc=.999;function cr(e,t,r,n,o){if(t<=0)return 0;let{aPeak:a,fyPeak:s}=o??lm(e,t),i=Math.min(Math.abs(r),uc*s),c=n?-1:1,l=(k,R)=>Math.abs(e.forces({Fz:t,kappa:c*k,alpha:R}).Fy),u=.3,d=u,p=l(u,a);if(p<i){let k=0,R=u,M=NaN,S=p;for(let w=0;w<9;w++){let F=.5*(k+R),T=l(F,a);T>=i?(k=F,M=T):(R=F,S=T)}Number.isNaN(M)&&(M=l(0,a)),d=M<i?0:rM(k,M,R,S,i)}if(d<=0)return 0;let m=k=>{if(i===0)return c*e.forces({Fz:t,kappa:c*k,alpha:0}).Fx;let R=0,M=a,S=NaN,w=NaN;for(let F=0;F<5;F++){let T=.5*(R+M),A=l(k,T);A<i?(R=T,S=A):(M=T,w=A)}return Number.isNaN(S)&&(S=l(k,0)),Number.isNaN(w)&&(w=l(k,a)),c*e.forces({Fz:t,kappa:c*k,alpha:rM(R,S,M,w,i)}).Fx},f=4,h=k=>d*k/f,b=[0],g=1;for(let k=1;k<=f;k++)b.push(m(h(k))),b[k]>b[g]&&(g=k);let[y,x]=g===f?[f-1,f-2]:b[g-1]>=b[g+1]?[g-1,g+1]:[g+1,g-1],v=I2(m,h(g-1),h(Math.min(f,g+1)),h(g),b[g],h(y),b[y],h(x),b[x],L2);return c*Math.max(0,v)}var L2=.01,D2=20,E2=(3-Math.sqrt(5))/2;function I2(e,t,r,n,o,a,s,i,c,l){o=-o,s=-s,c=-c;let u=r-t,d=0;for(let p=0;p<D2;p++){let m=l*Math.abs(n)+1e-10,f=.5*(t+r);if(Math.abs(n-f)<=2*m-.5*(r-t))break;let h=!0;if(Math.abs(u)>m){let y=(n-a)*(o-c),x=(n-i)*(o-s),v=(n-i)*x-(n-a)*y;x=2*(x-y),x>0&&(v=-v),x=Math.abs(x);let k=u;if(u=d,Math.abs(v)<Math.abs(.5*x*k)&&v>x*(t-n)&&v<x*(r-n)){d=v/x;let R=n+d;(R-t<2*m||r-R<2*m)&&(d=f>=n?m:-m),h=!1}}h&&(u=n>=f?t-n:r-n,d=E2*u);let b=Math.abs(d)>=m?n+d:n+(d>=0?m:-m),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 Vb(e,t,r){if(!(r<1))return 0;let n=Math.max(0,r);return sM(o=>Math.hypot(o,n)/e.reach(t,o,n)-1)}function aM(e,t,r){let n=Math.max(0,r);return sM(o=>Math.hypot(n,o)/e.reach(t,n,o)-1)}function sM(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 Bb(e,t){return e.model?.kind==="simple"?null:iM(e,t)}var nM=new WeakMap,Nb=100,oM=1.35,Ob=18,rn=41,cm=41,lc=65;function iM(e,t){let r=nM.get(e);if(r)return r;let n=Math.log(oM),o=(m,f)=>{let h=M=>Math.abs(cr(e,m,M,f)),b=h(0),g=t.muY(m)*m,y=new Float64Array(rn),x=b>0&&g>0?Math.max(1,t.muX(m)*m/b):1;if(!(b>0)||!(g>0))y.fill(1);else{let M=[],S=[];for(let F=0;F<cm;F++){let T=Math.sin(.5*Math.PI*F/(cm-1));M.push(T),S.push(F===0?1:F===cm-1?0:Math.min(S[F-1],h(T*g)/b))}let w=cm-1;for(let F=0;F<rn;F++){let T=F/(rn-1);for(;w>0&&S[w-1]<T;)w--;let A=w>0?S[w-1]-S[w]:0;y[F]=w===0?M[0]:M[w]+(A>0?(T-S[w])/A:0)*(M[w-1]-M[w])}y[0]=1,y[rn-1]=0}let v=new Float64Array(lc),k=M=>Math.atan2(y[M],M/(rn-1)/x),R=rn-2;for(let M=0;M<lc;M++){let S=.5*Math.PI*M/(lc-1),w=Math.cos(S),F=Math.sin(S);for(;R>0&&k(R)<S;)R--;let T=R/(rn-1)/x,A=y[R],C=(R+1)/(rn-1)/x,P=y[R+1],L=w*(P-A)-F*(C-T),E=Math.abs(L)>1e-12?(T*(P-A)-A*(C-T))/L:Math.hypot(T,A);v[M]=E>0?E:Math.hypot(T,A)}return{room:y,scale:x,edge:v}},a=Array.from({length:Ob},(m,f)=>Nb*oM**f),s=a.map(m=>o(m,!1)),i=a.map(m=>o(m,!0)),c=(m,f)=>{let h=Math.min(1,Math.abs(f)*m.scale)*(rn-1),b=Math.min(rn-2,Math.floor(h));return m.room[b]+(h-b)*(m.room[b+1]-m.room[b])},l=m=>{let f=m>Nb?Math.log(m/Nb)/n:0;if(f>=Ob-1)return[Ob-2,1];let h=Math.floor(f);return[h,f-h]},u=(m,f,h)=>{if(h===0)return 1;let b=h<0?i:s,g=c(b[m],h);return f>0?g+f*(c(b[m+1],h)-g):g},d=(m,f,h)=>{let b=f<0?i:s,[g,y]=l(m),x=Math.atan2(Math.abs(h),Math.abs(f))/(.5*Math.PI)*(lc-1),v=Math.min(lc-2,Math.floor(x)),k=M=>M.edge[v]+(x-v)*(M.edge[v+1]-M.edge[v]),R=k(b[g]);return y>0?R+y*(k(b[g+1])-R):R},p={keeps(m,f){if(f===0)return 1;let[h,b]=l(m);return u(h,b,f)},atLoad(m){let[f,h]=l(m);return b=>u(f,h,b)},use(m,f,h){let b=Math.hypot(f,h);return b>0?Math.min(1,b/d(m,f,h)):0},reach:d};return nM.set(e,p),p}var _2=[["front","FL","FR"],["rear","RL","RR"]];function ws(e,t,r,n){let o={...e},a=0,s=uc;for(let[i,c,l]of _2){let u=(v,k)=>n(i,Math.max(0,k[v])).fyPeak,d=Math.min(s,e[c]),p=Math.min(s,e[l]),m=d*u(c,r)+p*u(l,r);if(!(m>0))continue;let f=u(c,t),h=u(l,t),b=d*f+p*h,g=b>0?m/b:1/0,y=d*g,x=p*g;y<=s?x<=s||(x=s,y=f>0?(m-s*h)/f:1/0):(y=s,x=h>0?(m-s*f)/h:1/0),(!(y<=s)||!(x<=s))&&(a+=Math.max(0,m-s*(f+h)),y=Math.min(s,y),x=Math.min(s,x)),o[c]=y,o[l]=x}return{util:o,short:a}}var cM=.001,N2=1e-5,lM=100;function O2(e,t,r,n){if(!(n>cM))return r;let o=t,a=Math.abs(r-t)<lM?t+Math.sign(r-t)*lM:r;for(let s=0;s<60&&Math.abs(a-o)>N2;s++){let i=.5*(o+a);e(i)>cM?a=i:o=i}return o}function um(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=O2(e,t,o,e(o));return a!==o&&(n=a),a},edge:()=>n}}function mm(e,t){let r=n=>{try{return Ae(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 $b=40;function dm(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 uM=[0,0,0];function V2(e,t){let r=te(H(e.rockerPivotB,e.rockerPivotA)),n=te(H(e.rockerToPushrod,e.pushrodOuter)),o=te(H(e.damperChassis,e.rockerToDamper)),a=Math.abs(J(r,le(H(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(J(r,le(H(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}function pm(e,t,r){if(e.mcpherson)return B2(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 d=0;d<6;d++){let p=te(H(n[d].c,n[d].r)),m=le(H(n[d].r,o),p);a[0][d]=p[0],a[1][d]=p[1],a[2][d]=p[2],a[3][d]=m[0],a[4][d]=m[1],a[5][d]=m[2]}let s=le(H(e.contactPatch,o),t),i=r??uM,c=[-t[0],-t[1],-t[2],-(s[0]+i[0]),-(s[1]+i[1]),-(s[2]+i[2])],l=Qr(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]:V2(e,u[5]),condProxy:l.condProxy,singular:l.singular}}function B2(e,t,r){let n=e.wheelCenter,o=e.damperChassis,a=[{at:e.uprightLower,dir:te(H(e.lcaFront,e.uprightLower))},{at:e.uprightLower,dir:te(H(e.lcaRear,e.uprightLower))},{at:e.tieOuter,dir:te(H(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(H(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(H(e.contactPatch,n),t),c=r??uM,l=[-t[0],-t[1],-t[2],-(i[0]+c[0]),-(i[1]+c[1]),-(i[2]+c[2])],u=Qr(s,l),d=u.x,p=[d[3],d[4],d[5]],m=te(H(o,e.pushrodOuter)),f=J(p,m),h=Math.hypot(p[0]-f*m[0],p[1]-f*m[1],p[2]-f*m[2]);return{ucaFront:NaN,ucaRear:NaN,lcaFront:d[0],lcaRear:d[1],tieRod:d[2],pushRod:u.singular?NaN:f,damper:u.singular?NaN:f,condProxy:u.condProxy,singular:u.singular,strutSide:u.singular?NaN:h,topMount:p}}function Gb(e,t){let r=te(e.spinAxis),n=le(H(e.contactPatch,e.wheelCenter),t),o=J(n,r);return[-o*r[0],-o*r[1],-o*r[2]]}var $2=[0,0,0];function mc(e,t,r,n){let o=e.direct?e.damperChassis:e.rockerToPushrod;if(e.mcpherson)return{...pm(e,r,n),armResidual:0};if(t==="upright")return{...pm(e,r,n),armResidual:0};let a=t==="lowerArm",s=a?{bj:e.uprightUpper,front:e.ucaFront,rear:e.ucaRear}:{bj:e.uprightLower,front:e.lcaFront,rear:e.lcaRear},i=a?{bj:e.uprightLower,front:e.lcaFront,rear:e.lcaRear}:{bj:e.uprightUpper,front:e.ucaFront,rear:e.ucaRear},c=e.wheelCenter,l=te(H(s.front,s.bj)),u=te(H(s.rear,s.bj)),d=te(H(e.tieInner,e.tieOuter)),p=[{at:s.bj,dir:l},{at:s.bj,dir:u},{at:e.tieOuter,dir:d},{at:i.bj,dir:[1,0,0]},{at:i.bj,dir:[0,1,0]},{at:i.bj,dir:[0,0,1]}],m=[[],[],[],[],[],[]];for(let q=0;q<6;q++){let Y=p[q].dir,K=le(H(p[q].at,c),Y);m[0][q]=Y[0],m[1][q]=Y[1],m[2][q]=Y[2],m[3][q]=K[0],m[4][q]=K[1],m[5][q]=K[2]}let f=le(H(e.contactPatch,c),r),h=n??$2,b=[-r[0],-r[1],-r[2],-(f[0]+h[0]),-(f[1]+h[1]),-(f[2]+h[2])],g=Qr(m,b),y=g.singular,x=g.x,v=x[0],k=x[1],R=x[2],M=[x[3],x[4],x[5]],S=te(H(i.rear,i.front)),w=te(H(o,e.pushrodOuter)),F=X(M,-1),T=(q,Y)=>J(S,le(H(q,i.front),Y)),A=T(e.pushrodOuter,w),C=Math.abs(A)>1e-9?-T(i.bj,F)/A:NaN,P=oe(F,X(w,C)),L=X(P,-1),E=te(H(i.front,i.bj)),_=te(H(i.rear,i.bj)),D=J(E,E),I=J(E,_),V=J(_,_),O=J(E,L),B=J(_,L),z=D*V-I*I,j=NaN,$=NaN,N=NaN;if(Math.abs(z)>1e-12){j=(O*V-B*I)/z,$=(D*B-I*O)/z;let q=oe(X(E,j),X(_,$)),Y=H(L,q);N=Math.hypot(Y[0],Y[1],Y[2])}let W=a?{f:v,r:k}:{f:j,r:$},Z=a?{f:j,r:$}:{f:v,r:k};return{ucaFront:W.f,ucaRear:W.r,lcaFront:Z.f,lcaRear:Z.r,tieRod:R,pushRod:C,damper:y||!Number.isFinite(C)||e.decoupled?NaN:e.direct?C:G2(e,C),condProxy:g.condProxy,singular:y,armResidual:N}}function G2(e,t){let r=te(H(e.rockerPivotB,e.rockerPivotA)),n=te(H(e.rockerToPushrod,e.pushrodOuter)),o=te(H(e.damperChassis,e.rockerToDamper)),a=Math.abs(J(r,le(H(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(J(r,le(H(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}var Rj=Math.PI/180;function dc(e,t){let r=Math.min(Math.max(t,e.range[0]),e.range[1])-e.reference;return Math.max(.2,1+e.perDegC*r+e.perDegC2*r*r)}var dM=["QSX3","QSX8","QSX13","QSX14"],K2=["QSX1"],fm=["PHY1","PHY2","PHY3","PKY6","PKY7","PVY1","PVY2","PVY3","PVY4","PEY3","PEY4","QHZ1","QHZ2","QHZ3","QHZ4","QEZ4","QEZ5","QDZ6","QDZ7","QDZ8","QDZ9","QDZ10","QDZ11","SSZ1","SSZ3","SSZ4","RBY3","RHX1","RVY1","RVY2","RVY3",...dM],H2=["PKY6","PKY7","PVY3","PVY4","PHY3","PEY4","RVY3","QBZ4","QDZ3","QHZ3","QHZ4","QEZ5","QDZ8","QDZ9","QDZ10","QDZ11","SSZ3","SSZ4"];function z2(){let e=new Set(H2),t=fm.filter(r=>!dM.includes(r));return[...t.filter(r=>!e.has(r)),...[...e].filter(r=>!t.includes(r)),...K2]}function Y2(e,t){let r={...e};for(let n of t)r[n]!==void 0&&r[n]!==0&&(r[n]=-r[n]);return r}var Ln=(e,t,r)=>Number.isFinite(e[t])?e[t]:r;function pM(e,t){return t!=="5.2"?Ln(e,"PKY6",0)*Ln(e,"LKYC",1):Ln(e,"PKY1",-15)*Math.sin(Ln(e,"PKY4",2)*Math.atan(1/Ln(e,"PKY2",2)))*Ln(e,"LKY",1)*Ln(e,"PHY3",0)+Ln(e,"PVY3",0)*Ln(e,"LMUY",1)}var mM=.1;function fM(e){if(e.fitData)return"sae";let t=pM(e.coeffs,e.version);return t>mM?"sae":t<-mM?"iso":null}function pc(e){return e.axisSystem??fM(e)??"sae"}function hm(e){let t=new Set,r=n=>{for(let o of n)t.has(o)?t.delete(o):t.add(o)};return pc(e)==="iso"&&r(fm),e.axisSystem&&e.side==="left"&&r(z2()),t.size?Y2(e.coeffs,t):e.coeffs}var kj=Math.PI/180;var G=(e,t)=>Number.isFinite(e)?e:t;function bM(e){let t=hm(e);return{PCX1:G(t.PCX1,1.65),PDX1:G(t.PDX1,1),PDX2:G(t.PDX2,0),PDX3:G(t.PDX3,0),PEX1:G(t.PEX1,0),PEX2:G(t.PEX2,0),PEX3:G(t.PEX3,0),PEX4:G(t.PEX4,0),PHX1:G(t.PHX1,0),PHX2:G(t.PHX2,0),PKX1:G(t.PKX1,20),PKX2:G(t.PKX2,0),PKX3:G(t.PKX3,0),PPX1:G(t.PPX1,0),PPX2:G(t.PPX2,0),PPX3:G(t.PPX3,0),PPX4:G(t.PPX4,0),PVX1:G(t.PVX1,0),PVX2:G(t.PVX2,0),PCY1:G(t.PCY1,1.3),PDY1:G(t.PDY1,1),PDY2:G(t.PDY2,0),PDY3:G(t.PDY3,0),PEY1:G(t.PEY1,0),PEY2:G(t.PEY2,0),PEY3:G(t.PEY3,0),PEY4:G(t.PEY4,0),PEY5:G(t.PEY5,0),PHY1:G(t.PHY1,0),PHY2:G(t.PHY2,0),PHY3:G(t.PHY3,0),PKY1:G(t.PKY1,-15),PKY2:G(t.PKY2,2),PKY3:G(t.PKY3,0),PKY4:G(t.PKY4,2),PKY5:G(t.PKY5,0),PKY6:G(t.PKY6,0),PKY7:G(t.PKY7,0),PPY1:G(t.PPY1,0),PPY2:G(t.PPY2,0),PPY3:G(t.PPY3,0),PPY4:G(t.PPY4,0),PPY5:G(t.PPY5,0),PVY1:G(t.PVY1,0),PVY2:G(t.PVY2,0),PVY3:G(t.PVY3,0),PVY4:G(t.PVY4,0),RBX1:G(t.RBX1,0),RBX2:G(t.RBX2,0),RBX3:G(t.RBX3,0),RBY1:G(t.RBY1,0),RBY2:G(t.RBY2,0),RBY3:G(t.RBY3,0),RBY4:G(t.RBY4,0),RCX1:G(t.RCX1,1),RCY1:G(t.RCY1,1),REX1:G(t.REX1,0),REX2:G(t.REX2,0),REY1:G(t.REY1,0),REY2:G(t.REY2,0),RHX1:G(t.RHX1,0),RHY1:G(t.RHY1,0),RHY2:G(t.RHY2,0),RVY1:G(t.RVY1,0),RVY2:G(t.RVY2,0),RVY3:G(t.RVY3,0),RVY4:G(t.RVY4,0),RVY5:G(t.RVY5,1),RVY6:G(t.RVY6,0),PPZ1:G(t.PPZ1,0),PPZ2:G(t.PPZ2,0),QBZ1:G(t.QBZ1,8),QBZ2:G(t.QBZ2,0),QBZ3:G(t.QBZ3,0),QBZ4:G(t.QBZ4,0),QBZ5:G(t.QBZ5,0),QBZ9:G(t.QBZ9,0),QBZ10:G(t.QBZ10,0),QCZ1:G(t.QCZ1,1.1),QDZ1:G(t.QDZ1,.1),QDZ2:G(t.QDZ2,0),QDZ3:G(t.QDZ3,0),QDZ4:G(t.QDZ4,0),QDZ6:G(t.QDZ6,0),QDZ7:G(t.QDZ7,0),QDZ8:G(t.QDZ8,0),QDZ9:G(t.QDZ9,0),QDZ10:G(t.QDZ10,0),QDZ11:G(t.QDZ11,0),QEZ1:G(t.QEZ1,0),QEZ2:G(t.QEZ2,0),QEZ3:G(t.QEZ3,0),QEZ4:G(t.QEZ4,0),QEZ5:G(t.QEZ5,0),QHZ1:G(t.QHZ1,0),QHZ2:G(t.QHZ2,0),QHZ3:G(t.QHZ3,0),QHZ4:G(t.QHZ4,0),SSZ1:G(t.SSZ1,0),SSZ2:G(t.SSZ2,0),SSZ3:G(t.SSZ3,0),SSZ4:G(t.SSZ4,0),QSX1:G(t.QSX1,0),QSX2:G(t.QSX2,0),QSX3:G(t.QSX3,0),QSX4:G(t.QSX4,0),QSX5:G(t.QSX5,0),QSX6:G(t.QSX6,0),QSX7:G(t.QSX7,0),QSX8:G(t.QSX8,0),QSX9:G(t.QSX9,0),QSX10:G(t.QSX10,0),QSX11:G(t.QSX11,0),QSX12:G(t.QSX12,0),QSX13:G(t.QSX13,0),QSX14:G(t.QSX14,0),PPMX1:G(t.PPMX1,0),QSY1:G(t.QSY1,0),QSY2:G(t.QSY2,0),QSY3:G(t.QSY3,0),QSY4:G(t.QSY4,0),QSY5:G(t.QSY5,0),QSY6:G(t.QSY6,0),QSY7:G(t.QSY7,0),QSY8:G(t.QSY8,0),LONGVL:t.LONGVL!==void 0&&t.LONGVL>0?t.LONGVL:16.7,LCX:G(t.LCX,1),LCY:G(t.LCY,1),LEX:G(t.LEX,1),LEY:G(t.LEY,1),LFZO:G(t.LFZO,1),LHX:G(t.LHX,1),LHY:G(t.LHY,1),LKX:G(t.LKX,1),LKY:G(t.LKY,1),LKYC:G(t.LKYC,1),LKZC:G(t.LKZC,1),LMUX:G(t.LMUX,1),LMUY:G(t.LMUY,1),LMX:G(t.LMX,1),LMY:G(t.LMY,1),LVMX:G(t.LVMX,1),LRES:G(t.LRES,1),LS:G(t.LS,1),LTR:G(t.LTR,1),LVX:G(t.LVX,1),LVY:G(t.LVY,1),LVYKA:G(t.LVYKA,1),LXAL:G(t.LXAL,1),LYKA:G(t.LYKA,1)}}var hM=new WeakMap;function fc(e){let t=hM.get(e);return t===void 0&&(t=bM(e),hM.set(e,t)),t}var gM=e=>e>=0?1:-1;function hc(e,t,r=0,n){let o=fc(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,d=(o.PDY1+o.PDY2*c)*(1+o.PPY3*l+o.PPY4*l*l)*(1-o.PDY3*s*s)*o.LMUY,p=o.PCY1*o.LCY,m=d*a,f=o.PKY1*i*(1+o.PPY1*l)*Math.sin(o.PKY4*Math.atan(a/((o.PKY2+o.PKY5*s*s)*(1+o.PPY2*l)*i)))*(1-o.PKY3*Math.abs(s))*o.LKY,h=e.version!=="5.2",b=a*(o.PKY6+o.PKY7*c)*(1+o.PPY5*l)*o.LKYC,g=a*(o.PVY3+o.PVY4*c)*s*o.LKYC*o.LMUY,y=Math.abs(f)>1e-6?f:1e-6*(f<0?-1:1),x=h?(o.PHY1+o.PHY2*c)*o.LHY+(b*s-g)/y:(o.PHY1+o.PHY2*c)*o.LHY+o.PHY3*s,v=h?a*(o.PVY1+o.PVY2*c)*o.LVY*o.LMUY+g:a*((o.PVY1+o.PVY2*c)*o.LVY+(o.PVY3+o.PVY4*c)*s)*o.LMUY,k=p*m!==0?f/(p*m):0;return{Fz:a,g:s,dfz:c,dpi:l,Fz0p:i,R0:u,Cy:p,Dy:m,By:k,SHy:x,SVy:v,Kya:f,muy:d,EyA:o.PEY1+o.PEY2*c,EyG:1+o.PEY5*s*s,EyS:o.PEY3+o.PEY4*s,LEY:o.LEY}}function bm(e,t,r=0,n){let o=hc(e,t,r,n),a=fc(e),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:d,muy:p,Kya:m,SVy:f,By:h,Cy:b,Dy:g,SHy:y}=o,x=(a.PHX1+a.PHX2*c)*a.LHX,v=(a.PDX1+a.PDX2*c)*(1+a.PPX3*l+a.PPX4*l*l)*(1-a.PDX3*i*i)*a.LMUX,k=a.PCX1*a.LCX,R=v*s,M=s*(a.PKX1+a.PKX2*c)*Math.exp(a.PKX3*c)*(1+a.PPX1*l+a.PPX2*l*l)*a.LKX,S=k*R!==0?M/(k*R):0,w=Math.abs(m)>1e-6?m:1e-6*(m<0?-1:1),F=e.version!=="5.2",T=s*(a.PVX1+a.PVX2*c)*a.LVX*a.LMUX,A=F&&i!==0?hc(e,t,0,n):o,C=a.REX1+a.REX2*c;C>1&&(C=1);let P=a.REY1+a.REY2*c;return P>1&&(P=1),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:d,Cy:b,Dy:g,By:h,SHy:y,SVy:f,Kya:m,muy:p,EyA:o.EyA,EyG:o.EyG,EyS:o.EyS,LEY:o.LEY,SHx:x,Cx:k,Dx:R,Bx:S,SVx:T,ExA:a.PEX1+a.PEX2*c+a.PEX3*c*c,PEX4:a.PEX4,LEX:a.LEX,SHxa:a.RHX1,Bxa0:a.RBX1+a.RBX3*i*i,RBX2:a.RBX2,LXAL:a.LXAL,Cxa:a.RCX1,Exa:C,SHyk:a.RHY1+a.RHY2*c,Byk0:a.RBY1+a.RBY4*i*i,RBY2:a.RBY2,RBY3:a.RBY3,LYKA:a.LYKA,Cyk:a.RCY1,Eyk:P,DVykA:p*s*(a.RVY1+a.RVY2*c+a.RVY3*i),RVY4:a.RVY4,RVY5:a.RVY5,RVY6:a.RVY6,LVYKA:a.LVYKA,SHt:a.QHZ1+a.QHZ2*c+(a.QHZ3+a.QHZ4*c)*i,Bt:(a.QBZ1+a.QBZ2*c+a.QBZ3*c*c)*(1+a.QBZ4*i+a.QBZ5*Math.abs(i))*(a.LKY/a.LMUY),Ct:a.QCZ1,Dt:s*(d/u)*(a.QDZ1+a.QDZ2*c)*(1-a.PPZ1*l)*(1+a.QDZ3*i+a.QDZ4*i*i)*a.LTR,EtA:a.QEZ1+a.QEZ2*c+a.QEZ3*c*c,EtG:a.QEZ4+a.QEZ5*i,Br:a.QBZ9*(a.LKY/a.LMUY)+a.QBZ10*h*b,Dr:F?s*d*((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*d*((a.QDZ6+a.QDZ7*c)*a.LRES+(a.QDZ8+a.QDZ9*c)*(1+a.PPZ2*l)*i)*a.LMUY,arOff:m!==0?f/m:0,sixOne:F,y0:A,kk:M/w*(M/w),sS0:d*(a.SSZ1+(a.SSZ3+a.SSZ4*c)*i)*a.LS,sS2:d*a.SSZ2*a.LS/u}}function jo(e,t){let r=t+e.SHy,n=e.EyA*(e.EyG-e.EyS*gM(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 gm(e,t){let r=t+e.SHx,n=e.ExA*(1-e.PEX4*gM(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 yM(e,t,r){if(r===0)return t;let n=Math.tan(t);return Math.atan(Math.sqrt(n*n+e.kk*r*r))*Math.sign(t)}function W2(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=yM(e,o,r),i=e.Bt*s;return e.Dt*Math.cos(e.Ct*Math.atan(i-a*(i-Math.atan(i))))*n}function j2(e,t,r,n){return e.Dr*Math.cos(Math.atan(e.Br*yM(e,t+e.SHy+e.arOff,r)))*n}function xM(e,t,r,n,o,a){let s=Math.cos(t),i=W2(e,t,r,s),c=j2(e,t,r,s);return-i*a+c+(e.sS0+e.sS2*o)*n}function U2(e,t,r,n,o,a){return e.sixOne?r*(e.g===0?n:jo(e.y0,t)):o-a}function ym(e,t,r){let n=e.Bxa0*Math.cos(Math.atan(e.RBX2*t))*e.LXAL,o=r+e.SHxa,a=e.SHxa===0?1:Math.cos(e.Cxa*Math.atan(n*e.SHxa-e.Exa*(n*e.SHxa-Math.atan(n*e.SHxa))))||1;return Math.cos(e.Cxa*Math.atan(n*o-e.Exa*(n*o-Math.atan(n*o))))/a*gm(e,t)}function Kb(e,t){let r=e.sS0===0&&e.sS2===0?0:ym(e,0,t),n=jo(e,t);return xM(e,t,0,r,n,e.sixOne&&e.g!==0?jo(e.y0,t):n)}function xm(e,t,r){let n=jo(e,r),o=ym(e,t,r),a=e.Byk0*Math.cos(Math.atan(e.RBY2*(r-e.RBY3)))*e.LYKA,s=t+e.SHyk,i=e.SHyk===0?1:Math.cos(e.Cyk*Math.atan(a*e.SHyk-e.Eyk*(a*e.SHyk-Math.atan(a*e.SHyk))))||1,c=Math.cos(e.Cyk*Math.atan(a*s-e.Eyk*(a*s-Math.atan(a*s))))/i,u=e.DVykA*Math.cos(Math.atan(e.RVY4*r))*Math.sin(e.RVY5*Math.atan(e.RVY6*t))*e.LVYKA,d=c*n+u;return{Fx:o,Fy:d,Mz:xM(e,r,t,o,d,U2(e,r,c,n,d,u))}}var bc=(e,t)=>Math.max(.1,e.muY0+e.loadSensY*(t-e.nominalLoad)),gc=(e,t)=>Math.max(.1,e.muX0+e.loadSensX*(t-e.nominalLoad)),RM=(e,t,r)=>bc(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cy*Math.atan(e.By*r)),vM=(e,t,r)=>gc(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cx*Math.atan(e.Bx*r));function Hb(e,t){let r=Math.max(1,t.Fz),n=bc(e,r)*r,o=gc(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 Cs=Math.PI/180;function bo(e){if(e.kind==="simple")return"none";let t=e.missing?.some(n=>/^aligning moment Mz\b/i.test(n))??!1,r=["QBZ1","QCZ1","QDZ1"].every(n=>Number.isFinite(e.coeffs[n]));return t||!r?"assumed":"model"}function kM(e){let t=e.thermal?.operating;if(t===void 0||!e.thermal)return e;let{lateral:r,longitudinal:n,aligning:o}=e.thermal,a=r?dc(r,t):1,s=n?dc(n,t):1,i=o?dc(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,d)=>{c[u]=(c[u]??1)*d};return l("LMUY",a),l("LMUX",s),l("LTR",i),l("LRES",i),{...e,coeffs:c}}function Fs(e,t,r){let n=0,o=0;for(let s=r;s<=t;s+=r){let i=Math.abs(e(s));i>o&&(o=i,n=s)}let a=r/10;for(let s=Math.max(a,n-r);s<=n+r;s+=a)o=Math.max(o,Math.abs(e(s)));return o}var Ej=Math.LN2/16;var X2=45;var q2=[];for(let e=1;e<=X2;e++){let t=[];for(let r=Math.max(.1,e-1);r<=e+1;r+=.1)t.push(r);q2[e]=t}var MM=new WeakMap;function vm(e,t){MM.set(e,t)}function nn(e){return MM.get(e)??((t,r,n,o,a)=>e.forces({Fz:t,kappa:r,alpha:n,gamma:o,p:a}).Fx)}function Ke(e){let t=kM(e),r=t,n=t,o=4,a=b=>{let g=[],y=[],x=[],v=[];for(let M=0;M<o;M++)g.push(null),y.push(NaN),x.push(NaN),v.push(NaN);let k=0,R=0;return(M,S,w)=>{if(g[k]!==null&&M===y[k]&&S===x[k]&&w===v[k])return g[k];for(let T=0;T<o;T++)if(g[T]!==null&&M===y[T]&&S===x[T]&&w===v[T])return k=T,g[T];let F=b(M,S,w);return g[R]=F,y[R]=M,x[R]=S,v[R]=w,k=R,R=(R+1)%o,F}},s=a((b,g,y)=>bm(r,b,g,y)),i=a((b,g,y)=>hc(r,b,g,y)),c=b=>e.kind==="magic"?xm(s(b.Fz,b.gamma??0,b.p),b.kappa,b.alpha):Hb(n,b),l=(b,g,y=0,x)=>e.kind==="magic"?jo(i(g,y,x),b):RM(n,g,b),u=(b,g,y=0,x)=>e.kind==="magic"?gm(s(g,y,x),b):vM(n,g,b),d=(b,g,y=0,x)=>e.kind==="magic"?Kb(s(g,y,x),b):c({Fz:g,kappa:0,alpha:b,gamma:y,p:x}).Mz,p=b=>e.kind==="simple"?bc(n,b):Fs(g=>l(g*Cs,b),45,1)/Math.max(1,b),m=b=>e.kind==="simple"?gc(n,b):Fs(g=>u(g,b),.6,.02)/Math.max(1,b),f=b=>{let g=.1*Cs;return Math.abs((l(g,b)-l(-g,b))/(2*g))},h={model:e,forces:c,Fx:u,Fy:l,Mz:d,muX:m,muY:p,corneringStiffness:f,verticalStiffness:()=>e.verticalStiffness,rollingRadius:b=>{if(e.kind==="magic"&&e.missing?.includes("UNLOADED_RADIUS"))return 0;let g=e.unloadedR0??0;if(!(g>0))return 0;let y=e.verticalStiffness*1e3;if(!(y>0))return g;let x=e.rollingFraction??.306;return g-x*Math.max(0,b)/y},relaxationLength:b=>{let g=e.relaxation;if(!g)return 0;let y=g.carcassStiffness??0;if(!(y>0))return g.sigma;let x=f(Math.max(0,b));return x>0?x/(y*1e3):g.sigma}};return e.kind==="magic"&&vm(h,(b,g,y,x,v)=>ym(s(b,x,v),g,y)),h}function Ts(e){let t=Math.max(1,e.model.kind==="magic"?e.model.fnomin:e.model.nominalLoad);return e.Fy(2*Cs,t,0)-e.Fy(-2*Cs,t,0)>=0?1:-1}function yc(e,t=e.kind==="magic"?e.fnomin:e.nominalLoad){let r=Ke(e),n=2*Cs,o=3*Cs,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 Q2=Math.PI/180;function we(e,t){return e.axle?e.axle(t):e}function km(e,t){if(e===t)return e;let r=Ts(e)*Ts(t),n=(p,m)=>.5*(p+m),o=(p,m)=>p>0&&m>0?n(p,m):p>0?p:m>0?m:0,a=p=>{let m=e.forces(p),f=t.forces(p);return{Fx:n(m.Fx,f.Fx),Fy:n(m.Fy,r*f.Fy),Mz:n(m.Mz,r*f.Mz)}},s=(p,m,f=0,h)=>n(e.Fx(p,m,f,h),t.Fx(p,m,f,h)),i=(p,m,f=0,h)=>n(e.Fy(p,m,f,h),r*t.Fy(p,m,f,h)),c=(p,m,f=0,h)=>n(e.Mz(p,m,f,h),r*t.Mz(p,m,f,h)),l={model:e.model,forces:a,Fx:s,Fy:i,Mz:c,muX:p=>Fs(m=>s(m,p),.6,.02)/Math.max(1,p),muY:p=>Fs(m=>i(m*Q2,p),45,1)/Math.max(1,p),corneringStiffness:p=>n(e.corneringStiffness(p),t.corneringStiffness(p)),verticalStiffness:()=>o(e.verticalStiffness(),t.verticalStiffness()),rollingRadius:p=>o(e.rollingRadius(p),t.rollingRadius(p)),relaxationLength:p=>o(e.relaxationLength(p),t.relaxationLength(p)),axle:p=>p==="front"?e:t},u=nn(e),d=nn(t);return vm(l,(p,m,f,h,b)=>n(u(p,m,f,h,b),d(p,m,f,h,b))),l}function zt(e){if(SM.has(e))return e;let t=AM.get(e);if(t)return t;let r;if(e.axle){let n=e.axle("front"),o=e.axle("rear"),a=zt(n),s=zt(o);r=a===n&&s===o?e:km(a,s)}else Ts(e)>0?r=e:(r={...e,forces:n=>{let o=e.forces(n);return{Fx:o.Fx,Fy:-o.Fy,Mz:-o.Mz}},Fy:(n,o,a,s)=>-e.Fy(n,o,a,s),Mz:(n,o,a,s)=>-e.Mz(n,o,a,s)},vm(r,nn(e)));return SM.add(r),r!==e&&AM.set(e,r),r}var SM=new WeakSet,AM=new WeakMap;var Mm=25*(Math.PI/180);function Z2(e){let t=.6180339887,r=0,n=Mm,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 xc(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=Mm;if(s(Mm)<=a){let u=Z2(s);if(u.force<=a)return u.alpha;c=u.alpha}else if(o>0){let u=Math.max(0,o*.6),d=Math.min(Mm,o*1.6+.001);s(u)<a&&s(d)>=a&&(i=u,c=d)}let l=.001*a;for(let u=0;u<12;u++){let d=.5*(i+c),p=s(d)-a;if(p<0?i=d:c=d,Math.abs(p)<=l)return d}return c}var zb={shaft:!1,trail:0,hub:[0,0,0]};function CM(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 Yb(e,t,r){let n=r.shaft?Gb(e,t):[0,0,0];if(r.trail!==0){let a=CM(e),s=[t[0],t[1],0],i=H(s,X(a,J(s,a)));n=oe(n,le(X(a,-r.trail),i))}let o=r.hub;return(o[0]!==0||o[1]!==0||o[2]!==0)&&(n=H(n,le(H(e.contactPatch,e.wheelCenter),o))),{force:oe(t,o),moment:n}}var J2=(e,t)=>{let r=e!==void 0&&e>0?1/e:0,n=t!==void 0&&t>0?1/t:0;return r+n},Sm={ucaFront:0,ucaRear:0,lcaFront:0,lcaRear:0,tieRod:0,pushRod:0,rack:0};function Uo(e){return!e.measured}function Xo(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 Rc(e,t){let r=e.corner.hardpoints,n=ps(e.rocker,t.points.rockerAngle);return{ucaFront:r.ucaFront,ucaRear:r.ucaRear,lcaFront:r.lcaFront,lcaRear:r.lcaRear,tieInner:Go(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 Wb(e,t,r=0){let n=t.links??{},o=t.bushings??{},a=(l,u,d)=>{let p=J2(u,d);return p>0&&Number.isFinite(l)?l*p:0},s=o.topMount,i=e.topMount,c=i&&s!==void 0&&s>0&&i.every(Number.isFinite)?[-i[0]/s,-i[1]/s,-i[2]/s]:void 0;return{...c?{topMount:c}:{},ucaFront:a(e.ucaFront,n.ucaFront,o.ucaFront),ucaRear:a(e.ucaRear,n.ucaRear,o.ucaRear),lcaFront:a(e.lcaFront,n.lcaFront,o.lcaFront),lcaRear:a(e.lcaRear,n.lcaRear,o.lcaRear),tieRod:a(e.tieRod,n.tieRod,o.tieInner),pushRod:a(e.pushRod,n.pushRod,void 0),rack:r}}function FM(e,t,r,n){let o=Pe(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 vc(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=FM(r.ucaFront,r.ucaRear,Pe(r.uprightUpper,r.ucaFront)+t.ucaFront,Pe(r.uprightUpper,r.ucaRear)+t.ucaRear);o.ubjAxial0=i.axial,o.ubjRadius2=i.radius2}if(t.lcaFront!==0||t.lcaRear!==0){let i=FM(r.lcaFront,r.lcaRear,Pe(r.uprightLower,r.lcaFront)+t.lcaFront,Pe(r.uprightLower,r.lcaRear)+t.lcaRear),c=J(n.lbjRel0,n.lcaDir),l=H(n.lbjRel0,X(n.lcaDir,c)),u=Math.hypot(l[0],l[1],l[2]);o.lbjRel0=u>1e-9?oe(X(n.lcaDir,i.axial),X(l,Math.sqrt(i.radius2)/u)):oe(X(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,X(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 e_=8,t_=1e-5,r_=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 jb(e,t,r){let n=Yb(e,r.force,r.extras??zb),o=r.alignMoment?oe(n.moment,[0,0,r.alignMoment]):n.moment;return mc(e,t,n.force,o)}function wm(e,t,r,n,o,a,s=0){let i=tt(e,t,r,o,a),c=e.corner.compliance;if(!(Xo(c)&&Uo(e.corner)))return{state:i,forces:jb(Rc(e,i),e.corner.config.pushrodAttach,n),deflection:Sm,rigid:i,iterations:0,converged:!0,bypassed:!0};let u=i,d=e,p=e.corner.config.pushrodAttach,m=jb(Rc(e,i),p,n),f=Sm,h=!1,b=0;for(;b<e_;b++){let g=Rc(d,u);if(m=jb(g,p,n),m.singular)break;f=Wb(m,c,s),d=vc(e,f);let y=tt(d,t,r,r_(u),a),x=Pe(y.points.wheelCenter,u.points.wheelCenter);if(u=y,x<t_){h=!0;break}}return{state:u,forces:m,deflection:f,rigid:i,iterations:b+1,converged:h&&u.converged,bypassed:!1}}var Am=1e3,TM=1e5;function PM(e,t,r,n,o){let a=wm(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 Cm(e,t,r,n,o){let a={force:[0,0,n]},s=(b,g=0)=>PM(e,t,r,{force:b,alignMoment:g},o),i=PM(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,Am,n]),l=s([0,-Am,n]),u=s([Am,0,n]),d=s([-Am,0,n]),p=s([0,0,n],TM),m=s([0,0,n],-TM),f=(b,g)=>(b-g)/2,h=[i,c,l,u,d,p,m].every(b=>b.converged);return{toePerLateral:f(c.toe,l.toe),camberPerLateral:f(c.camber,l.camber),toePerLongitudinal:f(u.toe,d.toe),camberPerLongitudinal:f(u.camber,d.camber),toePerAligning:f(p.toe,m.toe),lateralPatch:f(c.patch[1],l.patch[1]),longitudinalPatch:f(u.patch[0],d.patch[0]),bypassed:!1,converged:h}}var n_=1e3;function Ub(e,t=n_){if(!Xo(e.compliance)||!Uo(e))return;let r=wt(e),n=tt(r,0,0),o=Cm(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 Ps(e,t=-$b,r=$b,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=ct(e,{travelMin:t,travelMax:r,steps:n}),s=Ub(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 Fm(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 go(e,t){return{motionRatio:Fm(e.travel,e.motionRatio,t),camber:Fm(e.travel,e.camber,t),toe:Fm(e.travel,e.toe,t),damperLen:Fm(e.travel,e.damperLen,t)}}var LM=Math.PI/180,o_=9.81;function yo(e,t,r,n=0){let o=Ge(e),a=e.wheelbase*(1-e.frontMassFrac),s=e.wheelbase*e.frontMassFrac,i=As(e,n),c=e.aero?.model?(v,k,R)=>As(e,n,k,v,R):()=>i,l=go(t,0),u=go(r,0),d=e.loadFactor,p=d!==void 0&&d!==1?(d-1)*e.massTotal*o_:0,m=p*e.frontMassFrac/2,f=p*(1-e.frontMassFrac)/2,h=(v,k)=>k>0&&Number.isFinite(k)&&v+k>0?k/(v+k):1,b=yt(e,"front"),g=yt(e,"rear"),y={F:h(e.wheelRateFront+(e.heaveSpringFront??0),b),R:h(e.wheelRateRear+(e.heaveSpringRear??0),g)},x={F:h(e.wheelRateFront+e.arbFront,b),R:h(e.wheelRateRear+e.arbRear,g)};return(v,k,R=0,M=0)=>{let S=c(v,k,R),w={F:o.rollGradientFront*v,R:o.rollGradientRear*v},F=o.pitchGradient*k*LM,T=(_,D)=>{let I=D==="F"?e.trackFront:e.trackRear,V=D==="F"?o.rideRateFront:o.rideRateRear,O=(_==="R"?1:-1)*(I/2)*Math.tan(w[D]*LM),B=(D==="R"?s:-a)*Math.tan(F),z=`${D}${_}`,j=p?S[z]+(D==="F"?m:f):S[z],$=V>0?j/V:0;return{anti:O,sym:B+$}},A={FL:T("L","F"),FR:T("R","F"),RL:T("L","R"),RR:T("R","R")},C=_=>{let D=_[0];return A[_].sym*y[D]+A[_].anti*x[D]},P=Ss(e,M,o,{FL:C("FL"),FR:C("FR")}),L=P.ends?{F:w.F+P.ends.front,R:w.R+P.ends.rear}:{F:w.F+P.rollDeg,R:w.R+P.rollDeg},E=(_,D)=>{let I=D==="F"?t:r,V=D==="F"?l:u,O=`${D==="F"?"F":"R"}${_}`,B=A[O].sym+A[O].anti+P.travel[O],z=C(O)+P.travel[O]*x[D],j=B-z,$=go(I,z),N=(_==="R"?1:-1)*$.camber;return{travel:z,tyre:j,ground:B,camber:N,camberRoad:N+L[D],toe:$.toe,bumpToe:$.toe-V.toe,damperTravel:V.damperLen-$.damperLen}};return{FL:E("L","F"),FR:E("R","F"),RL:E("L","R"),RR:E("R","R"),steeringJacking:P}}}var Xb=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function qo(e){return{enabled:e?.enabled===!0,roadFeedbackGain:Math.min(2,Math.max(0,Xb(e?.roadFeedbackGain,1))),turnInFrictionNm:Math.max(0,Xb(e?.turnInFrictionNm,0)),columnStiffnessNmPerRad:Math.max(0,Xb(e?.columnStiffnessNmPerRad,0))}}function qb(e,t,r){let n=qo(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 DM=()=>({totalNm:0,aligningNm:0,lateralNm:0,longitudinalNm:0,jackingNm:0});function Qo(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 kc(e,t,r,n="model",o){let a=e.steerFront;if(!Qo(e)||!a)return null;let s=t<0?-1:1,c=a.rackRatioMmPerRev/(2*Math.PI)/1e3,l=t>=0,u=o&&a.travelSurface?ks(a,Math.abs(t),l?o.FL:o.FR,l?o.FR:o.FL):Ms(a,Math.abs(t));if(!u.innerJacobian||!u.outerJacobian)return null;let d=(b,g)=>{let y=r[b],x=b==="FL"?-1:1,v=-x*y.Fy,R={aligning:1e3*(-x*y.Mz)*g.yaw,lateral:v*g.lateral,longitudinal:y.Fx*g.longitudinal,jacking:y.Fz*g.vertical},M=DM();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 S=-s*(R.aligning+R.lateral+R.longitudinal+R.jacking);return{moment:M,rackN:S}},p=d("FL",l?u.innerJacobian:u.outerJacobian),m=d("FR",l?u.outerJacobian:u.innerJacobian),f=DM();for(let b of[p.moment,m.moment])f.aligningNm+=b.aligningNm,f.lateralNm+=b.lateralNm,f.longitudinalNm+=b.longitudinalNm,f.jackingNm+=b.jackingNm,f.totalNm+=b.totalNm;let h=qb(f.totalNm,t,e.steeringSystem);return f.totalNm=h.driverNm,{...f,roadNm:h.roadNm,assistanceNm:h.assistanceNm,frictionNm:h.frictionNm,columnTwistDeg:h.columnTwistDeg,rackForceN:p.rackN+m.rackN,aligningSource:n,perWheel:{FL:p.moment,FR:m.moment}}}var a_=e=>"front"in e&&"rear"in e;function Ls(e,t){return a_(e)?e[t]:e}function Zb(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 d=Math.min(r-2,Math.floor(u/o)),p=(u-a[d])/o;return l[d]+p*(l[d+1]-l[d])};return{muX:l=>c(s,l),muY:l=>c(i,l)}}function Qb(e,t){let r=Math.max(0,t.Fz);return IM(e.muX(r)*r,e.muY(r)*r,t)}function IM(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 EM(e,t,r){let n=Qb(e,t),o=Qb(e,r);return{left:n,right:o,fyRes:n.fyRes+o.fyRes}}function Dn(e,t,r){let n=EM(Ls(e,"front"),t.FL,t.FR),o=EM(Ls(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 Mc=[{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"}],i_=Mc.flatMap(e=>[e.min,e.max]);function c_(e){let t={};for(let r of Mc){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 Tm(e){if(e.kind==="magic")return e.range??c_(e.coeffs)}function Jb(e){return Math.max(1,e.kind==="magic"?e.fnomin:e.nominalLoad)}function _M(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 Or(e){let t=NM.get(e);if(t!==void 0)return t;let r=10*Jb(e.model),{turnover:n,collapse:o}=u_(e,r),a=n??o??r;return NM.set(e,a),a}var NM=new WeakMap;function u_(e,t){let r=Jb(e.model),n=d=>e.muY(d),o=d=>n(d)*d,a=80,s=t/a,i=null,c=o(s);for(let d=2;d<=a;d++){let p=o(d*s);if(p<c){i=_M(o,(d-2)*s,d*s,20,(m,f)=>m>f);break}c=p}let l=null,u=n(s);for(let d=2;d<=a;d++){let p=n(d*s);if(p>u){let m=_M(n,(d-2)*s,d*s,40,(f,h)=>f<h);n(m)<.05*n(r)&&(l=m);break}u=p}return{turnover:i,collapse:l}}var OM=.1;function Pm(e,t=Jb(e)){let r=Ke(e).muX(t);return{muX:r,none:Number.isFinite(r)&&r<OM}}var VM=["FL","FR","RL","RR"],m_=e=>e==="FL"||e==="RL",d_=e=>e==="FL"||e==="FR"?"front":"rear";function Lm(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 VM)a[l]={...t[l]};let s=l=>{let u=0;for(let p of VM)d_(p)===e.axle&&(a[p].Fx=e.sense*(p===e.strong?l-e.open/2:e.open/2),u-=(m_(p)?o:-o)*a[p].Fx);let d=Dn(r,a,n.arms);return u*n.ayDir>=0?Math.abs(u)<=d.stabil:Math.abs(u)<=d.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 p_=[["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]],f_=[["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]],h_=[["QBZ1","Trail slope factor for trail Bpt at Fznom",8],["QBZ2","Variation of slope Bpt with load",0],["QBZ3","Variation of slope Bpt with load squared",0],["QBZ4","Variation of slope Bpt with camber",0],["QBZ5","Variation of slope Bpt with absolute camber",0],["QBZ9","Factor for scaling factors of slope factor Br of Mzr",0],["QBZ10","Factor for dimensionless cornering stiffness of Br of Mzr",0],["QCZ1","Shape factor Cpt for pneumatic trail",1.1],["QDZ1","Peak trail Dpt = Dpt*(Fz/Fznom*R0)",.1],["QDZ2","Variation of peak Dpt with load",0],["QDZ3","Variation of peak Dpt with camber",0],["QDZ4","Variation of peak Dpt with camber squared",0],["QDZ6","Peak residual torque Dmr = Dmr/(Fz*R0)",0],["QDZ7","Variation of peak factor Dmr with load",0],["QDZ8","Variation of peak factor Dmr with camber",0],["QDZ9","Variation of peak factor Dmr with camber and load",0],["QDZ10","Variation of peak factor Dmr with camber squared",0],["QDZ11","Variation of Dmr with camber squared and load",0],["QEZ1","Trail curvature Ept at Fznom",0],["QEZ2","Variation of curvature Ept with load",0],["QEZ3","Variation of curvature Ept with load squared",0],["QEZ4","Variation of curvature Ept with sign of Alpha-t",0],["QEZ5","Variation of Ept with camber and sign Alpha-t",0],["QHZ1","Trail horizontal shift Sht at Fznom",0],["QHZ2","Variation of shift Sht with load",0],["QHZ3","Variation of shift Sht with camber",0],["QHZ4","Variation of shift Sht with camber and load",0],["PPZ1","Effect of inflation pressure on length of pneumatic trail",0],["PPZ2","Influence of inflation pressure on residual aligning torque",0],["SSZ1","Nominal value of s/R0: effect of Fx on Mz",0],["SSZ2","Variation of distance s/R0 with Fy/Fznom",0],["SSZ3","Variation of distance s/R0 with camber",0],["SSZ4","Variation of distance s/R0 with load and camber",0]],b_=[["RBX1","Slope factor for combined slip Fx reduction",0],["RBX2","Variation of slope Fx reduction with kappa",0],["RBX3","Influence of camber on stiffness for Fx combined",0],["RCX1","Shape factor for combined slip Fx reduction",1],["REX1","Curvature factor of combined Fx",0],["REX2","Curvature factor of combined Fx with load",0],["RHX1","Shift factor for combined slip Fx reduction",0],["RBY1","Slope factor for combined Fy reduction",0],["RBY2","Variation of slope Fy reduction with alpha",0],["RBY3","Shift term for alpha in slope Fy reduction",0],["RBY4","Influence of camber on stiffness of Fy combined",0],["RCY1","Shape factor for combined Fy reduction",1],["REY1","Curvature factor of combined Fy",0],["REY2","Curvature factor of combined Fy with load",0],["RHY1","Shift factor for combined Fy reduction",0],["RHY2","Shift factor for combined Fy reduction with load",0],["RVY1","Kappa induced side force Svyk/Muy*Fz at Fznom",0],["RVY2","Variation of Svyk/Muy*Fz with load",0],["RVY3","Variation of Svyk/Muy*Fz with camber",0],["RVY4","Variation of Svyk/Muy*Fz with alpha",0],["RVY5","Variation of Svyk/Muy*Fz with kappa",1],["RVY6","Variation of Svyk/Muy*Fz with atan(kappa)",0]],g_=[["LFZO","Scale factor of nominal (rated) load",1],["LCX","Scale factor of Fx shape factor",1],["LMUX","Scale factor of Fx peak friction coefficient",1],["LEX","Scale factor of Fx curvature factor",1],["LKX","Scale factor of Fx slip stiffness",1],["LHX","Scale factor of Fx horizontal shift",1],["LVX","Scale factor of Fx vertical shift",1],["LCY","Scale factor of Fy shape factor",1],["LMUY","Scale factor of Fy peak friction coefficient",1],["LEY","Scale factor of Fy curvature factor",1],["LKY","Scale factor of Fy cornering stiffness",1],["LKYC","Scale factor of camber force stiffness",1],["LKZC","Scale factor of camber torque stiffness",1],["LHY","Scale factor of Fy horizontal shift",1],["LVY","Scale factor of Fy vertical shift",1],["LTR","Scale factor of peak of pneumatic trail",1],["LRES","Scale factor for offset of residual torque",1],["LXAL","Scale factor of alpha influence on Fx",1],["LYKA","Scale factor of kappa influence on Fy",1],["LVYKA","Scale factor of kappa induced Fy",1],["LS","Scale factor of moment arm of Fx",1]],$M=[["lateral",p_],["longitudinal",f_],["aligning",h_],["combined",b_],["scaling",g_]].flatMap(([e,t])=>t.map(([r,n,o])=>({key:r,section:e,text:n,fallback:o}))),wU=new Map($M.map(e=>[e.key,e]));var y_=/^\$\s*EDITED\s+([A-Z][A-Z0-9_]*)\s+was\s+(absent|[-+0-9.eE]+)\s*$/;function GM(e){let t={};for(let r of e.split(/\r?\n/)){let n=r.trim().match(y_);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 R_=/^\s*\$\s*UNLOADED_RADIUS_STAND_IN\s*=\s*([0-9.eE+-]+)/,v_=/^\$-+ written by (?:PaceDynamics|PaceLab)\b/m,k_=/^\$\s*AXIS_SYSTEM\s*=\s*(ISO-W|SAE)\b/m;function M_(e){let t=e.match(k_);return t?{axisSystem:t[1]==="SAE"?"sae":"iso",trustSide:!0}:v_.test(e)?{axisSystem:"sae",trustSide:!1}:{axisSystem:"iso",trustSide:!0}}function S_(e){return e>=62?"6.2":e>=61?"6.1":"5.2"}var KM=new Map([["pa",1],["pascal",1],["kpa",1e3],["kilopascal",1e3],["mpa",1e6],["megapascal",1e6],["bar",1e5],["psi",6894.757293168]]);function A_(e,t,r){let n=r.PRESSURE?.trim().toLowerCase(),o=n===void 0?1:KM.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 w_=new Map([["radians",1],["radian",1],["rad",1],["degrees",Math.PI/180],["degree",Math.PI/180],["deg",Math.PI/180]]);function C_(e,t){let r=(s,i)=>s===void 0?1:i.get(s.trim().toLowerCase()),n=r(t.ANGLE,w_),o={fz:1,kappa:1,alpha:n,gamma:n,p:r(t.PRESSURE,KM)},a={};for(let s of Mc){let i=o[s.q];if(i===void 0)continue;let c={};for(let[l,u]of[["min",s.min],["max",s.max]]){let d=e[u];Number.isFinite(d)&&(c[l]=i===1?d:Number((d*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 Sc(e,t="imported",r={}){let n=M_(e),o=r.axisSystem??n.axisSystem,a={},s={},i={},c="",l;for(let g of e.split(/\r?\n/)){let y=g.match(R_);y&&(l=parseFloat(y[1]));let x=g.replace(/[$!].*$/,"").trim();if(!x)continue;if(x.startsWith("[")){c=(x.match(/^\[([^\]]*)/)?.[1]??"").trim().toUpperCase();continue}let v=x.indexOf("=");if(v<0)continue;let k=x.slice(0,v).trim().toUpperCase(),R=x.slice(v+1).trim(),M=R.match(/^'([^']*)'|^"([^"]*)"/);if(M){s[k]=M[1]??M[2]??"",c==="UNITS"&&(i[k]=s[k]);continue}let S=parseFloat(R);Number.isFinite(S)&&(a[k]=S)}let u=S_(a.FITTYP??62),d=GM(e),p=d?Object.fromEntries(Object.entries(d).filter(([g])=>a[g]!==void 0)):void 0,m=a.VERTICAL_STIFFNESS??a.KZ??0,f=A_(a,s,i),h=C_(a,i),b=[];return a.UNLOADED_RADIUS===void 0&&a.R0===void 0&&b.push("UNLOADED_RADIUS"),m<=0&&b.push("VERTICAL_STIFFNESS"),a.FNOMIN===void 0&&b.push("FNOMIN"),f===void 0&&b.push("NOMPRES"),{kind:"magic",name:t,version:u,coeffs:a,axisSystem:o,side:n.trustSide?s.TYRESIDE==="RIGHT"?"right":s.TYRESIDE==="LEFT"?"left":void 0:void 0,fnomin:a.FNOMIN??5e3,unloadedR0:a.UNLOADED_RADIUS??a.R0??(l!==void 0&&l>0?l:.3),...a.WIDTH!==void 0&&a.WIDTH>0?{sectionWidth:a.WIDTH}:{},verticalStiffness:m>0?m/1e3:0,...a.FREFF!==void 0&&!a.DREFF?{rollingFraction:a.FREFF}:{},...a.LATERAL_STIFFNESS!==void 0&&a.LATERAL_STIFFNESS>0?{relaxation:{sigma:0,carcassStiffness:a.LATERAL_STIFFNESS/1e3,source:"fitted"}}:{},nomPressure:f??0,missing:b,...p&&Object.keys(p).length?{edited:p}:{},...h?{range:h}:{}}}function on(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 Dm(e){if(!e)return null;let t=e.sectionWidth;return t!==void 0&&t>0?t:null}function HM(e){if(!e||e.kind!=="magic")return null;let t=e.coeffs.RIM_RADIUS,r=e.coeffs.RIM_WIDTH;return typeof t=="number"&&t>0&&typeof r=="number"&&r>0?{diameter:2*t*1e3,width:r*1e3}:null}var IU=Math.PI/180;var BU=Math.PI/180,$U=180/Math.PI;function Ac(){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 WM=`$ AXIS_SYSTEM = SAE (authored in the evaluation frame: y right)
|
|
2
|
+
import{parentPort as gI,workerData as gY}from"node:worker_threads";import{readFileSync as T1}from"node:fs";import{join as P1}from"node:path";var Iu=e=>e.format!=="points"&&!e.field;var kt=e=>e?.kind==="ice";var pv={packVoltageMax:600,segmentVoltageMax:120,powerLimitKw:80};var Je=e=>typeof e=="number"&&Number.isFinite(e);function xI(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 RI(e){return!e||typeof e!="object"?"The cell has no curve.":e.kind==="table"?xI(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 _u(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=RI(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 $o(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 et(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 Nu(e,t,r,n,o){let a=e.length,s=t.length;if(a===0||s===0)return 0;let i=$o(e,n),c=$o(t,o),l=Math.min(i.i+1,a-1),u=Math.min(c.i+1,s-1),d=r[c.i][i.i],p=r[c.i][l],m=r[u][i.i],f=r[u][l],h=d+i.t*(p-d),b=m+i.t*(f-m);return h+c.t*(b-h)}var as=[0,.05,.1,.2,.3,.4,.5,.6,.7,.8,.9,1],gh={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]},fv=[0,.05,.1,.2,.5,.8,1],hv=[2.2,1.55,1.3,1.12,1,.97,.98];function bv(e){return et(fv,hv,e)}var gv=[-20,-10,0,10,25,40,60],yv=[4,2.8,2,1.4,1,.82,.75];function yh(e){return et(gv,yv,e)}var xv=.5;function xh(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=gh[t]??gh.other,l=e.socAtNom??xv,u=as.includes(l)?[...as]:[...as,l].sort((h,b)=>h-b),d=et(as,c,l),p=d>0&&d<1?Math.log(i)/Math.log(d):1,m=[],f=[];for(let h of u){let b=et(as,c,h);m.push(o+s*Math.pow(b,p)),f.push(e.constantResistance?a:a*bv(h))}return{kind:"table",soc:u,ocv:m,r0:f}}function Rh(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+=(et(t,r,s)+et(t,r,i))/2*(i-s)}return o}var ss=25,Rv=new WeakMap;function An(e){let t=Rv.get(e);if(t)return t;let r=_u(e);if(r)throw new Error(r);let{cell:n,pack:o}=e,a=n.curve.kind==="table"?n.curve:xh(n.curve,n.chemistry),s=o.series,i=o.parallel,c=s/i,l=a.rTempC,u=a.rGrid,d=i*n.capacityAh,p=s*n.vMin,m=n.iMaxA>0?i*n.iMaxA:1/0,f=n.iMaxChargeA!==void 0&&n.iMaxChargeA>0?n.iMaxChargeA:n.iMaxA/4,h=f>0?i*f:1/0,b=S=>s*et(a.soc,a.ocv,S),g=(S,w=ss)=>{let F=l&&u?Nu(a.soc,l,u,S,w):et(a.soc,a.r0,S)*yh(w);return c*F+o.busResistance},y=(S,w,F)=>b(S)-w*g(S,F),x=(S,w,F)=>{if(!(S>0))return 0;let T=b(w),A=g(w,F);if(!(A>0))return S/T;let C=T*T-4*A*S;return C<0?NaN:2*S/(T+Math.sqrt(C))},v=(S,w,F)=>{if(!(S>0))return 0;let T=b(w),A=g(w,F);return A>0?2*S/(T+Math.sqrt(T*T+4*A*S)):S/T},k=S=>{let w=e.thermal;if(!w||w.derateFromC===void 0)return 1;let F=w.derateToC??w.derateFromC;return S<=w.derateFromC?1:!(F>w.derateFromC)||S>=F?0:1-(S-w.derateFromC)/(F-w.derateFromC)},R=(S,w,F=0)=>{let T=b(S),A=g(S,w),C=A>0?T/(2*A):1/0,P=$=>{if(!(A>0))return $*T;let N=Math.min($,C);return N*(T-N*A)},L=A>0?Math.max(0,(T-p)/A):1/0,E=F>0&&Number.isFinite(F)?F:1/0,_=A>0?P(L):1/0,D=Number.isFinite(m)?P(m):1/0,I=A>0?T*T/(4*A):1/0,V=[["rules",E],["voltage-floor",_],["current",D],["matched-load",I]],O=V[0][0],B=V[0][1];for(let[$,N]of V)N<B&&(B=N,O=$);let z=k(w??ss);z<1&&(B=Number.isFinite(B)?B*z:B,O="temperature");let j=Number.isFinite(B)?x(B,S,w):1/0;return{watts:B,binding:O,rules:E,voltageFloor:_,current:D,matchedLoad:I,derate:z,amps:j,volts:Number.isFinite(j)?T-j*A:T}},M={model:e,table:a,capacityAh:d,chargeC:d*3600,energyKwh:d*(s*Rh(a))/1e3,socRange:[a.soc[0],a.soc[a.soc.length-1]],voltageAtFull:s*a.ocv[a.ocv.length-1],voltageCeiling:s*n.vMax,voltageFloor:p,currentCeiling:m,chargeCurrentCeiling:h,massKg:n.massKg!==void 0?s*i*n.massKg:null,thermal:e.thermal?{heatCapacityJPerK:s*i*e.thermal.heatCapacityJPerK,coolingWPerK:s*i*e.thermal.coolingWPerK,...e.thermal.startC!==void 0?{startC:e.thermal.startC}:{},entropicVPerK:s*(e.thermal.entropicVPerK??0)}:null,derateAt:k,ocv:b,resistance:g,terminalVoltage:y,currentFor:x,chargeCurrentFor:v,maxPower:R};return Rv.set(e,M),M}function vh(e){return{name:e.name,chemistry:e.chemistry,capacityAh:e.capacityAh,curve:{kind:"analytic",vFull:e.vFull,vNom:e.vNom,vCut:e.vCut,r0:e.r0},iMaxA:e.iMaxA,...e.iMaxChargeA!==void 0?{iMaxChargeA:e.iMaxChargeA}:{},vMin:e.vCut,vMax:e.vFull,...e.massKg!==void 0?{massKg:e.massKg}:{}}}var vv={name:"High-power NMC pouch 4.0 Ah",chemistry:"nmc",capacityAh:4,vCut:3,vNom:3.6,vFull:4.2,r0:.0025,iMaxA:100,iMaxChargeA:40,massKg:.09},kv={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},Mv={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 kh(){return{name:"Formula Student accumulator",cell:vh(vv),pack:{series:140,parallel:2,busResistance:.02,seriesPerSegment:28},provenance:{source:"assumed",note:"Assumed high-power NMC pouch pack sized to the Formula Student rules; the cell curve and resistance are class-level guesses, not a measurement."}}}function Mh(){return{name:"LFP pack",cell:vh(kv),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 Sh(){return{name:"Road car pack",cell:vh(Mv),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 Ah(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 Ou(e){if(e.kind==="ice"){let n=e.gearbox.efficiency;return{model:e,maxTorque:o=>o>e.limitRpm?0:et(e.rpm,e.torque,o),efficiency:()=>n}}let t=n=>et(e.rpm,e.torque,n),r=e.kind==="simple"?()=>e.efficiency:(n,o)=>Nu(e.effRpm,e.effTorque,e.effGrid,n,o);return{model:e,maxTorque:t,efficiency:r}}function wh(e){let t=e.resistanceAtC??20,r=e.torqueConstant,n=e.speedLossW??0,o=e.speedLossAtRpm??0,a=e.speedLossExponent??1.5,s=e.derateFromC,i=e.derateToC,c=f=>Math.max(0,e.terminalResistanceOhm*(1+.00393*(f-t))),l=f=>n>0&&o>0?n*Math.pow(Math.max(0,f)/o,a):0,u=(f,h,b)=>{let g=r>0?Math.abs(h)/r:0;return 1.5*c(b)*g*g+l(f)},d=(f,h)=>{let b=e.coolingWPerK*(h-e.coolantC)-l(f);return!(b>0)||r<=0?0:r*Math.sqrt(b/(1.5*c(h)))},p=e.coolingWPerK>0?e.heatCapacityJPerK/e.coolingWPerK:1/0,m=Number.isFinite(p)?.25*p:1/0;return{spec:e,startC:e.startC??e.coolantC,lossW:u,step(f,h,b){if(!(b>0)||!(e.heatCapacityJPerK>0))return f;let g=Number.isFinite(m)?Math.max(1,Math.ceil(b/m)):1,y=b/g,x=f;for(let v=0;v<g;v++)x+=(h-e.coolingWPerK*(x-e.coolantC))*y/e.heatCapacityJPerK;return x},continuousTorque:d,derate(f,h,b){if(s===void 0||i===void 0||!(i>s)||!(b>0)||h<=s)return 1;let g=Math.min(1,d(f,i)/b);return h>=i?g:1-(1-g)*(h-s)/(i-s)},equilibriumC(f){return e.coolingWPerK>0?e.coolantC+f/e.coolingWPerK:1/0}}}function yt(e,t){return t==="rear"&&e.tireRateRear!==void 0?e.tireRateRear:e.tireRate}function Ch(e,t){let r=e.tyreFreeRadiusRear;return(t==="rear"&&r!==void 0?r:e.tyreFreeRadius)??0}var Vu=9.81,Sv=(e,t)=>e*(t*t)/2*(Math.PI/180)/1e3,Hi=(e,t)=>e+t>0?e*t/(e+t):0,Av=.5;function Bu(e,t,r){if(!(r>0))return 1;let n=e*Vu*t*(Math.PI/180)/r;return 1/(1-Math.min(Av,n))}function wv(e,t,r,n){let o=r??0,a=e+t;if(!(o>0)||!Number.isFinite(o)||!(a>0))return null;let s=Math.max(0,Math.min(1,n)),i=e*t+o*a,c=a*(s*t+o)/i,l=a*((1-s)*e+o)/i;return{share:e/a*c,front:c,rear:l}}function Fh(e,t,r){return r>0?e*Vu*t/(r*r):0}function Cv(e,t,r,n,o){if(!(n>0)||!(o>0))return 1;let a=Fh(e,t,r)*(1/n+1/o);return 1/(1-Math.min(Av,a))}function Ge(e){let t=4*e.unsprungPerCorner,r=Math.max(0,e.massTotal-t),n=r*e.frontMassFrac,o=r*(1-e.frontMassFrac),a=yt(e,"front"),s=yt(e,"rear"),i=e.wheelRateFront+(e.heaveSpringFront??0),c=e.wheelRateRear+(e.heaveSpringRear??0),l=Hi(i,a),u=Hi(c,s),d=(B,z)=>{let j=z/2;return j>0?1/(2*Math.PI)*Math.sqrt(B*1e3/j):0},p=d(l,n),m=d(u,o),f=Hi(e.wheelRateFront+e.arbFront,a),h=Hi(e.wheelRateRear+e.arbRear,s),b=Sv(f,e.trackFront),g=Sv(h,e.trackRear),y=b+g,x=y>0?b/y:.5,v=e.rcHeightFront+(e.rcHeightRear-e.rcHeightFront)*(1-e.frontMassFrac),k=(e.cgHeight-v)/1e3,R=r*Vu*k,M=Bu(r,k,y),S=y>0?R/y*M:0,w=wv(b,g,e.chassisTorsion,e.frontMassFrac),F=w?w.share:x,T=w?S*w.front:S,A=w?S*w.rear:S,C=e.massTotal*Vu*e.cgHeight/e.wheelbase,P=2*l,L=2*u,E=Cv(r,e.cgHeight,e.wheelbase,P,L),D=(P>0&&L>0?(C/P+C/L)/e.wheelbase*E:0)*(180/Math.PI),I=e.wheelbase*e.wheelbase*Hi(P,L)*(Math.PI/180)/1e3,V=e.damperFront??2.5,O=e.damperRear??2.5;return{sprungMass:r,sprungFront:n,sprungRear:o,rideRateFront:l,rideRateRear:u,rideFreqFront:p,rideFreqRear:m,rollRateFront:b,rollRateRear:g,rollRateTotal:y,rollWheelRateFront:f,rollWheelRateRear:h,frontRollStiffFrac:x,frontElasticShare:F,rollGradient:S,rollGradientFront:T,rollGradientRear:A,pitchGradient:D,pitchRate:I,cgRollGain:M,cgPitchGain:E,rideDampingFront:V+(e.heaveDamperFront??0),rideDampingRear:O+(e.heaveDamperRear??0),rollDampingFront:V+(e.rollDamperFront??0),rollDampingRear:O+(e.rollDamperRear??0)}}var lo=["clFront","clRear","cd"],uo=e=>e.frame?.kind==="pitch";function is(e){return uo(e)?{x:e.axes.h,y:e.axes.pitch}:{x:e.axes.hFront,y:e.axes.hRear}}var $u=e=>e.frame?.kind==="pitch",Fv=e=>e.kind==="map";var Gu=45,Mt=e=>typeof e=="number"&&Number.isFinite(e);function Ku(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(Mt))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 Tv(e,t){if(t===void 0)return null;for(let r of lo){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(Mt)||!n.factor.every(Mt))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 Pv(e,t){return t===void 0?null:!Mt(t.dCl)||!Mt(t.dBalance)||!Mt(t.dCd)?`The ${e} slopes must be numbers.`:!Mt(t.maxDeg)||!(t.maxDeg>0)?`The ${e} response needs a positive angle to be valid to.`:null}function zi(e){if(!e||typeof e!="object")return"Not an aero model.";if(!Mt(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=Ku("front ride-height",e.axes?.hFront);if(i)return i;let c=Ku("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(!Mt(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=Ku("ride-height",e.axes?.h);if(i)return i;let c=Ku("pitch",e.axes?.pitch,"\xB0","pitch");if(c)return c;let l=e.axes.pitch.find(u=>Math.abs(u)>=Gu);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 lo){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(Mt))return`${i} contains a value that is not a number.`}}return Tv("yaw",e.attitude?.yaw)??Tv("roll",e.attitude?.roll)}if(e.kind==="sensitivity"){let t;if(e.frame==null)t=["hFront","hRear"];else if(e.frame?.kind==="pitch"){if(!Mt(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||!Mt(r[t[0]])||!Mt(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 lo){if(!e.at||!Mt(e.at[s]))return`${s} at the reference must be a number.`;let i=n?.[s];if(!i||!Mt(i[t[0]])||!Mt(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||!Mt(i[0])||!Mt(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])>=Gu||Math.abs(i[1])>=Gu))return`A pitch range reaching ${Math.abs(i[0])>=Gu?i[0]:i[1]}\xB0 is not a car's attitude. Pitch is in degrees.`}return Pv("yaw",e.attitude?.yaw)??Pv("roll",e.attitude?.roll)}return`Unknown aero model kind "${e.kind}".`}var Lv=180/Math.PI;function cs(e,t,r,n){let o=(n-r)/t;return{h:r+e.refX*o,pitch:Math.atan(o)*Lv}}function ls(e,t,r,n){let o=Math.tan(n/Lv);return{hFront:r-e.refX*o,hRear:r+(t-e.refX)*o}}var n8=180/Math.PI,vI=["hFront","hRear"],kI=["h","pitch"],Lh=e=>e?.kind==="pitch"?kI:vI,ar=(e,t)=>e[t],Hu=(e,t)=>e[t],Th=(e,t)=>({[e[0]]:t(e[0]),[e[1]]:t(e[1])});function MI(e){if(!(!e.yaw&&!e.roll))return{...e.yaw?{yaw:{...e.yaw}}:{},...e.roll?{roll:{...e.roll}}:{}}}function Dh(e){let t=Lh(e.frame),r=e.balanceFront,n=e.cl*r,o=e.cl*(1-r),a=Th(t,c=>ar(e.dCl,c)*r+e.cl*ar(e.dBalance,c)),s=Th(t,c=>ar(e.dCl,c)*(1-r)-e.cl*ar(e.dBalance,c)),i=MI(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:Th(t,c=>ar(e.dCd,c))},range:{[t[0]]:[...Hu(e.range,t[0])],[t[1]]:[...Hu(e.range,t[1])]},provenance:{...e.provenance},...i?{attitude:i}:{}}}function zu(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 Ph(e,t,r=11){let n=Array.from({length:r},(a,s)=>t.maxDeg*s/(r-1)),o=n.map(a=>zu(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 Dv(e){if(!(!e.attitude?.yaw&&!e.attitude?.roll))return{...e.attitude.yaw?{yaw:Ph(e.at,e.attitude.yaw)}:{},...e.attitude.roll?{roll:Ph(e.at,e.attitude.roll)}:{}}}function Ev(e,t,r,n=0,o=0){let[a,s]=Lh(e.frame),i=t-ar(e.ref,a),c=r-ar(e.ref,s),l={clFront:e.at.clFront+ar(e.slope.clFront,a)*i+ar(e.slope.clFront,s)*c,clRear:e.at.clRear+ar(e.slope.clRear,a)*i+ar(e.slope.clRear,s)*c,cd:e.at.cd+ar(e.slope.cd,a)*i+ar(e.slope.cd,s)*c},u=e.attitude?.yaw?zu(e.at,e.attitude.yaw,n):{clFront:1,clRear:1,cd:1},d=e.attitude?.roll?zu(e.at,e.attitude.roll,o):{clFront:1,clRear:1,cd:1};return{clFront:l.clFront*u.clFront*d.clFront,clRear:l.clRear*u.clRear*d.clRear,cd:l.cd*u.cd*d.cd}}function Eh(e){let[t,r]=Lh(e.frame),n=[...Hu(e.range,t)],o=[...Hu(e.range,r)],a=i=>o.map(c=>n.map(l=>i(Ev(e,l,c)))),s=Dv(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 Ih=180/Math.PI,Iv=new WeakMap,_v=new WeakMap,_h=new WeakMap;function mo(e,t){let r=_v.get(e);if(r)return r;let n=t?.wheelbase,o=n!==void 0?_h.get(e)?.get(n):void 0;if(o)return o;let a=SI(e),s=a.map;if(!uo(s)){let l=AI(e,a);return _v.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=wI(e,a,s.frame,n),c=_h.get(e);return c||(c=new Map,_h.set(e,c)),c.set(n,i),i}function SI(e){let t=Iv.get(e);if(t)return t;let r=zi(e);if(r)throw new Error(r);let n=e.kind==="map"?e:Eh(e),{x:o,y:a}=is(n),s=o.length,i=a.length,c=n.attitude?.yaw,l=n.attitude?.roll,u=!!(c||l),d={clFront:1,clRear:1,cd:1,clamped:!1},p=(y,x)=>{let v=Math.abs(x),k=y.clFront.deg[y.clFront.deg.length-1];return{clFront:et(y.clFront.deg,y.clFront.factor,v),clRear:et(y.clRear.deg,y.clRear.factor,v),cd:et(y.cd.deg,y.cd.factor,v),clamped:v>k}},m=(y,x)=>{if(!u)return d;let v=c?p(c,y):d,k=l?p(l,x):d;return{clFront:v.clFront*k.clFront,clRear:v.clRear*k.clRear,cd:v.cd*k.cd,clamped:v.clamped||k.clamped}},f=(y,x,v=0,k=0)=>{let R=$o(o,y),M=$o(a,x),S=Math.min(R.i+1,s-1),w=Math.min(M.i+1,i-1),F=A=>{let C=A[M.i][R.i],P=A[M.i][S],L=A[w][R.i],E=A[w][S],_=C+R.t*(P-C),D=L+R.t*(E-L);return _+M.t*(D-_)},T=m(v,k);return{clFront:u?F(n.clFront)*T.clFront:F(n.clFront),clRear:u?F(n.clRear)*T.clRear:F(n.clRear),cd:u?F(n.cd)*T.cd:F(n.cd),clampedRide:R.clamped||M.clamped,clampedAttitude:T.clamped}},h={x:[o[0],o[s-1]],y:[a[0],a[i-1]]},b=(y,x,v=!1,k=0,R=0)=>{let M=m(k,R),S=$o(o,v?Math.min(Math.max(y,h.x[0]),h.x[1]):y),w=$o(a,v?Math.min(Math.max(x,h.y[0]),h.y[1]):x),F=Math.min(S.i+1,s-1),T=Math.min(w.i+1,i-1),A=F>S.i?o[F]-o[S.i]:0,C=T>w.i?a[T]-a[w.i]:0,P={};for(let L of lo){let E=n[L],_=E[w.i][S.i],D=E[w.i][F],I=E[T][S.i],V=E[T][F],O=S.clamped||A===0?0:((D-_)*(1-w.t)+(V-I)*w.t)/A,B=w.clamped||C===0?0:((I-_)*(1-S.t)+(V-D)*S.t)/C;P[L]=u?{x:O*M[L],y:B*M[L]}:{x:O,y:B}}return P},g={map:n,x:h.x,y:h.y,hasAttitude:u,factors:m,at:f,slopes:b};return Iv.set(e,g),g}function AI(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 d of lo)u[d]={hFront:l[d].x,hRear:l[d].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 wI(e,t,r,n){let o=r.refX,a=o/n,s=(l,u,d=0,p=0)=>{let m=(u-l)/n;return t.at(l+o*m,Math.atan(m)*Ih,d,p)},i=(l,u,d=!1,p=0,m=0)=>{let f=(u-l)/n,h=t.slopes(l+o*f,Math.atan(f)*Ih,d,p,m),b=Ih/(n*(1+f*f)),g={};for(let y of lo)g[y]={hFront:h[y].x*(1-a)-h[y].y*b,hRear:h[y].x*a+h[y].y*b};return g},c={frame:r,x:t.x,y:t.y,at:t.at,toAxles:(l,u)=>ls(r,n,l,u),fromAxles:(l,u)=>{let d=cs(r,n,l,u);return{x:d.h,y:d.pitch}}};return{model:e,map:t.map,area:t.map.area,grid:c,hasAttitude:t.hasAttitude,at:s,slopes:i,factors:t.factors}}function Nh(e){let t=e.clFront+e.clRear;return{cl:t,balanceFront:t!==0?e.clFront/t:.5}}var Se=(e,t)=>e*t/100,xt=e=>e/100,Nv={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:xt(-.3),hRear:xt(.15)},dCd:{hFront:Se(1.3,-.1),hRear:Se(1.3,.05)},yaw:{dCl:Se(3,-1),dBalance:xt(-.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."},Ov={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:xt(-.15),hRear:xt(.15)},dCd:{hFront:Se(.9,-.15),hRear:Se(.9,-.05)},yaw:{dCl:Se(3,-1.5),dBalance:xt(.2),dCd:Se(.9,.8),maxDeg:8},roll:{dCl:Se(3,-1),dBalance:xt(-.3),dCd:0,maxDeg:2},note:"Assumed class-level sensitivities for a ground-effect floor, ride height, yaw and roll; not measured."},Vv={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:xt(-.25),hRear:xt(.15)},dCd:{hFront:Se(.42,-.1),hRear:0},yaw:{dCl:Se(1.4,-.8),dBalance:xt(-.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."},Bv={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."},$v={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:xt(-.25),hRear:xt(.15)},dCd:{hFront:Se(.4,-.1),hRear:0},yaw:{dCl:Se(.45,-1.2),dBalance:xt(-.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."},Gv={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:xt(-.25),hRear:xt(.15)},dCd:{hFront:Se(.45,-.1),hRear:0},yaw:{dCl:Se(.6,-1),dBalance:xt(-.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."},Kv={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:xt(-.25),hRear:xt(.15)},dCd:{hFront:Se(.9,-.1),hRear:Se(.9,.05)},yaw:{dCl:Se(2.5,-1),dBalance:xt(-.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."},Hv={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 wn(e){return Dh({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 Oh=()=>wn(Nv),Vh=()=>wn(Ov),Bh=()=>wn(Vv),$h=()=>wn(Bv),Gh=()=>wn($v),Kh=()=>wn(Gv),Hh=()=>wn(Kv),zh=()=>wn(Hv);function Go(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 Yu(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,yt(e,"front")))/r,rear:(t.sprungMass*(1-n)+o*a(t.rideRateRear,yt(e,"rear")))/r}}function Wu(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 Yh(e,t){return e.wheelbase>0?e.massTotal*t*9.81/e.wheelbase:0}function us(e,t,r){let n=2*t.rideRateFront,o=2*t.rideRateRear;return!(n>0)||!(o>0)?0:Math.min(Fh(t.sprungMass,r,e.wheelbase),.5*n*o/(n+o))}function Yi(e,t,r,n,o){let a=e.cgHeight,s=Yh(e,r);if(n===0&&o===0&&s===0)return{height:a,forward:0,noseLoad:0,dropFront:0,dropRear:0};let i=Yu(e,t),c=2*t.rideRateFront,l=2*t.rideRateRear,u=a,d=0,p=0,m=0;for(let h=0;h<6;h++){m=us(e,t,u);let b=n-s*u,g=o+s*u;if(m>0){let v=c*l-m*(c+l);d=(b*(l-m)-m*g)/v,p=(g*(c-m)-m*b)/v}else d=c>0?b/c:0,p=l>0?g/l:0;let y=Wu(a,i,d,p),x=Math.abs(y-u);if(u=y,x<1e-9)break}let f=d-p;return{height:u,forward:e.wheelbase>0?u*f/e.wheelbase:0,noseLoad:m*f,dropFront:d,dropRear:p}}var Wh={yawDeg:0,rollDeg:0},zv=1e-4,CI=40,Yv=50;function po(e,t,r=0){let n=e.aero?.model;if(!(!n||!mo(n,e).hasAttitude))return{yawDeg:r,rollDeg:Ge(e).rollGradient*t}}function ms(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 ls(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=$u(r)?n(r.frame,r.ref.h,r.ref.pitch):r.ref;else if(r){let{x:a,y:s}=is(r),i=(a[0]+a[a.length-1])/2,c=(s[0]+s[s.length-1])/2;o=uo(r)?n(r.frame,i,c):{hFront:i,hRear:c}}return{hFront:e.rideHeightFront??o.hFront,hRear:e.rideHeightRear??o.hRear}}var Wv=new WeakMap;function Cn(e,t,r=0,n){let o=e.aero;if(!o?.model)return null;let a=Wv.get(e);a||(a=new Map,Wv.set(e,a));let s=n&&mo(o.model,e).hasAttitude?n:Wh,i=s===Wh?`${t}|${r}`:`${t}|${r}|${s.yawDeg.toFixed(3)}|${s.rollDeg.toFixed(3)}`,c=a.get(i);if(c)return c;let l=FI(e,o,t,r,s);return a.size>4096&&a.clear(),a.set(i,l),l}function FI(e,t,r,n,o){let a=mo(t.model,e),s=Ge(e),i=2*s.rideRateFront,c=2*s.rideRateRear,l=ms(t,e.wheelbase),u=.5*t.rho*r*r,d=a.area,p=e.wheelbase>0?t.copHeight/e.wheelbase:0,m=Yu(e,s),f=Yh(e,n),h=(F,T)=>Wu(e.cgHeight,m,l.hFront-F,l.hRear-T),b=(F,T)=>l.hFront-F-(l.hRear-T),g=(F,T)=>{let A=a.at(F,T,o.yawDeg,o.rollDeg),C=u*d*A.clFront,P=u*d*A.clRear,L=u*d*A.cd,E=L*p,_=h(F,T),D=f*_,I=us(e,s,_)*b(F,T),V=C-D-E+I,O=P+D+E-I,B=F-l.hFront+(i>0?V/i:0),z=T-l.hRear+(c>0?O/c:0);return{c:A,downFront:C,downRear:P,drag:L,rF:B,rR:z,norm:Math.hypot(B,z)}},y=(F,T,A=!1)=>{let C=a.slopes(F,T,A,o.yawDeg,o.rollDeg),P=i>0?u*d/i:0,L=c>0?u*d/c:0;return[[P*(C.clFront.hFront-p*C.cd.hFront),P*(C.clFront.hRear-p*C.cd.hRear)],[L*(C.clRear.hFront+p*C.cd.hFront),L*(C.clRear.hRear+p*C.cd.hRear)]]},x=l.hFront,v=l.hRear,k=g(x,v),R=0;for(;k.norm>=zv&&R<CI;){R++;let F=y(x,v),T=i>0?f/i:0,A=c>0?f/c:0,C=us(e,s,h(x,v)),P=i>0?C/i:0,L=c>0?C/c:0,E=1+F[0][0]-T*m.front-P,_=F[0][1]-T*m.rear+P,D=F[1][0]+A*m.front+L,I=1+F[1][1]+A*m.rear-L,V=E*I-_*D,O,B;Math.abs(V)>1e-9?(O=-(I*k.rF-_*k.rR)/V,B=-(-D*k.rF+E*k.rR)/V):(O=-.5*k.rF,B=-.5*k.rR);let z=Math.max(1,Math.abs(O)/Yv,Math.abs(B)/Yv);O/=z,B/=z;let j=1;for(let $=0;$<6;$++){let N=g(x+j*O,v+j*B);if(N.norm<=k.norm||$===5){x+=j*O,v+=j*B,k=N;break}j*=.5}}let M=y(x,v,!0),S=2+M[0][0]+M[1][1],w=(1+M[0][0])*(1+M[1][1])-M[0][1]*M[1][0];return{v:r,axG:n,hFront:x,hRear:v,cgHeight:h(x,v),cgForward:e.wheelbase>0?h(x,v)*b(x,v)/e.wheelbase:0,cgNoseLoad:us(e,s,h(x,v))*b(x,v),clFront:k.c.clFront,clRear:k.c.clRear,cd:k.c.cd,area:d,downforce:k.downFront+k.downRear,drag:k.drag,downFront:k.downFront,downRear:k.downRear,gain:TI(M),stable:w>0&&S>0,converged:k.norm<zv,iterations:R,clampedRide:k.c.clampedRide,yawDeg:o.yawDeg,rollDeg:o.rollDeg,clampedAttitude:k.c.clampedAttitude}}function TI(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 Wi(e,t,r=0,n){let o=Cn(e,t,r,n);return o?{downforce:o.downforce,drag:o.drag,downFront:o.downFront,downRear:o.downRear}:e.aero?Go(e.aero,t):{downforce:0,drag:0,downFront:0,downRear:0}}function PI(e,t,r,n){let o=Go(t,r),a=Ge(e),s=ms(t,e.wheelbase),i=e.wheelbase>0?o.drag*t.copHeight/e.wheelbase:0,c=Yi(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 jh(e,t,r=0,n){let o=Cn(e,t,r,n);return o||(e.aero?PI(e,e.aero,t,r):null)}function ju(e,t=0,r=0,n,o){if(e.aero&&t>0){if(e.aero.model){let i=Cn(e,t,r,n);return{height:i.cgHeight,forward:i.cgForward,noseLoad:i.cgNoseLoad}}let a=Go(e.aero,t),s=e.wheelbase>0?a.drag*e.aero.copHeight/e.wheelbase:0;return Yi(e,o??Ge(e),r,a.downFront-s,a.downRear+s)}return r===0?{height:e.cgHeight,forward:0,noseLoad:0}:Yi(e,o??Ge(e),r,0,0)}var jv=[0,1,0],Uh=[0,0,1],oe=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],H=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],X=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],Xh=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]],LI=e=>J(e,e),qr=e=>Math.sqrt(J(e,e)),ji=(e,t)=>LI(H(e,t)),Pe=(e,t)=>qr(H(e,t)),re=e=>{let t=qr(e);return t<1e-12?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]},Uv=(e,t,r)=>[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r,e[2]+(t[2]-e[2])*r];var Fn=(e,t,r)=>{let n=re(r),o=H(e,t);return oe(t,X(n,J(o,n)))},Xv=(e,t,r)=>Pe(e,Fn(e,t,r));var EI=1e-6;function II(e){if(e<EI){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 Dt(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]=II(r),a=le(e,t),s=le(e,a);return oe(t,oe(X(a,n),X(s,o)))}function sr(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 Dt(X(o,r),e)}function Qr(e,t){let r=t.length,n=e.map(a=>a.slice()),o=t.slice();return Qv(n,o,r,new Array(r).fill(0))}function qv(e,t,r){return Qv(e,t,t.length,r)}function Qv(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 d=Math.abs(e[u][s]);d>c&&(c=d,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 d=t[s];t[s]=t[i],t[i]=d}let l=e[s][s];for(let u=s+1;u<r;u++){let d=e[u][s]/l;if(d!==0){for(let p=s;p<r;p++)e[u][p]-=d*e[s][p];t[u]-=d*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 Zv=e=>{let t=0;for(let r of e)t=Math.max(t,Math.abs(r));return t},Jv=e=>{let t=0;for(let r of e)t+=r*r;return t},_I=Math.sqrt(Number.EPSILON);function ek(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=Zv(c),u=Jv(c),d=.001,p=1,m=c.length,f=Array.from({length:m},()=>new Array(a).fill(0)),h=Array.from({length:a},()=>new Array(a).fill(0)),b=Array.from({length:a},()=>new Array(a).fill(0)),g=new Array(a).fill(0),y=new Array(a).fill(0),x=new Array(a).fill(0),v=new Array(a).fill(0),k=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:p};for(let F=0;F<a;F++){let T=_I*Math.max(Math.abs(i[F]),s[F]);for(let C=0;C<a;C++)v[C]=i[C];v[F]+=T;let A=e(v);for(let C=0;C<m;C++)f[C][F]=(A[C]-c[C])/T}let M=0;for(let F=0;F<a;F++){for(let A=0;A<a;A++){let C=0;for(let P=0;P<m;P++)C+=f[P][F]*f[P][A];h[F][A]=C}let T=0;for(let A=0;A<m;A++)T+=f[A][F]*c[A];g[F]=T,M=Math.max(M,h[F][F])}let S=Math.max(M,1e-9),w=!1;for(let F=0;F<18;F++){let T=d*S;for(let C=0;C<a;C++){let P=h[C],L=b[C];for(let E=0;E<a;E++)L[E]=C===E?P[E]+T:P[E];y[C]=-g[C]}let A=qv(b,y,x);if(p=Math.max(p,A.condProxy),!A.singular){for(let L=0;L<a;L++)k[L]=i[L]+x[L];let C=e(k),P=Jv(C);if(P<u){for(let L=0;L<a;L++)i[L]=k[L];c=C,u=P,l=Zv(c),d=Math.max(d*.3,1e-12),w=!0;break}}d=Math.min(d*4,1e12)}if(!w)break}return{x:i,residualNorm:l,iterations:n,converged:l<o,condProxy:p}}function Ui(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,d=l*t/a;return{c1:u,s1:d,c2:u,s2:d,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 qh(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 tk=e=>[e[0],-e[1],-e[2],-e[3]];function ds(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 Uu(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 rk(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 Qh(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],d=r[2],p=n+i+d;if(p>=n&&p>=i&&p>=d){let h=Math.sqrt(1+p),b=.5/h;return[.5*h,(c-u)*b,(l-a)*b,(o-s)*b]}if(n>=i&&n>=d){let h=Math.sqrt(1+n-i-d),b=.5/h;return[(c-u)*b,.5*h,(s+o)*b,(l+a)*b]}if(i>=d){let h=Math.sqrt(1-n+i-d),b=.5/h;return[(l-a)*b,(s+o)*b,.5*h,(u+c)*b]}let m=Math.sqrt(1-n-i+d),f=.5/m;return[(o-s)*f,(l+a)*f,(u+c)*f,.5*m]}function nk(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 ok(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 NI(e){let t=Math.abs(e[0])<.6?[1,0,0]:[0,1,0],r=re(le(e,t));return[r,le(e,r)]}function OI(e){let t=e.hardpoints,r=re(H(t.damperChassis,t.pushrodOuter)),[n,o]=NI(r);return{top:t.damperChassis,lower0:t.pushrodOuter,axis0:r,e1:n,e2:o}}function Zh(e){let t=e.hardpoints,r=t.wheelCenter,n=re(H(t.ucaRear,t.ucaFront)),o=H(t.uprightUpper,t.ucaFront),a=J(o,n),s=H(o,X(n,a)),i=J(s,s),c=re(H(t.lcaRear,t.lcaFront)),l=H(t.uprightLower,t.lcaFront),u=ji(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:re(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:OI(e)}:{}}}function Rr(e,t,r){let n=[t[3],t[4],t[5]],o=[t[0],t[1],t[2]],a=H(r,e.c0);return oe(oe(Dt(n,a),e.c0),o)}function Jh(e,t){return oe(e.lcaFront,sr(e.lbjRel0,e.lcaDir,t))}function Ko(e,t){return e.steerMovesRack?oe(e.tieInner0,X(e.rackAxis,t)):e.tieInner0}function eb(e,t,r,n){let o=Rr(e,t,e.lbj0),a=Jh(e,r),s=o[0]-a[0],i=o[1]-a[1],c=o[2]-a[2],l,u;if(e.strut){let f=e.strut,h=[t[3],t[4],t[5]],b=H(f.top,Rr(e,t,f.lower0));l=J(b,Dt(h,f.e1)),u=J(b,Dt(h,f.e2))}else{let f=Rr(e,t,e.ubj0),h=H(f,e.ucaFront),b=J(h,e.ucaDir),g=H(h,X(e.ucaDir,b));l=b-e.ubjAxial0,u=(J(g,g)-e.ubjRadius2)/e.ubjRadiusRef}let d=Rr(e,t,e.tro0),p=Ko(e,n),m=(ji(d,p)-e.tieLen2)/e.tieLenRef;return[s,i,c,l,u,m]}var Xi=e=>Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]),Xu=e=>{let t=Xi(e);return[e[0]/t,e[1]/t,e[2]/t]},VI=(e,t)=>H(e,X(t,J(e,t))),tb=e=>Xu(le(e,Math.abs(e[0])<.6?[1,0,0]:[0,1,0]));function BI(e,t){let r=e.ucaDir,n=oe(e.ucaFront,X(r,e.ubjAxial0)),o=Math.sqrt(e.ubjRadius2),a=VI(H(e.ubj0,e.ucaFront),r),s=Xi(a)>1e-9?Xu(a):tb(r),i=le(r,s),c=H(e.ubj0,e.lbj0),l=J(c,c);if(!(l>1e-18))return"free";let u=H(n,t),d=J(u,u),p=Ui(2*o*J(s,u),2*o*J(i,u),l-d-o*o,2*o*Math.sqrt(d));if(p.free)return"free";let m=Xu(c),f=(h,b)=>{let g=oe(n,oe(X(s,o*h),X(i,o*b))),y=Xu(H(g,t));return{q1:Uu(m,y),k:y,margin:p.margin,ok:p.ok}};return p.margin>0?[f(p.c1,p.s1),f(p.c2,p.s2)]:[f(p.c1,p.s1)]}function $I(e,t,r){let n=t.axis0,o=oe(t.lower0,X(n,J(H(e.lbj0,t.lower0),n))),a=H(o,e.lbj0),s=Xi(a),i=s>1e-9?X(a,1/s):tb(n),c=H(t.top,r),l=Xi(c);if(!(l>1e-9))return"free";let u=X(c,1/l),d=s/l,p=1-d,m=p>=0?Math.sqrt((1-d)*(1+d)):0,f=tb(u),h=b=>{let g=b*m,y=oe(X(u,g),X(f,Math.min(d,1))),x=H(X(u,Math.min(d,1)),X(f,g));return{q1:qh(Qh(x,y,le(x,y)),tk(Qh(i,n,le(i,n)))),k:u,margin:p,ok:p>=0}};return p>0?[h(1),h(-1)]:[h(1)]}function GI(e,t,r,n){let{k:o}=n,a=ds(n.q1,H(e.tro0,e.lbj0)),s=J(a,o),i=H(a,X(o,s)),c=Xi(i);if(!(c>1e-9))return"free";let l=X(i,1/c),u=le(o,l),d=oe(t,X(o,s)),p=H(d,r),m=J(p,p),f=Ui(2*c*J(p,l),2*c*J(p,u),e.tieLen2-m-c*c,2*c*Math.sqrt(m));if(f.free)return"free";let h=(g,y)=>({q:qh(rk(o,g,y),n.q1)});return{roots:f.margin>0?[h(f.c1,f.s1),h(f.c2,f.s2)]:[h(f.c1,f.s1)],margin:f.margin,ok:f.ok}}function ak(e,t,r,n=[0,0,0,0,0,0]){let o=Jh(e,t),a=Ko(e,r),s=nk([n[3],n[4],n[5]]),i=h=>Math.abs(h[0]*s[0]+h[1]*s[1]+h[2]*s[2]+h[3]*s[3]),c=e.strut?$I(e,e.strut,o):BI(e,o);if(c==="free")return{x:n.slice(),converged:!1,margin:0,free:!0};let l=null,u=null;for(let h of c){let b=GI(e,o,a,h);if(b==="free")return{x:n.slice(),converged:!1,margin:0,free:!0};let g=Math.min(h.margin,b.margin),y=b.ok&&h.ok;for(let{q:x}of b.roots){let v=i(x);y&&(!l||v>l.near)&&(l={q:x,margin:g,near:v}),!y&&(!u||v>u.near)&&(u={q:x,margin:g,near:v})}}let{q:d,margin:p}=l??u,m=ok(d),f=H(H(o,e.c0),Dt(m,H(e.lbj0,e.c0)));return{x:[f[0],f[1],f[2],m[0],m[1],m[2]],converged:l!==null,margin:p,free:!1}}function ik(e){let t=re(H(e.rockerPivotB,e.rockerPivotA));return{pivotA:e.rockerPivotA,axis:t,rprRel0:H(e.rockerToPushrod,e.rockerPivotA),rdmRel0:H(e.rockerToDamper,e.rockerPivotA),damperChassis:e.damperChassis,rodLen2:ji(e.pushrodOuter,e.rockerToPushrod),damperLen0:Pe(e.rockerToDamper,e.damperChassis)}}var KI=(e,t)=>oe(e.pivotA,sr(e.rprRel0,e.axis,t)),rb=(e,t)=>oe(e.pivotA,sr(e.rdmRel0,e.axis,t));function ps(e,t){return{pushrod:KI(e,t),damper:rb(e,t)}}function ck(e,t,r=0){let n=J(e.rprRel0,e.axis),o=H(e.rprRel0,X(e.axis,n)),a=le(e.axis,o),s=H(oe(e.pivotA,X(e.axis,n)),t),i=J(o,o),c=J(s,s),l=Ui(2*J(s,o),2*J(s,a),e.rodLen2-c-i,2*Math.sqrt(i*c));if(l.free){let m=Math.abs(e.rodLen2-c-i)<=1e-9*e.rodLen2;return{phi:r,damperLength:Pe(rb(e,r),e.damperChassis),converged:m,margin:0}}let u=sk(Math.atan2(l.s1,l.c1),r),d=sk(Math.atan2(l.s2,l.c2),r),p=Math.abs(d-r)<Math.abs(u-r)?d:u;return{phi:p,damperLength:Pe(rb(e,p),e.damperChassis),converged:l.ok,margin:l.margin}}function sk(e,t){let r=2*Math.PI;return e+r*Math.round((t-e)/r)}function lk(e,t,r,n){return oe(t,Dt(X(re(r),n),H(e,t)))}function uk(e,t,r,n){let o=re(n),a=p=>{let m=H(p,r);return H(m,X(o,J(m,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))),d=J(le(s,i),o)/(c*l);return Math.atan2(d,u)}function mk(e,t,r,n){return oe(t,Dt(X(re(r),n),H(e,t)))}var qu=180/Math.PI,HI=(e,t,r)=>Math.max(t,Math.min(r,e)),dk=[NaN,NaN,NaN];function qi(e){let t=re(e.spinAxis),r=re(H(e.uprightUpper,e.uprightLower)),n=-Math.asin(HI(t[2],-1,1))*qu,o=Math.atan2(t[0],t[1])*qu,a=Math.atan2(-r[0],r[2])*qu,s=Math.atan2(-r[1],r[2])*qu,i=re(oe([0,0,-1],X(t,t[2]))),c=oe(e.wheelCenter,X(i,e.loadedRadius)),l=e.patchShift?[c[0]+e.patchShift.x,c[1]+e.patchShift.y,c[2]]:c,u=e.uprightLower,d=Math.abs(r[2])>1e-9,p=w=>oe(u,X(r,(w-u[2])/r[2])),m=d?p(l[2]):dk,f=d?p(e.wheelCenter[2]):dk,h=l[1]-m[1],b=m[0]-l[0],g=re(le(t,[0,0,1])),y=le([0,0,1],g),x=H(l,m),v=J(x,y),k=-J(x,g),R=e.wheelCenter[1]-f[1],M=f[0]-e.wheelCenter[0],S=Xv(e.tieOuter,u,r);return{camber:n,toe:o,caster:a,kpi:s,scrubRadius:h,mechanicalTrail:b,scrubAtWheel:v,trailAtWheel:k,kingpinOffset:R,casterOffset:M,steeringArm:S,contactPatch:l,kingpinGround:m,kingpinAtHub:f}}function wt(e){return{corner:e,inv:Zh(e),rocker:ik(e.hardpoints)}}var zI=[20,20,20,.2,.2,.2];function fk(e,t,r,n=[0,0,0,0,0,0]){let o=ak(e,t,r,n);if(!o.free)return o;let a=YI(e,t,r,n);return{x:a.x,converged:a.converged,margin:0}}function YI(e,t,r,n=[0,0,0,0,0,0]){return ek(o=>eb(e,o,t,r),n,{scales:zI,tol:1e-10,maxIter:40})}var WI=.01,Qu=1.2,Ht=e=>e.ok?e.state:null,Et=e=>e.ok?e.state:e.nearest;function Ae(e,t,r,n,o){let a=0,s=tt(e,a,r,n,o);if(Math.abs(s.travel-t)<1e-4)return pk(s,t,!1);let c=(tt(e,.02,r,nb(s),o).travel-s.travel)/.02;(!Number.isFinite(c)||Math.abs(c)<1e-6)&&(c=1);let l=p=>Math.max(-Qu,Math.min(Qu,p)),u=l((t-s.travel)/c),d=tt(e,u,r,nb(s),o);for(let p=0;p<12&&!(Math.abs(d.travel-t)<1e-4);p++){let m=d.travel-s.travel,f=Math.abs(m)<1e-9?u:u-(d.travel-t)*((u-a)/m);a=u,s=d,u=l(f),d=tt(e,u,r,nb(s),o)}return pk(d,t,Math.abs(u)===Qu)}function pk(e,t,r){let n=e.travel-t,o=Math.abs(n)<=WI,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 nb(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 jI(e,t,r,n,o){switch(e){case"upright":return Rr(t,r,o.pushrodOuter);case"upperArm":{let a=Rr(t,r,t.ubj0),s=uk(t.ubj0,a,t.ucaFront,t.ucaDir);return mk(o.pushrodOuter,t.ucaFront,t.ucaDir,s)}default:return lk(o.pushrodOuter,t.lcaFront,t.lcaDir,n)}}function tt(e,t,r,n,o){let{inv:a,corner:s}=e,i=n?.q??[0,0,0,0,0,0],c=fk(a,t,r,i),l=c.x,u=[l[3],l[4],l[5]],d={t:[l[0],l[1],l[2]],omega:u},p=s.hardpoints,m=s.config,f=a.strut,h=f?f.top:Rr(a,l,p.uprightUpper),b=Rr(a,l,p.uprightLower),g=Rr(a,l,p.tieOuter),y=Rr(a,l,p.wheelCenter),x=re(Dt(u,m.spinAxis)),v=jI(f?"upright":m.pushrodAttach,a,l,t,p),k=f?f.top:p.damperChassis,R=f||m.actuation==="direct"?{phi:0,damperLength:Pe(v,k),converged:!0,margin:1}:ck(e.rocker,v,n?.phi??0),M=qi({uprightUpper:h,uprightLower:b,wheelCenter:y,spinAxis:x,tieOuter:g,loadedRadius:o?.loadedRadius??m.loadedRadius,patchShift:o?.patchShift});return{pose:d,beta:t,travel:l[2],steer:r,points:{uprightUpper:h,uprightLower:b,tieOuter:g,wheelCenter:y,pushrodOuter:v,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 fs=e=>e==="FL"||e==="FR"?"front":"rear",bk=e=>e==="FL"||e==="RL"?"left":"right";function qe(e,t){return e.corners?.[t]??UI(e[fs(t)],bk(t))}function gk(e){let t=e.config.springSplit;return e.config.actuation==="decoupled"||t===void 0||!Number.isFinite(t)||Math.abs(t)>=1?0:t}var hk=new WeakMap;function UI(e,t){let r=gk(e);if(r===0)return e;let n=hk.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)},hk.set(e,n)}return n[t]}var Zr=["FL","FR","RL","RR"],qt=e=>2*e.hardpoints.wheelCenter[1],ir=(e,t)=>t?qt(qe(e,"FL"))/2+qt(qe(e,"FR"))/2:qt(qe(e,"RL"))/2+qt(qe(e,"RR"))/2;function ze(e,t){let r=e==="FL"||e==="FR";return{axleX:r?t.frontAxleX:t.frontAxleX-t.wheelbase,sideSign:e==="FR"||e==="RR"?1:-1,isFront:r}}function rt(e,t){return[t.axleX+e[0],t.sideSign*e[1],e[2]]}function Tn(e,t){return[e[0],t.sideSign*e[1],e[2]]}function fo(e){return e.frontAxleX-e.wheelbase/2}function ob(e,t,r){return t[2]+e.heave+(t[0]-r)*Math.sin(e.pitch)-t[1]*Math.sin(e.roll)}function ho(e,t,r,n){let o=ze(e,t),a=(n?ir(n,o.isFront):o.isFront?t.trackFront:t.trackRear)/2,s=o.sideSign*a,i=o.axleX-fo(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 XI={travelMin:-40,travelMax:40,steps:41,steer:0};function Qi(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 ct(e,t={}){let r={...XI,...t},n=wt(e);return hs(n,r)}function hs(e,t){let r=t.steer,n=.01,o=tt(e,n,r),a=tt(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=[],d=tt(e,0,r);u.push({beta:0,travel:d.travel,warm:Qi(d),converged:d.converged});let p=Qi(d);for(let x=1;x<=l;x++){let v=c*x/l,k=tt(e,v,r,p);p=Qi(k),u.push({beta:v,travel:k.travel,warm:p,converged:k.converged})}p=Qi(d);for(let x=1;x<=l;x++){let v=-c*x/l,k=tt(e,v,r,p);p=Qi(k),u.push({beta:v,travel:k.travel,warm:p,converged:k.converged})}u.sort((x,v)=>x.beta-v.beta);let m=u[u.length-1].travel>=u[0].travel,f=!1;for(let x=1;x<u.length;x++){let v=u[x].travel-u[x-1].travel;(m&&v<-1e-6||!m&&v>1e-6)&&(f=!0)}let h=u.filter(x=>x.converged).map(x=>x.travel),b=h.length?[Math.min(...h),Math.max(...h)]:[0,0],g=h.length>0&&b[0]<=t.travelMin+1e-6&&b[1]>=t.travelMax-1e-6,y=[];for(let x=0;x<t.steps;x++){let v=t.steps===1?t.travelMin:t.travelMin+(t.travelMax-t.travelMin)*x/(t.steps-1),k=qI(u,v,m),R=QI(u,k);y.push(tt(e,k,r,R))}return ZI(y,e.corner.config.actuation==="decoupled"?0:e.corner.config.springRate),{samples:y,covered:g,reach:b,fold:f,unconverged:y.filter(x=>!x.converged).length}}function qI(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 QI(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 ab(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 ZI(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=ab(n,r,s),c=ab(o,r,s),l=-ab(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 Zu=e=>e!==void 0&&Number.isFinite(e)&&e>0;function JI(e){return e&&Zu(e.helperRate)&&Zu(e.helperTravel)?{rate:e.helperRate,travel:e.helperTravel}:null}function sb(e,t,r){let n=t/e;return r?n+Math.min(t/r.rate,r.travel):n}function Zi(e,t,r,n){if(!(e>0)||!Number.isFinite(e)||!(t>0)||!Number.isFinite(t))return null;let o=JI(n),a=-sb(e,t,o),s=bs(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 bs(e,t){if(!Number.isFinite(e))return{droop:null,bump:null};let r=Zu(t?.extended)&&t.extended>e?t.extended:null,n=r!==null&&Zu(t?.stroke)?r-t.stroke:null;return{droop:r!==null?e-r:null,bump:n!==null&&n<e?e-n:null}}function ib(e,t){if(!(e>0)||!Number.isFinite(e))return null;let r=bs(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 e2(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=sb(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 t2(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=sb(r,n,o)+t;return a<=0?0:a>=o.rate*o.travel/r+o.travel?r:r*o.rate/(r+o.rate)}function gs(e,t){let r=e2(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 cb(e,t){let r=t2(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 lb(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 Ju={min:-60,max:60,steps:61},ub=e=>({travel:[e.min,e.max],force:[0,0],motionRatio:[0,0],spring:null}),yk=new WeakMap;function r2(e,t){let r=yk.get(e.corner);r||yk.set(e.corner,r=new Map);let n=`${t.min}|${t.max}|${t.steps}`,o=r.get(n);return o||r.set(n,o=hs(e,{travelMin:t.min,travelMax:t.max,steps:t.steps,steer:0})),o}function ec(e,t,r=Ju,n=e.corner.config.coilover){let o=e.corner.config;if(o.actuation==="decoupled")return ub(r);let a=r2(e,r),s=o2(e,o.springRate,a.samples),i=[];for(let h of a.samples){let b=h.metrics.motionRatio;!h.converged||b===void 0||!Number.isFinite(b)||!Number.isFinite(h.metrics.damperLength)||i.length>0&&h.travel<=i[i.length-1].t+1e-6||i.push({t:h.travel,L:h.metrics.damperLength,mr:b})}if(i.length<2)return ub(r);let c=s2(i,0);if(!(Math.abs(c.mr)>1e-6))return ub(r);let l=t/c.mr,u=Zi(s,l,c.L,n),d=u?n2(i,lb(u).map(h=>c.L-h)):i,p=d.map(h=>(u?gs(u,c.L-h.L):l+s*(c.L-h.L))*h.mr-t),m=h=>h===null?null:d.find(b=>b.L===c.L-h)?.t??null,f=u?lb(u).map(m).filter(h=>h!==null):[];return{travel:d.map(h=>h.t),force:p,motionRatio:d.map(h=>h.mr),spring:{rate:s,preload:l,length0:c.L,law:u},...u?{stops:{droop:m(u.droop),bump:m(u.bump)}}:{},...f.length?{kinks:f}:{},length:d.map(h=>h.L)}}function mb(e,t){if(!e.spring)return null;let r=e.travel.length,n=e.length;if(n&&n.length===r&&r>=2){let s=Jr(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+=(Ji(e,i)+Ji(e,c))/2*(c-i)}return a}function n2(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 o2(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:a2(e,n,r);return!(o>0)||!Number.isFinite(o)?t:t*o/(t+o)}function a2(e,t,r){let n;for(let d of r)d.converged&&(!n||Math.abs(d.travel)<Math.abs(n.travel))&&(n=d);if(!n)return t;let o=e.corner.hardpoints,a=ps(e.rocker,n.points.rockerAngle),s=re(H(o.rockerPivotB,o.rockerPivotA)),i=(d,p)=>Math.abs(J(s,le(H(d,o.rockerPivotA),re(H(p,d))))),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 Ji(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.motionRatio[0];let n=Jr(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 Pn(e,t,r){if(!e.spring)return Nr(e,t);let{rate:n,preload:o,length0:a,law:s}=e.spring,i=Ji(e,0),c=a-r;return(s?gs(s,c):o+n*c)*Ji(e,t)-o*i}function s2(e,t){let r=Jr(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 Jr(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 Nr(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.force[0];let n=Jr(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 ys(e,t){let r=e.travel.length;if(r<3)return tc(e,t);let n=Jr(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 tc(e,t){if(e.travel.length<2)return 0;let n=Jr(e.travel,t);return(e.force[n+1]-e.force[n])/(e.travel[n+1]-e.travel[n])}function Ye(e,t,r){let n=e.hardpoints;switch(t.attach){case"upright":{let o=H(t.outer,n.wheelCenter);return oe(oe(Dt(r.pose.omega,o),n.wheelCenter),r.pose.t)}case"lowerArm":{let o=re(H(n.lcaRear,n.lcaFront));return oe(n.lcaFront,Dt(X(o,r.beta),H(t.outer,n.lcaFront)))}case"rocker":{let o=re(H(n.rockerPivotB,n.rockerPivotA));return oe(n.rockerPivotA,sr(H(t.outer,n.rockerPivotA),o,r.points.rockerAngle))}}}function en(e,t,r){return e.config.actuation==="decoupled"&&t.attach==="rocker"&&r==="coil"}function db(e,t,r){return en(e,t,r)?[t.inner[0],-t.inner[1],t.inner[2]]:t.inner}function xs(e,t,r){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return pb(e,t,r.kind,ct(e,{travelMin:n,travelMax:o,steps:a}).samples)}function pb(e,t,r,n){let o=re(H(t.outer,db(e,t,r))),a=[],s=[],i=t.outer;for(let m of n)a.push(m.travel),s.push(J(H(Ye(e,t,m),i),o));let c=a.length,l=new Array(c).fill(0);for(let m=0;m<c;m++){let f=Math.max(0,m-1),h=Math.min(c-1,m+1),b=a[h]-a[f];l[m]=b!==0?(s[h]-s[f])/b:0}let u=l[0];for(let m=1;m<c;m++)if(a[m]>=0){let f=a[m]-a[m-1],h=f!==0?(0-a[m-1])/f:0;u=l[m-1]+h*(l[m]-l[m-1]);break}let d=l.filter(m=>Math.abs(m)>1e-9).map(Math.sign),p=d.length>0&&d.some(m=>m!==d[0]);return{travel:a,ratio:l,linkTravel:s,atDesign:u,reverses:p}}function fb(e,t){let{travel:r,ratio:n}=e,o=r.length;if(o===0)return 0;if(t<=r[0])return n[0];if(t>=r[o-1])return n[o-1];let a=0,s=o-1;for(;s-a>1;){let c=a+s>>1;r[c]<=t?a=c:s=c}let i=(t-r[a])/(r[s]-r[a]);return n[a]+i*(n[s]-n[a])}function hb(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 Ho=e=>e.mount??{kind:"rockerToRocker"},kk=e=>[e[0],0,e[2]],i2=e=>2*Math.abs(e[1]),c2=(e,t)=>Math.hypot(e[0]-t[0],e[2]-t[2]);function tm(e,t){return t.kind==="chassis"?c2(e,t.anchor):i2(e)}function rc(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 zo(e,t,r={}){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return bb(e,t,ct(e,{travelMin:n,travelMax:o,steps:a}).samples)}function bb(e,t,r){let n=Ho(t),o=f=>Ye(e,{...t,inner:t.outer},r[f]),a=[],s=[],i=[];for(let f=0;f<r.length;f++)a.push(r[f].travel),i.push(tm(o(f),n));let c=Rk(a,i,0);for(let f of i)s.push(c-f);let l=a.length,u=new Array(l).fill(0);for(let f=0;f<l;f++){let h=Math.max(0,f-1),b=Math.min(l-1,f+1),g=a[b]-a[h];u[f]=g!==0?(s[b]-s[h])/g:0}let d=xk(a,20),p=xk(a,-20),m=rc(o(d),o(p),n);return{travel:a,ratio:u,springTravel:s,atDesign:Rk(a,u,0),installedLength:c,rollSensitivity:c-m}}function xk(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 Rk(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 gb(e,t,r){let n={outer:t.outer,attach:t.attach},o=ct(e,{travelMin:-5,travelMax:5,steps:3}),a=f=>kk(Ye(e,{...n,inner:n.outer},o.samples[f])),s=a(1),i=a(2),c=a(0),l=i[0]-c[0],u=i[2]-c[2],d=Math.hypot(l,u),p=d>1e-9?[l/d,u/d]:[0,1],m=r??Math.max(80,2*Math.abs(t.outer[1])*.5);return[s[0]+p[0]*m,0,s[2]+p[1]*m]}function yb(e,t){let r=e.hardpoints,n=r.rockerPivotA,o=vk(em(r.rockerPivotB,r.rockerPivotA)),a=Math.max(30,.6*Mk(em(r.rockerToDamper,n))),s=em(r.rockerToDamper,n),i=vk(em(s,l2(o,u2(s,o)))),c=m2(o,i),l=null,u=-1/0;for(let d=0;d<360;d+=10){let p=d*Math.PI/180,f={outer:[n[0]+a*(Math.cos(p)*i[0]+Math.sin(p)*c[0]),n[1]+a*(Math.cos(p)*i[1]+Math.sin(p)*c[1]),n[2]+a*(Math.cos(p)*i[2]+Math.sin(p)*c[2])],attach:"rocker"},h=t==="chassis"?{...f,mount:{kind:"chassis",anchor:gb(e,f)}}:f,b;try{b=zo(e,h,{travelMin:-20,travelMax:20,steps:9})}catch{continue}let g=b.atDesign/(1+4*Math.abs(b.rollSensitivity));Number.isFinite(g)&&g>u&&(u=g,l=h)}return l??{outer:r.rockerToDamper,attach:"rocker"}}var em=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],l2=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],u2=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Mk=e=>Math.hypot(e[0],e[1],e[2]),vk=e=>{let t=Mk(e)||1;return[e[0]/t,e[1]/t,e[2]/t]},m2=(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 xb=.001,d2=e=>({outer:e.outer,inner:e.outer,attach:e.attach}),Lk=(e,t,r)=>(tm(e.at0,t)-tm(r,t))/2,p2=(e,t)=>J(H(t,e.pickup.at0),e.axis);function Rb(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 Sk(e,t){let r=[0,1,2].map(n=>Rb(e,t.map(o=>o[n])));return t.map((n,o)=>[r[0][o],r[1][o],r[2][o]])}function vb(e){return{travel:e,heave:e.map(t=>t/2),heaveRatio:e.map(()=>.5),roll:[...e],rollRatio:e.map(()=>1)}}function Ak(e,t,r,n){let o=e.corner;if(!t.heave&&!t.roll)return{side:vb([n.min,n.max]),pickups:{}};let a=Et(Ae(e,0,0)),s={};if(t.heave&&r){let h=d2(t.heave);s.heave={corner:o,link:h,at0:Ye(o,h,a)}}if(t.roll){let h=t.roll;s.roll={pickup:{corner:o,link:h,at0:Ye(o,h,a)},axis:re(H(h.outer,db(o,h,t.rollKind??"coil")))}}let i=t.roll&&en(o,t.roll,t.rollKind??"coil")?{near:t.roll,far:{...t.roll,outer:t.roll.inner}}:null,c=hs(e,{travelMin:n.min,travelMax:n.max,steps:n.steps,steer:0}),l=[],u=[],d=[],p=[],m=[];for(let h of c.samples)!h.converged||l.length>0&&h.travel<=l[l.length-1]+1e-6||(l.push(h.travel),u.push(s.heave&&r?Lk(s.heave,r,Ye(o,s.heave.link,h)):h.travel/2),d.push(s.roll?p2(s.roll,Ye(o,s.roll.pickup.link,h)):h.travel),i&&(p.push(Ye(o,i.near,h)),m.push(Ye(o,i.far,h))));if(l.length<2)return{side:vb([n.min,n.max]),pickups:{}};let f={travel:l,heave:u,heaveRatio:Rb(l,u),roll:d,rollRatio:Rb(l,d)};return i&&(f.eyes={near:p,nearRatio:Sk(l,p),far:m,farRatio:Sk(l,m)}),{side:f,pickups:s}}function rm(e,t,r){let n=Jr(e,r);return t[n]+(r-e[n])/(e[n+1]-e[n])*(t[n+1]-t[n])}function wk(e,t,r){let n=Jr(e,r);return(t[n+1]-t[n])/(e[n+1]-e[n])}function nt(e,t){return{h:rm(e.travel,e.heave,t),dh:rm(e.travel,e.heaveRatio,t),ddh:wk(e.travel,e.heaveRatio,t),r:rm(e.travel,e.roll,t),dr:rm(e.travel,e.rollRatio,t),ddr:wk(e.travel,e.rollRatio,t)}}function Ck(e,t,r,n){let o=Jr(e,n),a=e[o+1]-e[o],s=(n-e[o])/a,i=(u,d)=>[u[0]+s*(d[0]-u[0]),u[1]+s*(d[1]-u[1]),u[2]+s*(d[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 kb=(e,t)=>Math.hypot(e[0]-t[0],e[1]+t[1],e[2]-t[2]);function Mb(e,t){let r=e.side[0].eyes,n=e.side[1].eyes;if(!r||!n)return null;let o=Ck(e.side[0].travel,r.near,r.nearRatio,t[0]),a=Ck(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]],d=[-a.dd[0],a.dd[1],-a.dd[2]],p=J(c,l),m=J(c,u),f=(J(l,u)-p*m)/i;return{L:i,dL:[p,m],ddL:[[(J(l,l)-p*p)/i+J(c,o.dd),f],[f,(J(u,u)-m*m)/i+J(c,d)]]}}var Dk=(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,f2=(e,t)=>e.bump!==null&&t>e.bump||e.droop!==null&&t<e.droop?e.rate:0;function nc(e,t,r,n,o=0){let a=e.rollStop;if(!a)return r;let s=Mb(e,t);if(!s)return r;let i=Dk(a,a.length0-(n??s.L+o));return i===0?r:[r[0]-i*s.dL[0],r[1]-i*s.dL[1]]}function nm(e,t){let r=vb(e.travel);return t==="heave"?{...e,heave:r.heave,heaveRatio:r.heaveRatio}:{...e,roll:r.roll,rollRatio:r.rollRatio}}var om=(e,t)=>e?e.law?gs(e.law,t):e.preload+e.rate*t:0,Fk=(e,t)=>e?e.law?cb(e.law,t):e.rate:0;function oc(e,t,r,n,o){let a=om(e.heave,n),s=om(e.roll,o);return[a*t.dh+s*t.dr,a*r.dh-s*r.dr]}var Tk=(e,t)=>nt(e[0],t).h+nt(e[1],t).h;function h2(e,t){let r=e.gap>0?Tk(t,e.gap):0;return e.bothWays?{free:r,pull:e.gap>0?Tk(t,-e.gap):0}:{free:r,pull:null}}function b2(e,t,r){let n={...t,outer:t.inner},o=(u,d)=>{let p=Ht(Ae(e[0],u,0)),m=Ht(Ae(e[1],d,0));if(!p||!m)return NaN;let f=Ye(e[0].corner,t,p),h=Ye(e[1].corner,n,m);return Math.hypot(f[0]-h[0],f[1]+h[1],f[2]-h[2])},a=1,s=o(0,0),i=o(-a,a)-o(a,-a),c=nt(r[0],a).r-nt(r[1],-a).r-(nt(r[0],-a).r-nt(r[1],a).r),l=i/c;return Number.isFinite(s)&&s>0&&Number.isFinite(l)&&Math.abs(l)>xb?{length0:s,scale:l}:null}function Ek(e,t,r,n=Ju){let o=r.heave?Ho(r.heave):void 0,a=Ak(e[0],r,o,n),s=e[1].corner===e[0].corner?a:Ak(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,d=u?u.rate:(t[0].heaveRate+t[1].heaveRate)/2,p=(t[0].arbRate+t[1].arbRate)/2,m=i.map(C=>nt(C,0));c&&!(Math.abs(m[0].dh+m[1].dh)>xb)&&(i=[nm(i[0],"heave"),nm(i[1],"heave")],c=!1),l&&!(Math.abs(m[0].dr+m[1].dr)>xb)&&(i=[nm(i[0],"roll"),nm(i[1],"roll")],l=!1),m=i.map(C=>nt(C,0));let f=m[0].dh+m[1].dh,h=m[0].dr+m[1].dr,b=d>0?2*d/(f*f):0,g=p>0?2*p/(h*h):0,y=0,x=0;if(r.carriesLoad){let C=[t[0].springLoad,t[1].springLoad];if(b>0&&g>0){let P=-m[0].dh*m[1].dr-m[1].dh*m[0].dr;Math.abs(P)>1e-12&&(y=(-C[0]*m[1].dr-C[1]*m[0].dr)/P,x=(m[0].dh*C[1]-m[1].dh*C[0])/P)}else b>0?y=(C[0]+C[1])/f:g>0&&(x=(C[0]-C[1])/h)}let v={};if(c&&o){let C=[a.pickups.heave,s.pickups.heave];v.heave={pickups:C,mount:o,span0:rc(C[0].at0,C[1].at0,o)}}let k=v.heave?v.heave.span0:NaN,R=v.heave?r.coilover:void 0,M=r.carriesLoad?Zi(b,y,k,R):u?ib(b,{...h2(u,i),length0:k,coilover:R}):null,S=b>0?{rate:b,preload:y,...M?{law:M}:{}}:null;if(l&&(v.roll={pickups:[a.pickups.roll.pickup,s.pickups.roll.pickup],axes:[a.pickups.roll.axis,s.pickups.roll.axis]},r.roll&&en(e[0].corner,r.roll,r.rollKind??"coil"))){let C=b2(e,r.roll,i);C&&(v.roll.unit=C)}let w=g>0?{rate:g,preload:x}:null,F={side:i,heave:S,roll:w,force0:[0,0],carriesLoad:r.carriesLoad,read:v},T=v.roll?.unit,A=T&&g>0&&i[0].eyes&&i[1].eyes?bs(T.length0,r.rollCoilover):null;return T&&A&&(A.droop!==null||A.bump!==null)&&(F.rollStop={length0:T.length0,rate:1e3*g/(T.scale*T.scale),...A}),F.force0=nc(F,[0,0],oc(F,m[0],m[1],m[0].h+m[1].h,m[0].r-m[1].r)),F}function ac(e,t,r){let n=nt(e.side[0],t[0]),o=nt(e.side[1],t[1]),a=r?nc(e,t,oc(e,n,o,n.h+o.h+r.heave,n.r-o.r+r.roll),void 0,r.unit):nc(e,t,oc(e,n,o,n.h+o.h,n.r-o.r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function Sb(e,t,r){let n=nt(e.side[0],t[0]),o=nt(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=Fk(e.heave,a),c=Fk(e.roll,s),l=om(e.heave,a),u=om(e.roll,s),d=i*n.dh*o.dh-c*n.dr*o.dr,p=[[i*n.dh*n.dh+l*n.ddh+c*n.dr*n.dr+u*n.ddr,d],[d,i*o.dh*o.dh+l*o.ddh+c*o.dr*o.dr-u*o.ddr]],m=e.rollStop,f=m?Mb(e,t):null;if(!m||!f)return p;let h=m.length0-(r?f.L+r.unit:f.L),b=f2(m,h);if(b===0)return p;let g=Dk(m,h),y=(v,k)=>b*f.dL[v]*f.dL[k]-g*f.ddL[v][k],x=d+y(0,1);return[[p[0][0]+y(0,0),x],[x,p[1][1]+y(1,1)]]}function Ab(e,t,r){let n=Sb(e,t);return n[r][0]+n[r][1]}function g2(e,t,r){let n=e.read.heave;if(!n)return nt(e.side[0],t[0]).h+nt(e.side[1],t[1]).h;let[o,a]=n.pickups;return n.span0-rc(Ye(o.corner,o.link,r[0]),Ye(a.corner,a.link,r[1]),n.mount)}function y2(e,t,r){let n=e.read.roll;if(!n)return nt(e.side[0],t[0]).r-nt(e.side[1],t[1]).r;let o=a=>J(H(Ye(n.pickups[a].corner,n.pickups[a].link,r[a]),n.pickups[a].at0),n.axes[a]);return o(0)-o(1)}function x2(e,t){let r=e.read.roll;if(!e.rollStop||!r)return;let[n,o]=r.pickups;return kb(Ye(n.corner,n.link,t[0]),Ye(o.corner,{...o.link,outer:o.link.inner},t[1]))}function sc(e,t,r){let n=nt(e.side[0],t[0]),o=nt(e.side[1],t[1]),a=nc(e,t,oc(e,n,o,g2(e,t,r),y2(e,t,r)),x2(e,r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function wb(e,t,r,n){let o=nt(e.side[0],r),a=nt(e.side[1],r),s=e.read.heave,i=s?.pickups[t],c=s&&i&&n?2*Lk(i,s.mount,Ye(i.corner,i.link,n)):o.h+a.h,l=e.rollStop&&n?e.read.roll?.pickups[t]:void 0,u=l&&n?kb(Ye(l.corner,l.link,n),Ye(l.corner,{...l.link,outer:l.link.inner},n)):void 0;return nc(e,[r,r],oc(e,o,a,c,n?0:o.r-a.r),u)[t]-e.force0[t]}function Cb(e,t,r,n){let o=ys(e,r[n]);return t?.carriesLoad?o+Ab(t,r,n):o}function Ik(e,t){return nt(e.side[0],t[0]).h+nt(e.side[1],t[1]).h}function _k(e,t){return Mb(e,t)?.L??null}var Fb=e=>e==="FR"||e==="RR"?1:0,am=(e,t)=>e.elements?.[t==="FL"||t==="FR"?"front":"rear"]??null;var Nk=e=>Number.isFinite(e)&&e>0?1/e:0;var Ok=(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},R2=(e,t)=>[e[0][0]*t[0]+e[0][1]*t[1],e[1][0]*t[0]+e[1][1]*t[1]],Vk=1e-8,v2=40;function k2(e,t,r,n){return{force:(s,i)=>{if(r){let u=ac(r,s,n);return[Nr(t[0],s[0])+i[0]+u[0],Nr(t[1],s[1])+i[1]+u[1]]}let c=(s[0]+s[1])/2,l=(s[0]-s[1])/2;return[Nr(t[0],s[0])+i[0]+e[0].heaveRate*c+e[0].arbRate*l,Nr(t[1],s[1])+i[1]+e[1].heaveRate*c-e[1].arbRate*l]},stiffness:(s,i=tc)=>{if(r){let c=Sb(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 Rs(e,t,r,n,o,a=[0,0],s=[0,0],i=null,c){let l=[Nk(r[0].tyreRate),Nk(r[1].tyreRate)],u=[r[0].staticLoad,r[1].staticLoad],d=k2(r,n,i,c),p=P=>d.force(P,a),m=d.stiffness([0,0]),f=[l[0]>0?l[0]:1/Math.max(1,Math.abs(m[0][0])),l[1]>0?l[1]:1/Math.max(1,Math.abs(m[1][1]))],h=(P,L)=>{let E=L===1?p(P):d.force(P,[a[0]*L,a[1]*L]),_=[E[0]+s[0]*L,E[1]+s[1]*L],D=[P[0]+t[0]*L+_[0]*l[0]-e[0]*L,P[1]+t[1]*L+_[1]*l[1]-e[1]*L],I=[f[0]*(u[0]+_[0]),f[1]*(u[1]+_[1])],V=[I[0]<D[0],I[1]<D[1]];return{f:_,on:D,off:I,lifted:V,r:[Math.min(D[0],I[0]),Math.min(D[1],I[1])]}},b=(P,L)=>[L[0]?[f[0]*P[0][0],f[0]*P[0][1]]:[1+P[0][0]*l[0],P[0][1]*l[0]],L[1]?[f[1]*P[1][0],f[1]*P[1][1]]:[P[1][0]*l[1],1+P[1][1]*l[1]]],g=P=>Math.max(Math.abs(P[0]),Math.abs(P[1])),y=(P,L)=>{let E=[P[0],P[1]],_=h(E,L),D=!1,I=0;for(;I<v2;I++){if(g(_.r)<Vk){D=!0;break}let V=Ok(b(d.stiffness(E),_.lifted),[-_.r[0],-_.r[1]]);if(!V)break;let O=1,B=[E[0]+V[0],E[1]+V[1]],z=h(B,L);for(let j=0;j<8&&g(z.r)>g(_.r);j++)O/=2,B=[E[0]+O*V[0],E[1]+O*V[1]],z=h(B,L);E=B,_=z}return!D&&g(_.r)<Vk&&(D=!0),{t:E,b:_,converged:D,it:I}},x=y(o?[o[0],o[1]]:[e[0]-t[0],e[1]-t[1]],1),v=x.it;if(!x.converged){let P=0,L=[0,0],E=.25;for(;P<1&&E>=1/256;){let _=Math.min(1,P+E),D=y(L,_);v+=D.it,D.converged?(P=_,L=D.t,_===1&&(x=D)):E/=2}}let{t:k,b:R,converged:M}=x,S=R.lifted,w=[S[0]?-u[0]:R.f[0],S[1]?-u[1]:R.f[1]],F=[S[0]?Math.max(0,R.on[0]):0,S[1]?Math.max(0,R.on[1]):0],T=d.stiffness(k,ys),A=b(T,S);return{t:k,dF:w,lifted:S,clearance:F,converged:M,iterations:v,respond:(P,L,E=[0,0])=>{let _=[S[0]?-f[0]*E[0]:P[0]-L[0]-E[0]*l[0],S[1]?-f[1]*E[1]:P[1]-L[1]-E[1]*l[1]],D=Ok(A,_);if(!D)return[NaN,NaN];let I=R2(T,D);return[S[0]?0:I[0]+E[0],S[1]?0:I[1]+E[1]]}}}var Yo=e=>!(Number.isFinite(e.tyreRate)&&e.tyreRate>0);function vr(e,t,r){return t?.input.corners[r].staticLoadedRadius??e}var Tb=["FL","FR","RL","RR"],Gk={front:["FL","FR"],rear:["RL","RR"]},M2=512,S2=5e-4,A2=8;function sm(e,t){let r={},n={},o=new Map;for(let s of Tb){let i=e.ctx[s],c=t.corners[s],l=c.staticLoadedRadius;n[s]=Et(Ae(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"],d=`${Tb.findIndex(m=>qe(e.vehicle,m)===qe(e.vehicle,s))}|${c.springLoad}|${u?`${u.extended}/${u.stroke}`:""}`,p=o.get(d);p?r[s]=p:(r[s]=u?ec(i,c.springLoad,void 0,u):ec(i,c.springLoad),o.set(d,r[s]))}let a={front:null,rear:null};for(let s of["front","rear"]){let i=t.elements?.[s];if(!i)continue;let c=Gk[s];a[s]=Ek([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 Kk(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 w2=e=>`${e.heave}|${e.pitch}|${e.roll}|${e.steer}`;function Pb(e,t,r){return{travel:r.travel,steer:r.steer,ground:r.travel,tyreDeflection:0,load:NaN,loadedRadius:vr(qe(e.vehicle,t).config.loadedRadius,e.kc,t),lifted:!1,contactLength:0,converged:!0,rigid:!0,rideRate:NaN,wheelRateAtLoad:NaN}}var C2=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 Bk(e,t,r,n){let o=Gk[n],a=e.vehicle.config,s=o.map(w=>ho(w,a,r,e.vehicle)),i=[t.input.corners[o[0]],t.input.corners[o[1]]],c=t.loadCase;if(!c&&i.every(Yo))return{corners:[Pb(e,o[0],s[0]),Pb(e,o[1],s[1])],respond:null};let l=o.map(w=>t.curve[w]),u=t.elements?.[n]??null,d=o.map(w=>vr(qe(e.vehicle,w).config.loadedRadius,t,w)),p=[s[0].travel+(c?.ground[o[0]]??0),s[1].travel+(c?.ground[o[1]]??0)],m=[c?.linkLoad[o[0]]??0,c?.linkLoad[o[1]]??0],f=[c?.patchShift[o[0]],c?.patchShift[o[1]]],h=[0,0],b=[0,0],g,y=Rs(p,h,i,l,void 0,void 0,m,u),x=[void 0,void 0],v=[!0,!0],k=[0,0],R=!1;for(let w=0;w<A2;w++){w>0&&(y=Rs(p,h,i,l,g,b,m,u)),k=[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 F=[0,0],T=[0,0];for(let C=0;C<2;C++){let P=Ae(e.ctx[o[C]],y.t[C],s[C].steer,C2(x[C]),{loadedRadius:d[C]-k[C],patchShift:f[C]}),L=Et(P);x[C]=L,v[C]=P.ok,F[C]=L.points.contactPatch[2]-t.ground0[o[C]]-y.t[C]-k[C],T[C]=Pn(l[C],y.t[C],L.points.damperLength)-Nr(l[C],y.t[C])}if(u){let C=sc(u,y.t,[x[0],x[1]]),P=ac(u,y.t);T[0]+=C[0]-P[0],T[1]+=C[1]-P[1]}let A=Math.max(Math.abs(F[0]-h[0]),Math.abs(F[1]-h[1]),Math.abs(T[0]-b[0])/Math.max(1,i[0].tyreRate),Math.abs(T[1]-b[1])/Math.max(1,i[1].tyreRate));if(h=F,b=T,g=y.t,A<S2){R=!0;break}}let M=y.respond([1,1],[0,0]);return{corners:[0,1].map(w=>{let F=x[w];return{travel:y.t[w],steer:s[w].steer,ground:p[w],tyreDeflection:k[w],load:i[w].staticLoad+y.dF[w],loadedRadius:d[w]-k[w],lifted:y.lifted[w],clearance:y.clearance[w],contactLength:Kk(d[w]-k[w],i[w].staticLoad+y.dF[w],i[w].tyreRate),converged:y.converged&&R&&v[w],rigid:!1,state:F,solved:v[w],rideRate:M[w],wheelRateAtLoad:Cb(l[w],u,y.t,w)}}),respond:y.respond}}function Hk(e,t){let r=e.kc,n=w2(t),o=r.memo.get(n);if(o)return o;let a=Bk(e,r,t,"front"),s=Bk(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>=M2&&r.memo.clear(),r.memo.set(n,i),i}function Qt(e,t){if(!e.kc){let r={};for(let n of Tb)r[n]=Pb(e,n,ho(n,e.vehicle.config,t,e.vehicle));return r}return Hk(e,t).corners}function im(e,t,r){return e.kc?Hk(e,t).respond[r]:null}function ic(e,t,r,n=0){let o=e.kc;if(!o)return r;let a=o.input.corners[t];if(Yo(a))return r;let s=ho(t,e.vehicle.config,{heave:0,pitch:0,roll:0,steer:n},e.vehicle).steer,i=vr(qe(e.vehicle,t).config.loadedRadius,o,t),c=o.loadCase,l=c?.linkLoad[t]??0,u=c?.patchShift[t],d=Et(Ae(e.ctx[t],r,s,void 0,{loadedRadius:i,patchShift:u})),p=am(o,t),m=Pn(o.curve[t],r,d.points.damperLength)+(p?wb(p,Fb(t),r,d):a.heaveRate*r),h=Math.max(m+l,-a.staticLoad)/a.tyreRate;return(h===0?d:Et(Ae(e.ctx[t],r,s,void 0,{loadedRadius:i-h,patchShift:u}))).points.contactPatch[2]-o.ground0[t]-(c?.ground[t]??0)}var F2=180/Math.PI,T2=[0,0,1];function P2(e,t){let r=Tn(e,t),n=X(le(T2,r),-t.sideSign);return-Math.atan2(n[1],n[0])*F2}var zk=e=>1/Math.tan(e*Math.PI/180),Yk=.05,Wk=.001;function jk(e,t,r){if(!Number.isFinite(e)||!Number.isFinite(t))return NaN;if(!(Math.abs(e)<Wk&&Math.abs(t)<Wk))return e>0&&t>0?100*(zk(t)-zk(e))/r:NaN}function L2(e,t){let r=ir(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=[Yk,-Yk].map(l=>{let{inner:u,outer:d}=a(t("FL",l).deg-n,t("FR",l).deg-o);return jk(u,d,r)??NaN});s=(c[0]+c[1])/2}return s};return c=>{let l=t("FL",c),u=t("FR",c),{left:d,inner:p,outer:m}=a(l.deg-n,u.deg-o),f=jk(p,m,r);return{steerL:l.deg,steerR:u.deg,inner:p,outer:m,toeDiff:p-m,ackermannPct:f??i(),inside:f===void 0?null:d?"left":"right",converged:l.ok&&u.ok}}}function Lb(e,t){let r=e.vehicle.config,n={FL:ze("FL",r),FR:ze("FR",r)},o=t.travel??0,a=L2(e,(i,c)=>{let l=Ht(Ae(e.ctx[i],o,n[i].sideSign*c));return{deg:l?P2(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 Uk=35,Xk=55,It=e=>e.rackTravel&&e.rackTravel>0?e.rackTravel:Uk,Db=e=>e.rackRatio&&e.rackRatio>0?e.rackRatio:Xk;var Eb=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 qk(e,t,r,n,o){let a=Ae(e,n,0,void 0,o),s=Et(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=m=>{let f=[l],h=Eb(s);for(let b=1;b<=r;b++){let g=m*(t*b)/r,y=tt(e,s.beta,g,h,o),x=Ht(Ae(e,n,g,Eb(y),o));if(!x||!y.converged){i++,f.push({...f[f.length-1]});continue}f.push({steer:x.metrics.toe,camber:x.metrics.camber,lift:-(y.points.contactPatch[2]-c),contactPatch:y.points.contactPatch,spinAxis:y.points.spinAxis,yaw:-y.metrics.toe*Math.PI/180}),h=Eb(y)}return f},d=u(1),p=u(-1);return{travelMm:n,unsolved:i,centre:l,positive:d,negative:p}}function D2(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=X(H(e[a].contactPatch,e[o].contactPatch),1/s),c=re(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 Qk(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:D2(o,t)});return{travelMm:e.travelMm,inner:n(r?e.positive:e.negative),outer:n(r?e.negative:e.positive)}}function E2(e){return e.positive[1].steer-e.centre.steer<0}function I2(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:Db(e.config),innerJacobian:r.inner.jacobian,outerJacobian:r.outer.jacobian}}function Ib(e,t,r=13,n=-40,o=40,a=5,s){let i=wt(e),c=Array.from({length:r+1},(b,g)=>t*g/r),l=qk(i,t,r,0,s),u=E2(l),d=Qk(l,c,u),p=Math.max(2,Math.floor(a)),m=Array.from({length:p},(b,g)=>n+(o-n)*g/(p-1));m.some(b=>Math.abs(b)<1e-9)||m.push(0),m.sort((b,g)=>b-g);let f=l.unsolved,h=m.map(b=>{if(Math.abs(b)<1e-9)return d;let g=qk(i,t,r,b,s);return f+=g.unsolved,Qk(g,c,u)});return{...I2(e,c,d),...Zk(l.unsolved),travelSurface:{rackMm:c,rows:h,...Zk(f)}}}var Zk=e=>e>0?{unsolved:e}:{};function tn(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 cm(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 Jk(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 Wo=(e,t,r)=>e+r*(t-e);function vs(e,t,r,n,o){let a=tn(e.rackMm,e.rows[n.lo][t][r],o);if(n.lo===n.hi)return a;let s=tn(e.rackMm,e.rows[n.hi][t][r],o);return Wo(a,s,n.t)}function eM(e,t,r,n){let o=cm(e.rackMm,e.rows[r.lo][t].jacobian,n);if(r.lo===r.hi)return o;let a=cm(e.rackMm,e.rows[r.hi][t].jacobian,n);return{longitudinal:Wo(o.longitudinal,a.longitudinal,r.t),lateral:Wo(o.lateral,a.lateral,r.t),vertical:Wo(o.vertical,a.vertical,r.t),yaw:Wo(o.yaw,a.yaw,r.t)}}function ks(e,t,r,n){let o=e.travelSurface;if(!o||o.rackMm.length<2||o.rows.length===0)return Ms(e,t);let a=Jk(o,r),s=Jk(o,n),i=(m,f,h)=>{let b=o.rows[f.lo][m].steerDeg[h];return f.lo===f.hi?b:Wo(b,o.rows[f.hi][m].steerDeg[h],f.t)},c=new Array(o.rackMm.length);for(let m=0;m<c.length;m++)c[m]=.5*(i("inner",a,m)+i("outer",s,m));let l=Math.max(0,t),u=c.length-1,d=o.rackMm[u],p=l>c[u];if(l<=c[0])d=o.rackMm[0],p=!1;else if(!p){let m=1;for(;m<c.length-1&&c[m]<l;)m++;let f=m-1,h=c[m]-c[f],b=Math.abs(h)>1e-12?(l-c[f])/h:0;d=Wo(o.rackMm[f],o.rackMm[m],b)}return{innerDeg:vs(o,"inner","steerDeg",a,d),outerDeg:vs(o,"outer","steerDeg",s,d),innerCamber:vs(o,"inner","camberDeg",a,d),outerCamber:vs(o,"outer","camberDeg",s,d),innerLift:vs(o,"inner","liftMm",a,d),outerLift:vs(o,"outer","liftMm",s,d),innerJacobian:eM(o,"inner",a,d),outerJacobian:eM(o,"outer",s,d),atLock:p}}function Ms(e,t){let r=e.meanDeg.length-1;return{innerDeg:tn(e.meanDeg,e.innerDeg,t),outerDeg:tn(e.meanDeg,e.outerDeg,t),innerCamber:tn(e.meanDeg,e.innerCamber,t),outerCamber:tn(e.meanDeg,e.outerCamber,t),innerLift:e.innerLift?tn(e.meanDeg,e.innerLift,t):0,outerLift:e.outerLift?tn(e.meanDeg,e.outerLift,t):0,...e.innerJacobian&&e.outerJacobian?{innerJacobian:cm(e.meanDeg,e.innerJacobian,t),outerJacobian:cm(e.meanDeg,e.outerJacobian,t)}:{},atLock:r>=0&&t>e.meanDeg[r]}}var _2=()=>({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 Ss(e,t,r=Ge(e),n){let o=e.steerFront;if(!o?.innerLift||!o.outerLift||o.meanDeg.length<2||Math.abs(t)<1e-12)return _2();let a=Math.abs(t),s=t>0,i=n&&o.travelSurface?ks(o,a,s?n.FL:n.FR,s?n.FR:n.FL):null,c=i?.innerLift??tn(o.meanDeg,o.innerLift,a),l=i?.outerLift??tn(o.meanDeg,o.outerLift,a),u=s?c:l,d=s?l:c,p=.5*(u+d),m=r.rollWheelRateFront,f=r.rollWheelRateRear,h=e.trackFront,b=e.trackRear,g=m*h*h+f*b*b,y=N2(e,m,f,h,b);if(y){let k=(d-u)/h,R=k/(1/y.front+1/y.rear+1/y.chassis),M=k-R/y.front,S=R/y.rear,w={FL:u-p+.5*h*M,FR:d-p-.5*h*M,RL:.5*b*S,RR:-.5*b*S},F=Math.max(0,Math.min(1,e.frontMassFrac)),T=A=>-Math.atan(A)*180/Math.PI;return{lift:{FL:u,FR:d,RL:0,RR:0},travel:w,load:{FL:m*w.FL,FR:m*w.FR,RL:f*w.RL,RR:f*w.RR},rollDeg:T(F*M+(1-F)*S),ends:{front:T(M),rear:T(S)}}}let x=g>0?m*h*(d-u)/g:0,v={FL:u-p+.5*h*x,FR:d-p-.5*h*x,RL:.5*b*x,RR:-.5*b*x};return{lift:{FL:u,FR:d,RL:0,RR:0},travel:v,load:{FL:m*v.FL,FR:m*v.FR,RL:f*v.RL,RR:f*v.RR},rollDeg:x===0?0:-Math.atan(x)*180/Math.PI}}function N2(e,t,r,n,o){let a=e.chassisTorsion??0,s=.5*t*n*n,i=.5*r*o*o;return!(a>0)||!Number.isFinite(a)||!(s>0)||!(i>0)?null:{front:s,rear:i,chassis:a*1e3*180/Math.PI}}function _b(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 cc=9.81;function As(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?Cn(e,t,r,po(e,n,o)):Go(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 Nb(e,t,r=0,n=0,o=0){if(!e.aero?.model||t<=0)return!1;let a=Cn(e,t,r,po(e,n,o));return a!=null&&(a.clampedRide||a.clampedAttitude)}function jo(e){let t=e.loadFactor===void 0?e.massTotal*cc:e.massTotal*cc*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 tM(e,t=Ge(e),r=e.cgHeight){let n=e.trackFront/1e3,o=e.trackRear/1e3,a=e.rcHeightFront/1e3,s=e.rcHeightRear/1e3,i=(e.rcHeightFront+(e.rcHeightRear-e.rcHeightFront)*(1-e.frontMassFrac))/1e3,c=r/1e3-i,l=2*e.unsprungPerCorner,u=e.unsprungCgHeight/1e3,d=t.sprungMass*c*Bu(t.sprungMass,c,t.rollRateTotal),p=(d*t.frontElasticShare+t.sprungFront*a+l*u)/n,m=(d*(1-t.frontElasticShare)+t.sprungRear*s+l*u)/o;return{cf:p,cr:m}}function lc(e){let{cf:t,cr:r}=tM(e);return t+r>0?t/(t+r):.5}var rM=e=>1-e.frontMassFrac;function nM(e,t,r,n=e.cgHeight){return n-(t+(r-t)*rM(e))}function oM(e,t){if(!Number.isFinite(t.rcFront)||!Number.isFinite(t.rcRear)||!Number.isFinite(t.arm))return NaN;let r=t.arm+t.rcFront+(t.rcRear-t.rcFront)*rM(e);return lc({...e,rcHeightFront:t.rcFront,rcHeightRear:t.rcRear,cgHeight:r})}function aM(e,t,r){if(e.FL>=0&&e.FR>=0&&e.RL>=0&&e.RR>=0)return{loads:{FL:Math.max(0,e.FL),FR:Math.max(0,e.FR),RL:Math.max(0,e.RL),RR:Math.max(0,e.RR)},lifted:{FL:!1,FR:!1,RL:!1,RR:!1},overturned:!1};let n=e.FL+e.FR+e.RL+e.RR;if(!(n>0))return{loads:{FL:0,FR:0,RL:0,RR:0},lifted:{FL:!0,FR:!0,RL:!0,RR:!0},overturned:!0};let o=!1,a=e.FL+e.FR,s=e.RL+e.RR;a<0?(a=0,s=n,o=!0):s<0&&(s=0,a=n,o=!0);let i=(e.FR-e.FL)*t+(e.RR-e.RL)*r,c=Math.min(a,Math.max(-a,e.FR-e.FL)),l=Math.min(s,Math.max(-s,e.RR-e.RL)),u=i-(c*t+l*r);if(u!==0){let p=u>0?1:-1,m=(p*a-c)*t;p*u>=p*m?(c=p*a,u-=m):(c+=u/t,u=0);let f=(p*s-l)*r;u!==0&&(p*u>=p*f?(l=p*s,u-=f):(l+=u/r,u=0)),Math.abs(u)>1e-9*(Math.abs(i)+n*(t+r))&&(o=!0)}let d={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:d,lifted:{FL:d.FL===0,FR:d.FR===0,RL:d.RL===0,RR:d.RR===0},overturned:o}}function We(e,t,r,n=0,o=0,a=0,s,i){return lm(e,t,r,n,o,a,s,i).loads}function lm(e,t,r,n=0,o=0,a=0,s,i){let c=jo(e),l=Ge(e),u=ju(e,n,r,po(e,t,o),l),{cf:d,cr:p}=tM(e,l,u.height),m=d*t*cc,f=p*t*cc,h=e.massTotal*(r*cc)*u.height/e.wheelbase-u.noseLoad,b=As(e,n,r,t,o),g=(i??Ss(e,a,l,s)).load,y={FL:c.FL-m-h/2+b.FL+g.FL,FR:c.FR+m-h/2+b.FR+g.FR,RL:c.RL-f+h/2+b.RL+g.RL,RR:c.RR+f+h/2+b.RR+g.RR};return aM(y,e.trackFront,e.trackRear)}var Ob=Math.PI/180;function mm(e,t){let r=8*Ob,n=0,o=0;for(let a=1;a<=90;a++){let s=a*.5,i=Math.abs(e.Fy(s*Ob,t,0));if(i>n&&(n=i,r=s*Ob,o=a),a>o+12&&i<.995*n)break}return{aPeak:r,fyPeak:n}}function sM(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 mc=.999;function cr(e,t,r,n,o){if(t<=0)return 0;let{aPeak:a,fyPeak:s}=o??mm(e,t),i=Math.min(Math.abs(r),mc*s),c=n?-1:1,l=(k,R)=>Math.abs(e.forces({Fz:t,kappa:c*k,alpha:R}).Fy),u=.3,d=u,p=l(u,a);if(p<i){let k=0,R=u,M=NaN,S=p;for(let w=0;w<9;w++){let F=.5*(k+R),T=l(F,a);T>=i?(k=F,M=T):(R=F,S=T)}Number.isNaN(M)&&(M=l(0,a)),d=M<i?0:sM(k,M,R,S,i)}if(d<=0)return 0;let m=k=>{if(i===0)return c*e.forces({Fz:t,kappa:c*k,alpha:0}).Fx;let R=0,M=a,S=NaN,w=NaN;for(let F=0;F<5;F++){let T=.5*(R+M),A=l(k,T);A<i?(R=T,S=A):(M=T,w=A)}return Number.isNaN(S)&&(S=l(k,0)),Number.isNaN(w)&&(w=l(k,a)),c*e.forces({Fz:t,kappa:c*k,alpha:sM(R,S,M,w,i)}).Fx},f=4,h=k=>d*k/f,b=[0],g=1;for(let k=1;k<=f;k++)b.push(m(h(k))),b[k]>b[g]&&(g=k);let[y,x]=g===f?[f-1,f-2]:b[g-1]>=b[g+1]?[g-1,g+1]:[g+1,g-1],v=$2(m,h(g-1),h(Math.min(f,g+1)),h(g),b[g],h(y),b[y],h(x),b[x],O2);return c*Math.max(0,v)}var O2=.01,V2=20,B2=(3-Math.sqrt(5))/2;function $2(e,t,r,n,o,a,s,i,c,l){o=-o,s=-s,c=-c;let u=r-t,d=0;for(let p=0;p<V2;p++){let m=l*Math.abs(n)+1e-10,f=.5*(t+r);if(Math.abs(n-f)<=2*m-.5*(r-t))break;let h=!0;if(Math.abs(u)>m){let y=(n-a)*(o-c),x=(n-i)*(o-s),v=(n-i)*x-(n-a)*y;x=2*(x-y),x>0&&(v=-v),x=Math.abs(x);let k=u;if(u=d,Math.abs(v)<Math.abs(.5*x*k)&&v>x*(t-n)&&v<x*(r-n)){d=v/x;let R=n+d;(R-t<2*m||r-R<2*m)&&(d=f>=n?m:-m),h=!1}}h&&(u=n>=f?t-n:r-n,d=B2*u);let b=Math.abs(d)>=m?n+d:n+(d>=0?m:-m),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 $b(e,t,r){if(!(r<1))return 0;let n=Math.max(0,r);return uM(o=>Math.hypot(o,n)/e.reach(t,o,n)-1)}function lM(e,t,r){let n=Math.max(0,r);return uM(o=>Math.hypot(n,o)/e.reach(t,n,o)-1)}function uM(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 Gb(e,t){return e.model?.kind==="simple"?null:mM(e,t)}var iM=new WeakMap,Vb=100,cM=1.35,Bb=18,rn=41,um=41,uc=65;function mM(e,t){let r=iM.get(e);if(r)return r;let n=Math.log(cM),o=(m,f)=>{let h=M=>Math.abs(cr(e,m,M,f)),b=h(0),g=t.muY(m)*m,y=new Float64Array(rn),x=b>0&&g>0?Math.max(1,t.muX(m)*m/b):1;if(!(b>0)||!(g>0))y.fill(1);else{let M=[],S=[];for(let F=0;F<um;F++){let T=Math.sin(.5*Math.PI*F/(um-1));M.push(T),S.push(F===0?1:F===um-1?0:Math.min(S[F-1],h(T*g)/b))}let w=um-1;for(let F=0;F<rn;F++){let T=F/(rn-1);for(;w>0&&S[w-1]<T;)w--;let A=w>0?S[w-1]-S[w]:0;y[F]=w===0?M[0]:M[w]+(A>0?(T-S[w])/A:0)*(M[w-1]-M[w])}y[0]=1,y[rn-1]=0}let v=new Float64Array(uc),k=M=>Math.atan2(y[M],M/(rn-1)/x),R=rn-2;for(let M=0;M<uc;M++){let S=.5*Math.PI*M/(uc-1),w=Math.cos(S),F=Math.sin(S);for(;R>0&&k(R)<S;)R--;let T=R/(rn-1)/x,A=y[R],C=(R+1)/(rn-1)/x,P=y[R+1],L=w*(P-A)-F*(C-T),E=Math.abs(L)>1e-12?(T*(P-A)-A*(C-T))/L:Math.hypot(T,A);v[M]=E>0?E:Math.hypot(T,A)}return{room:y,scale:x,edge:v}},a=Array.from({length:Bb},(m,f)=>Vb*cM**f),s=a.map(m=>o(m,!1)),i=a.map(m=>o(m,!0)),c=(m,f)=>{let h=Math.min(1,Math.abs(f)*m.scale)*(rn-1),b=Math.min(rn-2,Math.floor(h));return m.room[b]+(h-b)*(m.room[b+1]-m.room[b])},l=m=>{let f=m>Vb?Math.log(m/Vb)/n:0;if(f>=Bb-1)return[Bb-2,1];let h=Math.floor(f);return[h,f-h]},u=(m,f,h)=>{if(h===0)return 1;let b=h<0?i:s,g=c(b[m],h);return f>0?g+f*(c(b[m+1],h)-g):g},d=(m,f,h)=>{let b=f<0?i:s,[g,y]=l(m),x=Math.atan2(Math.abs(h),Math.abs(f))/(.5*Math.PI)*(uc-1),v=Math.min(uc-2,Math.floor(x)),k=M=>M.edge[v]+(x-v)*(M.edge[v+1]-M.edge[v]),R=k(b[g]);return y>0?R+y*(k(b[g+1])-R):R},p={keeps(m,f){if(f===0)return 1;let[h,b]=l(m);return u(h,b,f)},atLoad(m){let[f,h]=l(m);return b=>u(f,h,b)},use(m,f,h){let b=Math.hypot(f,h);return b>0?Math.min(1,b/d(m,f,h)):0},reach:d};return iM.set(e,p),p}var G2=[["front","FL","FR"],["rear","RL","RR"]];function ws(e,t,r,n){let o={...e},a=0,s=mc;for(let[i,c,l]of G2){let u=(v,k)=>n(i,Math.max(0,k[v])).fyPeak,d=Math.min(s,e[c]),p=Math.min(s,e[l]),m=d*u(c,r)+p*u(l,r);if(!(m>0))continue;let f=u(c,t),h=u(l,t),b=d*f+p*h,g=b>0?m/b:1/0,y=d*g,x=p*g;y<=s?x<=s||(x=s,y=f>0?(m-s*h)/f:1/0):(y=s,x=h>0?(m-s*f)/h:1/0),(!(y<=s)||!(x<=s))&&(a+=Math.max(0,m-s*(f+h)),y=Math.min(s,y),x=Math.min(s,x)),o[c]=y,o[l]=x}return{util:o,short:a}}var dM=.001,K2=1e-5,pM=100;function H2(e,t,r,n){if(!(n>dM))return r;let o=t,a=Math.abs(r-t)<pM?t+Math.sign(r-t)*pM:r;for(let s=0;s<60&&Math.abs(a-o)>K2;s++){let i=.5*(o+a);e(i)>dM?a=i:o=i}return o}function dm(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=H2(e,t,o,e(o));return a!==o&&(n=a),a},edge:()=>n}}function pm(e,t){let r=n=>{try{return Ae(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 Kb=40;function fm(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 fM=[0,0,0];function z2(e,t){let r=re(H(e.rockerPivotB,e.rockerPivotA)),n=re(H(e.rockerToPushrod,e.pushrodOuter)),o=re(H(e.damperChassis,e.rockerToDamper)),a=Math.abs(J(r,le(H(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(J(r,le(H(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}function hm(e,t,r){if(e.mcpherson)return Y2(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 d=0;d<6;d++){let p=re(H(n[d].c,n[d].r)),m=le(H(n[d].r,o),p);a[0][d]=p[0],a[1][d]=p[1],a[2][d]=p[2],a[3][d]=m[0],a[4][d]=m[1],a[5][d]=m[2]}let s=le(H(e.contactPatch,o),t),i=r??fM,c=[-t[0],-t[1],-t[2],-(s[0]+i[0]),-(s[1]+i[1]),-(s[2]+i[2])],l=Qr(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]:z2(e,u[5]),condProxy:l.condProxy,singular:l.singular}}function Y2(e,t,r){let n=e.wheelCenter,o=e.damperChassis,a=[{at:e.uprightLower,dir:re(H(e.lcaFront,e.uprightLower))},{at:e.uprightLower,dir:re(H(e.lcaRear,e.uprightLower))},{at:e.tieOuter,dir:re(H(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(H(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(H(e.contactPatch,n),t),c=r??fM,l=[-t[0],-t[1],-t[2],-(i[0]+c[0]),-(i[1]+c[1]),-(i[2]+c[2])],u=Qr(s,l),d=u.x,p=[d[3],d[4],d[5]],m=re(H(o,e.pushrodOuter)),f=J(p,m),h=Math.hypot(p[0]-f*m[0],p[1]-f*m[1],p[2]-f*m[2]);return{ucaFront:NaN,ucaRear:NaN,lcaFront:d[0],lcaRear:d[1],tieRod:d[2],pushRod:u.singular?NaN:f,damper:u.singular?NaN:f,condProxy:u.condProxy,singular:u.singular,strutSide:u.singular?NaN:h,topMount:p}}function Hb(e,t){let r=re(e.spinAxis),n=le(H(e.contactPatch,e.wheelCenter),t),o=J(n,r);return[-o*r[0],-o*r[1],-o*r[2]]}var W2=[0,0,0];function dc(e,t,r,n){let o=e.direct?e.damperChassis:e.rockerToPushrod;if(e.mcpherson)return{...hm(e,r,n),armResidual:0};if(t==="upright")return{...hm(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=re(H(s.front,s.bj)),u=re(H(s.rear,s.bj)),d=re(H(e.tieInner,e.tieOuter)),p=[{at:s.bj,dir:l},{at:s.bj,dir:u},{at:e.tieOuter,dir:d},{at:i.bj,dir:[1,0,0]},{at:i.bj,dir:[0,1,0]},{at:i.bj,dir:[0,0,1]}],m=[[],[],[],[],[],[]];for(let q=0;q<6;q++){let Y=p[q].dir,K=le(H(p[q].at,c),Y);m[0][q]=Y[0],m[1][q]=Y[1],m[2][q]=Y[2],m[3][q]=K[0],m[4][q]=K[1],m[5][q]=K[2]}let f=le(H(e.contactPatch,c),r),h=n??W2,b=[-r[0],-r[1],-r[2],-(f[0]+h[0]),-(f[1]+h[1]),-(f[2]+h[2])],g=Qr(m,b),y=g.singular,x=g.x,v=x[0],k=x[1],R=x[2],M=[x[3],x[4],x[5]],S=re(H(i.rear,i.front)),w=re(H(o,e.pushrodOuter)),F=X(M,-1),T=(q,Y)=>J(S,le(H(q,i.front),Y)),A=T(e.pushrodOuter,w),C=Math.abs(A)>1e-9?-T(i.bj,F)/A:NaN,P=oe(F,X(w,C)),L=X(P,-1),E=re(H(i.front,i.bj)),_=re(H(i.rear,i.bj)),D=J(E,E),I=J(E,_),V=J(_,_),O=J(E,L),B=J(_,L),z=D*V-I*I,j=NaN,$=NaN,N=NaN;if(Math.abs(z)>1e-12){j=(O*V-B*I)/z,$=(D*B-I*O)/z;let q=oe(X(E,j),X(_,$)),Y=H(L,q);N=Math.hypot(Y[0],Y[1],Y[2])}let W=a?{f:v,r:k}:{f:j,r:$},Z=a?{f:j,r:$}:{f:v,r:k};return{ucaFront:W.f,ucaRear:W.r,lcaFront:Z.f,lcaRear:Z.r,tieRod:R,pushRod:C,damper:y||!Number.isFinite(C)||e.decoupled?NaN:e.direct?C:j2(e,C),condProxy:g.condProxy,singular:y,armResidual:N}}function j2(e,t){let r=re(H(e.rockerPivotB,e.rockerPivotA)),n=re(H(e.rockerToPushrod,e.pushrodOuter)),o=re(H(e.damperChassis,e.rockerToDamper)),a=Math.abs(J(r,le(H(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(J(r,le(H(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}var Pj=Math.PI/180;function pc(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 bM=["QSX3","QSX8","QSX13","QSX14"],U2=["QSX1"],bm=["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",...bM],X2=["PKY6","PKY7","PVY3","PVY4","PHY3","PEY4","RVY3","QBZ4","QDZ3","QHZ3","QHZ4","QEZ5","QDZ8","QDZ9","QDZ10","QDZ11","SSZ3","SSZ4"];function q2(){let e=new Set(X2),t=bm.filter(r=>!bM.includes(r));return[...t.filter(r=>!e.has(r)),...[...e].filter(r=>!t.includes(r)),...U2]}function Q2(e,t){let r={...e};for(let n of t)r[n]!==void 0&&r[n]!==0&&(r[n]=-r[n]);return r}var Ln=(e,t,r)=>Number.isFinite(e[t])?e[t]:r;function gM(e,t){return t!=="5.2"?Ln(e,"PKY6",0)*Ln(e,"LKYC",1):Ln(e,"PKY1",-15)*Math.sin(Ln(e,"PKY4",2)*Math.atan(1/Ln(e,"PKY2",2)))*Ln(e,"LKY",1)*Ln(e,"PHY3",0)+Ln(e,"PVY3",0)*Ln(e,"LMUY",1)}var hM=.1;function yM(e){if(e.fitData)return"sae";let t=gM(e.coeffs,e.version);return t>hM?"sae":t<-hM?"iso":null}function fc(e){return e.axisSystem??yM(e)??"sae"}function gm(e){let t=new Set,r=n=>{for(let o of n)t.has(o)?t.delete(o):t.add(o)};return fc(e)==="iso"&&r(bm),e.axisSystem&&e.side==="left"&&r(q2()),t.size?Q2(e.coeffs,t):e.coeffs}var Dj=Math.PI/180;var G=(e,t)=>Number.isFinite(e)?e:t;function RM(e){let t=gm(e);return{PCX1:G(t.PCX1,1.65),PDX1:G(t.PDX1,1),PDX2:G(t.PDX2,0),PDX3:G(t.PDX3,0),PEX1:G(t.PEX1,0),PEX2:G(t.PEX2,0),PEX3:G(t.PEX3,0),PEX4:G(t.PEX4,0),PHX1:G(t.PHX1,0),PHX2:G(t.PHX2,0),PKX1:G(t.PKX1,20),PKX2:G(t.PKX2,0),PKX3:G(t.PKX3,0),PPX1:G(t.PPX1,0),PPX2:G(t.PPX2,0),PPX3:G(t.PPX3,0),PPX4:G(t.PPX4,0),PVX1:G(t.PVX1,0),PVX2:G(t.PVX2,0),PCY1:G(t.PCY1,1.3),PDY1:G(t.PDY1,1),PDY2:G(t.PDY2,0),PDY3:G(t.PDY3,0),PEY1:G(t.PEY1,0),PEY2:G(t.PEY2,0),PEY3:G(t.PEY3,0),PEY4:G(t.PEY4,0),PEY5:G(t.PEY5,0),PHY1:G(t.PHY1,0),PHY2:G(t.PHY2,0),PHY3:G(t.PHY3,0),PKY1:G(t.PKY1,-15),PKY2:G(t.PKY2,2),PKY3:G(t.PKY3,0),PKY4:G(t.PKY4,2),PKY5:G(t.PKY5,0),PKY6:G(t.PKY6,0),PKY7:G(t.PKY7,0),PPY1:G(t.PPY1,0),PPY2:G(t.PPY2,0),PPY3:G(t.PPY3,0),PPY4:G(t.PPY4,0),PPY5:G(t.PPY5,0),PVY1:G(t.PVY1,0),PVY2:G(t.PVY2,0),PVY3:G(t.PVY3,0),PVY4:G(t.PVY4,0),RBX1:G(t.RBX1,0),RBX2:G(t.RBX2,0),RBX3:G(t.RBX3,0),RBY1:G(t.RBY1,0),RBY2:G(t.RBY2,0),RBY3:G(t.RBY3,0),RBY4:G(t.RBY4,0),RCX1:G(t.RCX1,1),RCY1:G(t.RCY1,1),REX1:G(t.REX1,0),REX2:G(t.REX2,0),REY1:G(t.REY1,0),REY2:G(t.REY2,0),RHX1:G(t.RHX1,0),RHY1:G(t.RHY1,0),RHY2:G(t.RHY2,0),RVY1:G(t.RVY1,0),RVY2:G(t.RVY2,0),RVY3:G(t.RVY3,0),RVY4:G(t.RVY4,0),RVY5:G(t.RVY5,1),RVY6:G(t.RVY6,0),PPZ1:G(t.PPZ1,0),PPZ2:G(t.PPZ2,0),QBZ1:G(t.QBZ1,8),QBZ2:G(t.QBZ2,0),QBZ3:G(t.QBZ3,0),QBZ4:G(t.QBZ4,0),QBZ5:G(t.QBZ5,0),QBZ9:G(t.QBZ9,0),QBZ10:G(t.QBZ10,0),QCZ1:G(t.QCZ1,1.1),QDZ1:G(t.QDZ1,.1),QDZ2:G(t.QDZ2,0),QDZ3:G(t.QDZ3,0),QDZ4:G(t.QDZ4,0),QDZ6:G(t.QDZ6,0),QDZ7:G(t.QDZ7,0),QDZ8:G(t.QDZ8,0),QDZ9:G(t.QDZ9,0),QDZ10:G(t.QDZ10,0),QDZ11:G(t.QDZ11,0),QEZ1:G(t.QEZ1,0),QEZ2:G(t.QEZ2,0),QEZ3:G(t.QEZ3,0),QEZ4:G(t.QEZ4,0),QEZ5:G(t.QEZ5,0),QHZ1:G(t.QHZ1,0),QHZ2:G(t.QHZ2,0),QHZ3:G(t.QHZ3,0),QHZ4:G(t.QHZ4,0),SSZ1:G(t.SSZ1,0),SSZ2:G(t.SSZ2,0),SSZ3:G(t.SSZ3,0),SSZ4:G(t.SSZ4,0),QSX1:G(t.QSX1,0),QSX2:G(t.QSX2,0),QSX3:G(t.QSX3,0),QSX4:G(t.QSX4,0),QSX5:G(t.QSX5,0),QSX6:G(t.QSX6,0),QSX7:G(t.QSX7,0),QSX8:G(t.QSX8,0),QSX9:G(t.QSX9,0),QSX10:G(t.QSX10,0),QSX11:G(t.QSX11,0),QSX12:G(t.QSX12,0),QSX13:G(t.QSX13,0),QSX14:G(t.QSX14,0),PPMX1:G(t.PPMX1,0),QSY1:G(t.QSY1,0),QSY2:G(t.QSY2,0),QSY3:G(t.QSY3,0),QSY4:G(t.QSY4,0),QSY5:G(t.QSY5,0),QSY6:G(t.QSY6,0),QSY7:G(t.QSY7,0),QSY8:G(t.QSY8,0),LONGVL:t.LONGVL!==void 0&&t.LONGVL>0?t.LONGVL:16.7,LCX:G(t.LCX,1),LCY:G(t.LCY,1),LEX:G(t.LEX,1),LEY:G(t.LEY,1),LFZO:G(t.LFZO,1),LHX:G(t.LHX,1),LHY:G(t.LHY,1),LKX:G(t.LKX,1),LKY:G(t.LKY,1),LKYC:G(t.LKYC,1),LKZC:G(t.LKZC,1),LMUX:G(t.LMUX,1),LMUY:G(t.LMUY,1),LMX:G(t.LMX,1),LMY:G(t.LMY,1),LVMX:G(t.LVMX,1),LRES:G(t.LRES,1),LS:G(t.LS,1),LTR:G(t.LTR,1),LVX:G(t.LVX,1),LVY:G(t.LVY,1),LVYKA:G(t.LVYKA,1),LXAL:G(t.LXAL,1),LYKA:G(t.LYKA,1)}}var xM=new WeakMap;function hc(e){let t=xM.get(e);return t===void 0&&(t=RM(e),xM.set(e,t)),t}var vM=e=>e>=0?1:-1;function bc(e,t,r=0,n){let o=hc(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,d=(o.PDY1+o.PDY2*c)*(1+o.PPY3*l+o.PPY4*l*l)*(1-o.PDY3*s*s)*o.LMUY,p=o.PCY1*o.LCY,m=d*a,f=o.PKY1*i*(1+o.PPY1*l)*Math.sin(o.PKY4*Math.atan(a/((o.PKY2+o.PKY5*s*s)*(1+o.PPY2*l)*i)))*(1-o.PKY3*Math.abs(s))*o.LKY,h=e.version!=="5.2",b=a*(o.PKY6+o.PKY7*c)*(1+o.PPY5*l)*o.LKYC,g=a*(o.PVY3+o.PVY4*c)*s*o.LKYC*o.LMUY,y=Math.abs(f)>1e-6?f:1e-6*(f<0?-1:1),x=h?(o.PHY1+o.PHY2*c)*o.LHY+(b*s-g)/y:(o.PHY1+o.PHY2*c)*o.LHY+o.PHY3*s,v=h?a*(o.PVY1+o.PVY2*c)*o.LVY*o.LMUY+g:a*((o.PVY1+o.PVY2*c)*o.LVY+(o.PVY3+o.PVY4*c)*s)*o.LMUY,k=p*m!==0?f/(p*m):0;return{Fz:a,g:s,dfz:c,dpi:l,Fz0p:i,R0:u,Cy:p,Dy:m,By:k,SHy:x,SVy:v,Kya:f,muy:d,EyA:o.PEY1+o.PEY2*c,EyG:1+o.PEY5*s*s,EyS:o.PEY3+o.PEY4*s,LEY:o.LEY}}function ym(e,t,r=0,n){let o=bc(e,t,r,n),a=hc(e),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:d,muy:p,Kya:m,SVy:f,By:h,Cy:b,Dy:g,SHy:y}=o,x=(a.PHX1+a.PHX2*c)*a.LHX,v=(a.PDX1+a.PDX2*c)*(1+a.PPX3*l+a.PPX4*l*l)*(1-a.PDX3*i*i)*a.LMUX,k=a.PCX1*a.LCX,R=v*s,M=s*(a.PKX1+a.PKX2*c)*Math.exp(a.PKX3*c)*(1+a.PPX1*l+a.PPX2*l*l)*a.LKX,S=k*R!==0?M/(k*R):0,w=Math.abs(m)>1e-6?m:1e-6*(m<0?-1:1),F=e.version!=="5.2",T=s*(a.PVX1+a.PVX2*c)*a.LVX*a.LMUX,A=F&&i!==0?bc(e,t,0,n):o,C=a.REX1+a.REX2*c;C>1&&(C=1);let P=a.REY1+a.REY2*c;return P>1&&(P=1),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:d,Cy:b,Dy:g,By:h,SHy:y,SVy:f,Kya:m,muy:p,EyA:o.EyA,EyG:o.EyG,EyS:o.EyS,LEY:o.LEY,SHx:x,Cx:k,Dx:R,Bx:S,SVx:T,ExA:a.PEX1+a.PEX2*c+a.PEX3*c*c,PEX4:a.PEX4,LEX:a.LEX,SHxa:a.RHX1,Bxa0:a.RBX1+a.RBX3*i*i,RBX2:a.RBX2,LXAL:a.LXAL,Cxa:a.RCX1,Exa:C,SHyk:a.RHY1+a.RHY2*c,Byk0:a.RBY1+a.RBY4*i*i,RBY2:a.RBY2,RBY3:a.RBY3,LYKA:a.LYKA,Cyk:a.RCY1,Eyk:P,DVykA:p*s*(a.RVY1+a.RVY2*c+a.RVY3*i),RVY4:a.RVY4,RVY5:a.RVY5,RVY6:a.RVY6,LVYKA:a.LVYKA,SHt:a.QHZ1+a.QHZ2*c+(a.QHZ3+a.QHZ4*c)*i,Bt:(a.QBZ1+a.QBZ2*c+a.QBZ3*c*c)*(1+a.QBZ4*i+a.QBZ5*Math.abs(i))*(a.LKY/a.LMUY),Ct:a.QCZ1,Dt:s*(d/u)*(a.QDZ1+a.QDZ2*c)*(1-a.PPZ1*l)*(1+a.QDZ3*i+a.QDZ4*i*i)*a.LTR,EtA:a.QEZ1+a.QEZ2*c+a.QEZ3*c*c,EtG:a.QEZ4+a.QEZ5*i,Br:a.QBZ9*(a.LKY/a.LMUY)+a.QBZ10*h*b,Dr:F?s*d*((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*d*((a.QDZ6+a.QDZ7*c)*a.LRES+(a.QDZ8+a.QDZ9*c)*(1+a.PPZ2*l)*i)*a.LMUY,arOff:m!==0?f/m:0,sixOne:F,y0:A,kk:M/w*(M/w),sS0:d*(a.SSZ1+(a.SSZ3+a.SSZ4*c)*i)*a.LS,sS2:d*a.SSZ2*a.LS/u}}function Uo(e,t){let r=t+e.SHy,n=e.EyA*(e.EyG-e.EyS*vM(r))*e.LEY;n>1&&(n=1);let o=e.By*r;return e.Dy*Math.sin(e.Cy*Math.atan(o-n*(o-Math.atan(o))))+e.SVy}function xm(e,t){let r=t+e.SHx,n=e.ExA*(1-e.PEX4*vM(r))*e.LEX;n>1&&(n=1);let o=e.Bx*r;return e.Dx*Math.sin(e.Cx*Math.atan(o-n*(o-Math.atan(o))))+e.SVx}function kM(e,t,r){if(r===0)return t;let n=Math.tan(t);return Math.atan(Math.sqrt(n*n+e.kk*r*r))*Math.sign(t)}function Z2(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=kM(e,o,r),i=e.Bt*s;return e.Dt*Math.cos(e.Ct*Math.atan(i-a*(i-Math.atan(i))))*n}function J2(e,t,r,n){return e.Dr*Math.cos(Math.atan(e.Br*kM(e,t+e.SHy+e.arOff,r)))*n}function MM(e,t,r,n,o,a){let s=Math.cos(t),i=Z2(e,t,r,s),c=J2(e,t,r,s);return-i*a+c+(e.sS0+e.sS2*o)*n}function e_(e,t,r,n,o,a){return e.sixOne?r*(e.g===0?n:Uo(e.y0,t)):o-a}function Rm(e,t,r){let n=e.Bxa0*Math.cos(Math.atan(e.RBX2*t))*e.LXAL,o=r+e.SHxa,a=e.SHxa===0?1:Math.cos(e.Cxa*Math.atan(n*e.SHxa-e.Exa*(n*e.SHxa-Math.atan(n*e.SHxa))))||1;return Math.cos(e.Cxa*Math.atan(n*o-e.Exa*(n*o-Math.atan(n*o))))/a*xm(e,t)}function zb(e,t){let r=e.sS0===0&&e.sS2===0?0:Rm(e,0,t),n=Uo(e,t);return MM(e,t,0,r,n,e.sixOne&&e.g!==0?Uo(e.y0,t):n)}function vm(e,t,r){let n=Uo(e,r),o=Rm(e,t,r),a=e.Byk0*Math.cos(Math.atan(e.RBY2*(r-e.RBY3)))*e.LYKA,s=t+e.SHyk,i=e.SHyk===0?1:Math.cos(e.Cyk*Math.atan(a*e.SHyk-e.Eyk*(a*e.SHyk-Math.atan(a*e.SHyk))))||1,c=Math.cos(e.Cyk*Math.atan(a*s-e.Eyk*(a*s-Math.atan(a*s))))/i,u=e.DVykA*Math.cos(Math.atan(e.RVY4*r))*Math.sin(e.RVY5*Math.atan(e.RVY6*t))*e.LVYKA,d=c*n+u;return{Fx:o,Fy:d,Mz:MM(e,r,t,o,d,e_(e,r,c,n,d,u))}}var gc=(e,t)=>Math.max(.1,e.muY0+e.loadSensY*(t-e.nominalLoad)),yc=(e,t)=>Math.max(.1,e.muX0+e.loadSensX*(t-e.nominalLoad)),SM=(e,t,r)=>gc(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cy*Math.atan(e.By*r)),AM=(e,t,r)=>yc(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cx*Math.atan(e.Bx*r));function Yb(e,t){let r=Math.max(1,t.Fz),n=gc(e,r)*r,o=yc(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 Cs=Math.PI/180;function bo(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 wM(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?pc(r,t):1,s=n?pc(n,t):1,i=o?pc(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,d)=>{c[u]=(c[u]??1)*d};return l("LMUY",a),l("LMUX",s),l("LTR",i),l("LRES",i),{...e,coeffs:c}}function Fs(e,t,r){let n=0,o=0;for(let s=r;s<=t;s+=r){let i=Math.abs(e(s));i>o&&(o=i,n=s)}let a=r/10;for(let s=Math.max(a,n-r);s<=n+r;s+=a)o=Math.max(o,Math.abs(e(s)));return o}var Hj=Math.LN2/16;var t_=45;var r_=[];for(let e=1;e<=t_;e++){let t=[];for(let r=Math.max(.1,e-1);r<=e+1;r+=.1)t.push(r);r_[e]=t}var CM=new WeakMap;function Mm(e,t){CM.set(e,t)}function nn(e){return CM.get(e)??((t,r,n,o,a)=>e.forces({Fz:t,kappa:r,alpha:n,gamma:o,p:a}).Fx)}function Ke(e){let t=wM(e),r=t,n=t,o=4,a=b=>{let g=[],y=[],x=[],v=[];for(let M=0;M<o;M++)g.push(null),y.push(NaN),x.push(NaN),v.push(NaN);let k=0,R=0;return(M,S,w)=>{if(g[k]!==null&&M===y[k]&&S===x[k]&&w===v[k])return g[k];for(let T=0;T<o;T++)if(g[T]!==null&&M===y[T]&&S===x[T]&&w===v[T])return k=T,g[T];let F=b(M,S,w);return g[R]=F,y[R]=M,x[R]=S,v[R]=w,k=R,R=(R+1)%o,F}},s=a((b,g,y)=>ym(r,b,g,y)),i=a((b,g,y)=>bc(r,b,g,y)),c=b=>e.kind==="magic"?vm(s(b.Fz,b.gamma??0,b.p),b.kappa,b.alpha):Yb(n,b),l=(b,g,y=0,x)=>e.kind==="magic"?Uo(i(g,y,x),b):SM(n,g,b),u=(b,g,y=0,x)=>e.kind==="magic"?xm(s(g,y,x),b):AM(n,g,b),d=(b,g,y=0,x)=>e.kind==="magic"?zb(s(g,y,x),b):c({Fz:g,kappa:0,alpha:b,gamma:y,p:x}).Mz,p=b=>e.kind==="simple"?gc(n,b):Fs(g=>l(g*Cs,b),45,1)/Math.max(1,b),m=b=>e.kind==="simple"?yc(n,b):Fs(g=>u(g,b),.6,.02)/Math.max(1,b),f=b=>{let g=.1*Cs;return Math.abs((l(g,b)-l(-g,b))/(2*g))},h={model:e,forces:c,Fx:u,Fy:l,Mz:d,muX:m,muY:p,corneringStiffness:f,verticalStiffness:()=>e.verticalStiffness,rollingRadius:b=>{if(e.kind==="magic"&&e.missing?.includes("UNLOADED_RADIUS"))return 0;let g=e.unloadedR0??0;if(!(g>0))return 0;let y=e.verticalStiffness*1e3;if(!(y>0))return g;let x=e.rollingFraction??.306;return g-x*Math.max(0,b)/y},relaxationLength:b=>{let g=e.relaxation;if(!g)return 0;let y=g.carcassStiffness??0;if(!(y>0))return g.sigma;let x=f(Math.max(0,b));return x>0?x/(y*1e3):g.sigma}};return e.kind==="magic"&&Mm(h,(b,g,y,x,v)=>Rm(s(b,x,v),g,y)),h}function Ts(e){let t=Math.max(1,e.model.kind==="magic"?e.model.fnomin:e.model.nominalLoad);return e.Fy(2*Cs,t,0)-e.Fy(-2*Cs,t,0)>=0?1:-1}function xc(e,t=e.kind==="magic"?e.fnomin:e.nominalLoad){let r=Ke(e),n=2*Cs,o=3*Cs,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 n_=Math.PI/180;function we(e,t){return e.axle?e.axle(t):e}function Sm(e,t){if(e===t)return e;let r=Ts(e)*Ts(t),n=(p,m)=>.5*(p+m),o=(p,m)=>p>0&&m>0?n(p,m):p>0?p:m>0?m:0,a=p=>{let m=e.forces(p),f=t.forces(p);return{Fx:n(m.Fx,f.Fx),Fy:n(m.Fy,r*f.Fy),Mz:n(m.Mz,r*f.Mz)}},s=(p,m,f=0,h)=>n(e.Fx(p,m,f,h),t.Fx(p,m,f,h)),i=(p,m,f=0,h)=>n(e.Fy(p,m,f,h),r*t.Fy(p,m,f,h)),c=(p,m,f=0,h)=>n(e.Mz(p,m,f,h),r*t.Mz(p,m,f,h)),l={model:e.model,forces:a,Fx:s,Fy:i,Mz:c,muX:p=>Fs(m=>s(m,p),.6,.02)/Math.max(1,p),muY:p=>Fs(m=>i(m*n_,p),45,1)/Math.max(1,p),corneringStiffness:p=>n(e.corneringStiffness(p),t.corneringStiffness(p)),verticalStiffness:()=>o(e.verticalStiffness(),t.verticalStiffness()),rollingRadius:p=>o(e.rollingRadius(p),t.rollingRadius(p)),relaxationLength:p=>o(e.relaxationLength(p),t.relaxationLength(p)),axle:p=>p==="front"?e:t},u=nn(e),d=nn(t);return Mm(l,(p,m,f,h,b)=>n(u(p,m,f,h,b),d(p,m,f,h,b))),l}function zt(e){if(FM.has(e))return e;let t=TM.get(e);if(t)return t;let r;if(e.axle){let n=e.axle("front"),o=e.axle("rear"),a=zt(n),s=zt(o);r=a===n&&s===o?e:Sm(a,s)}else Ts(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)},Mm(r,nn(e)));return FM.add(r),r!==e&&TM.set(e,r),r}var FM=new WeakSet,TM=new WeakMap;var Am=25*(Math.PI/180);function o_(e){let t=.6180339887,r=0,n=Am,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 Rc(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=Am;if(s(Am)<=a){let u=o_(s);if(u.force<=a)return u.alpha;c=u.alpha}else if(o>0){let u=Math.max(0,o*.6),d=Math.min(Am,o*1.6+.001);s(u)<a&&s(d)>=a&&(i=u,c=d)}let l=.001*a;for(let u=0;u<12;u++){let d=.5*(i+c),p=s(d)-a;if(p<0?i=d:c=d,Math.abs(p)<=l)return d}return c}var Wb={shaft:!1,trail:0,hub:[0,0,0]};function LM(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 jb(e,t,r){let n=r.shaft?Hb(e,t):[0,0,0];if(r.trail!==0){let a=LM(e),s=[t[0],t[1],0],i=H(s,X(a,J(s,a)));n=oe(n,le(X(a,-r.trail),i))}let o=r.hub;return(o[0]!==0||o[1]!==0||o[2]!==0)&&(n=H(n,le(H(e.contactPatch,e.wheelCenter),o))),{force:oe(t,o),moment:n}}var a_=(e,t)=>{let r=e!==void 0&&e>0?1/e:0,n=t!==void 0&&t>0?1/t:0;return r+n},wm={ucaFront:0,ucaRear:0,lcaFront:0,lcaRear:0,tieRod:0,pushRod:0,rack:0};function Xo(e){return!e.measured}function qo(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 vc(e,t){let r=e.corner.hardpoints,n=ps(e.rocker,t.points.rockerAngle);return{ucaFront:r.ucaFront,ucaRear:r.ucaRear,lcaFront:r.lcaFront,lcaRear:r.lcaRear,tieInner:Ko(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 Ub(e,t,r=0){let n=t.links??{},o=t.bushings??{},a=(l,u,d)=>{let p=a_(u,d);return p>0&&Number.isFinite(l)?l*p:0},s=o.topMount,i=e.topMount,c=i&&s!==void 0&&s>0&&i.every(Number.isFinite)?[-i[0]/s,-i[1]/s,-i[2]/s]:void 0;return{...c?{topMount:c}:{},ucaFront:a(e.ucaFront,n.ucaFront,o.ucaFront),ucaRear:a(e.ucaRear,n.ucaRear,o.ucaRear),lcaFront:a(e.lcaFront,n.lcaFront,o.lcaFront),lcaRear:a(e.lcaRear,n.lcaRear,o.lcaRear),tieRod:a(e.tieRod,n.tieRod,o.tieInner),pushRod:a(e.pushRod,n.pushRod,void 0),rack:r}}function DM(e,t,r,n){let o=Pe(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 kc(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=DM(r.ucaFront,r.ucaRear,Pe(r.uprightUpper,r.ucaFront)+t.ucaFront,Pe(r.uprightUpper,r.ucaRear)+t.ucaRear);o.ubjAxial0=i.axial,o.ubjRadius2=i.radius2}if(t.lcaFront!==0||t.lcaRear!==0){let i=DM(r.lcaFront,r.lcaRear,Pe(r.uprightLower,r.lcaFront)+t.lcaFront,Pe(r.uprightLower,r.lcaRear)+t.lcaRear),c=J(n.lbjRel0,n.lcaDir),l=H(n.lbjRel0,X(n.lcaDir,c)),u=Math.hypot(l[0],l[1],l[2]);o.lbjRel0=u>1e-9?oe(X(n.lcaDir,i.axial),X(l,Math.sqrt(i.radius2)/u)):oe(X(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,X(n.rackAxis,t.rack))),t.pushRod===0)return{corner:e.corner,inv:o,rocker:e.rocker};let a=Math.sqrt(e.rocker.rodLen2)+t.pushRod,s={...e.rocker,rodLen2:a*a};return{corner:e.corner,inv:o,rocker:s}}var s_=8,i_=1e-5,c_=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 Xb(e,t,r){let n=jb(e,r.force,r.extras??Wb),o=r.alignMoment?oe(n.moment,[0,0,r.alignMoment]):n.moment;return dc(e,t,n.force,o)}function Fm(e,t,r,n,o,a,s=0){let i=tt(e,t,r,o,a),c=e.corner.compliance;if(!(qo(c)&&Xo(e.corner)))return{state:i,forces:Xb(vc(e,i),e.corner.config.pushrodAttach,n),deflection:wm,rigid:i,iterations:0,converged:!0,bypassed:!0};let u=i,d=e,p=e.corner.config.pushrodAttach,m=Xb(vc(e,i),p,n),f=wm,h=!1,b=0;for(;b<s_;b++){let g=vc(d,u);if(m=Xb(g,p,n),m.singular)break;f=Ub(m,c,s),d=kc(e,f);let y=tt(d,t,r,c_(u),a),x=Pe(y.points.wheelCenter,u.points.wheelCenter);if(u=y,x<i_){h=!0;break}}return{state:u,forces:m,deflection:f,rigid:i,iterations:b+1,converged:h&&u.converged,bypassed:!1}}var Cm=1e3,EM=1e5;function IM(e,t,r,n,o){let a=Fm(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 Tm(e,t,r,n,o){let a={force:[0,0,n]},s=(b,g=0)=>IM(e,t,r,{force:b,alignMoment:g},o),i=IM(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,Cm,n]),l=s([0,-Cm,n]),u=s([Cm,0,n]),d=s([-Cm,0,n]),p=s([0,0,n],EM),m=s([0,0,n],-EM),f=(b,g)=>(b-g)/2,h=[i,c,l,u,d,p,m].every(b=>b.converged);return{toePerLateral:f(c.toe,l.toe),camberPerLateral:f(c.camber,l.camber),toePerLongitudinal:f(u.toe,d.toe),camberPerLongitudinal:f(u.camber,d.camber),toePerAligning:f(p.toe,m.toe),lateralPatch:f(c.patch[1],l.patch[1]),longitudinalPatch:f(u.patch[0],d.patch[0]),bypassed:!1,converged:h}}var l_=1e3;function qb(e,t=l_){if(!qo(e.compliance)||!Xo(e))return;let r=wt(e),n=tt(r,0,0),o=Tm(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 Ps(e,t=-Kb,r=Kb,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=ct(e,{travelMin:t,travelMax:r,steps:n}),s=qb(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 Pm(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 go(e,t){return{motionRatio:Pm(e.travel,e.motionRatio,t),camber:Pm(e.travel,e.camber,t),toe:Pm(e.travel,e.toe,t),damperLen:Pm(e.travel,e.damperLen,t)}}var _M=Math.PI/180,u_=9.81;function yo(e,t,r,n=0){let o=Ge(e),a=e.wheelbase*(1-e.frontMassFrac),s=e.wheelbase*e.frontMassFrac,i=As(e,n),c=e.aero?.model?(v,k,R)=>As(e,n,k,v,R):()=>i,l=go(t,0),u=go(r,0),d=e.loadFactor,p=d!==void 0&&d!==1?(d-1)*e.massTotal*u_:0,m=p*e.frontMassFrac/2,f=p*(1-e.frontMassFrac)/2,h=(v,k)=>k>0&&Number.isFinite(k)&&v+k>0?k/(v+k):1,b=yt(e,"front"),g=yt(e,"rear"),y={F:h(e.wheelRateFront+(e.heaveSpringFront??0),b),R:h(e.wheelRateRear+(e.heaveSpringRear??0),g)},x={F:h(e.wheelRateFront+e.arbFront,b),R:h(e.wheelRateRear+e.arbRear,g)};return(v,k,R=0,M=0)=>{let S=c(v,k,R),w={F:o.rollGradientFront*v,R:o.rollGradientRear*v},F=o.pitchGradient*k*_M,T=(_,D)=>{let I=D==="F"?e.trackFront:e.trackRear,V=D==="F"?o.rideRateFront:o.rideRateRear,O=(_==="R"?1:-1)*(I/2)*Math.tan(w[D]*_M),B=(D==="R"?s:-a)*Math.tan(F),z=`${D}${_}`,j=p?S[z]+(D==="F"?m:f):S[z],$=V>0?j/V:0;return{anti:O,sym:B+$}},A={FL:T("L","F"),FR:T("R","F"),RL:T("L","R"),RR:T("R","R")},C=_=>{let D=_[0];return A[_].sym*y[D]+A[_].anti*x[D]},P=Ss(e,M,o,{FL:C("FL"),FR:C("FR")}),L=P.ends?{F:w.F+P.ends.front,R:w.R+P.ends.rear}:{F:w.F+P.rollDeg,R:w.R+P.rollDeg},E=(_,D)=>{let I=D==="F"?t:r,V=D==="F"?l:u,O=`${D==="F"?"F":"R"}${_}`,B=A[O].sym+A[O].anti+P.travel[O],z=C(O)+P.travel[O]*x[D],j=B-z,$=go(I,z),N=(_==="R"?1:-1)*$.camber;return{travel:z,tyre:j,ground:B,camber:N,camberRoad:N+L[D],toe:$.toe,bumpToe:$.toe-V.toe,damperTravel:V.damperLen-$.damperLen}};return{FL:E("L","F"),FR:E("R","F"),RL:E("L","R"),RR:E("R","R"),steeringJacking:P}}}var Qb=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function Qo(e){return{enabled:e?.enabled===!0,roadFeedbackGain:Math.min(2,Math.max(0,Qb(e?.roadFeedbackGain,1))),turnInFrictionNm:Math.max(0,Qb(e?.turnInFrictionNm,0)),columnStiffnessNmPerRad:Math.max(0,Qb(e?.columnStiffnessNmPerRad,0))}}function Zb(e,t,r){let n=Qo(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 NM=()=>({totalNm:0,aligningNm:0,lateralNm:0,longitudinalNm:0,jackingNm:0});function Zo(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 Mc(e,t,r,n="model",o){let a=e.steerFront;if(!Zo(e)||!a)return null;let s=t<0?-1:1,c=a.rackRatioMmPerRev/(2*Math.PI)/1e3,l=t>=0,u=o&&a.travelSurface?ks(a,Math.abs(t),l?o.FL:o.FR,l?o.FR:o.FL):Ms(a,Math.abs(t));if(!u.innerJacobian||!u.outerJacobian)return null;let d=(b,g)=>{let y=r[b],x=b==="FL"?-1:1,v=-x*y.Fy,R={aligning:1e3*(-x*y.Mz)*g.yaw,lateral:v*g.lateral,longitudinal:y.Fx*g.longitudinal,jacking:y.Fz*g.vertical},M=NM();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 S=-s*(R.aligning+R.lateral+R.longitudinal+R.jacking);return{moment:M,rackN:S}},p=d("FL",l?u.innerJacobian:u.outerJacobian),m=d("FR",l?u.outerJacobian:u.innerJacobian),f=NM();for(let b of[p.moment,m.moment])f.aligningNm+=b.aligningNm,f.lateralNm+=b.lateralNm,f.longitudinalNm+=b.longitudinalNm,f.jackingNm+=b.jackingNm,f.totalNm+=b.totalNm;let h=Zb(f.totalNm,t,e.steeringSystem);return f.totalNm=h.driverNm,{...f,roadNm:h.roadNm,assistanceNm:h.assistanceNm,frictionNm:h.frictionNm,columnTwistDeg:h.columnTwistDeg,rackForceN:p.rackN+m.rackN,aligningSource:n,perWheel:{FL:p.moment,FR:m.moment}}}var m_=e=>"front"in e&&"rear"in e;function Ls(e,t){return m_(e)?e[t]:e}function eg(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 d=Math.min(r-2,Math.floor(u/o)),p=(u-a[d])/o;return l[d]+p*(l[d+1]-l[d])};return{muX:l=>c(s,l),muY:l=>c(i,l)}}function Jb(e,t){let r=Math.max(0,t.Fz);return VM(e.muX(r)*r,e.muY(r)*r,t)}function VM(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 OM(e,t,r){let n=Jb(e,t),o=Jb(e,r);return{left:n,right:o,fyRes:n.fyRes+o.fyRes}}function Dn(e,t,r){let n=OM(Ls(e,"front"),t.FL,t.FR),o=OM(Ls(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 Sc=[{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"}],p_=Sc.flatMap(e=>[e.min,e.max]);function f_(e){let t={};for(let r of Sc){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 Lm(e){if(e.kind==="magic")return e.range??f_(e.coeffs)}function tg(e){return Math.max(1,e.kind==="magic"?e.fnomin:e.nominalLoad)}function BM(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 Or(e){let t=$M.get(e);if(t!==void 0)return t;let r=10*tg(e.model),{turnover:n,collapse:o}=b_(e,r),a=n??o??r;return $M.set(e,a),a}var $M=new WeakMap;function b_(e,t){let r=tg(e.model),n=d=>e.muY(d),o=d=>n(d)*d,a=80,s=t/a,i=null,c=o(s);for(let d=2;d<=a;d++){let p=o(d*s);if(p<c){i=BM(o,(d-2)*s,d*s,20,(m,f)=>m>f);break}c=p}let l=null,u=n(s);for(let d=2;d<=a;d++){let p=n(d*s);if(p>u){let m=BM(n,(d-2)*s,d*s,40,(f,h)=>f<h);n(m)<.05*n(r)&&(l=m);break}u=p}return{turnover:i,collapse:l}}var GM=.1;function Dm(e,t=tg(e)){let r=Ke(e).muX(t);return{muX:r,none:Number.isFinite(r)&&r<GM}}var KM=["FL","FR","RL","RR"],g_=e=>e==="FL"||e==="RL",y_=e=>e==="FL"||e==="FR"?"front":"rear";function Em(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 KM)a[l]={...t[l]};let s=l=>{let u=0;for(let p of KM)y_(p)===e.axle&&(a[p].Fx=e.sense*(p===e.strong?l-e.open/2:e.open/2),u-=(g_(p)?o:-o)*a[p].Fx);let d=Dn(r,a,n.arms);return u*n.ayDir>=0?Math.abs(u)<=d.stabil:Math.abs(u)<=d.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 x_=[["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]],R_=[["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]],v_=[["QBZ1","Trail slope factor for trail Bpt at Fznom",8],["QBZ2","Variation of slope Bpt with load",0],["QBZ3","Variation of slope Bpt with load squared",0],["QBZ4","Variation of slope Bpt with camber",0],["QBZ5","Variation of slope Bpt with absolute camber",0],["QBZ9","Factor for scaling factors of slope factor Br of Mzr",0],["QBZ10","Factor for dimensionless cornering stiffness of Br of Mzr",0],["QCZ1","Shape factor Cpt for pneumatic trail",1.1],["QDZ1","Peak trail Dpt = Dpt*(Fz/Fznom*R0)",.1],["QDZ2","Variation of peak Dpt with load",0],["QDZ3","Variation of peak Dpt with camber",0],["QDZ4","Variation of peak Dpt with camber squared",0],["QDZ6","Peak residual torque Dmr = Dmr/(Fz*R0)",0],["QDZ7","Variation of peak factor Dmr with load",0],["QDZ8","Variation of peak factor Dmr with camber",0],["QDZ9","Variation of peak factor Dmr with camber and load",0],["QDZ10","Variation of peak factor Dmr with camber squared",0],["QDZ11","Variation of Dmr with camber squared and load",0],["QEZ1","Trail curvature Ept at Fznom",0],["QEZ2","Variation of curvature Ept with load",0],["QEZ3","Variation of curvature Ept with load squared",0],["QEZ4","Variation of curvature Ept with sign of Alpha-t",0],["QEZ5","Variation of Ept with camber and sign Alpha-t",0],["QHZ1","Trail horizontal shift Sht at Fznom",0],["QHZ2","Variation of shift Sht with load",0],["QHZ3","Variation of shift Sht with camber",0],["QHZ4","Variation of shift Sht with camber and load",0],["PPZ1","Effect of inflation pressure on length of pneumatic trail",0],["PPZ2","Influence of inflation pressure on residual aligning torque",0],["SSZ1","Nominal value of s/R0: effect of Fx on Mz",0],["SSZ2","Variation of distance s/R0 with Fy/Fznom",0],["SSZ3","Variation of distance s/R0 with camber",0],["SSZ4","Variation of distance s/R0 with load and camber",0]],k_=[["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]],M_=[["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]],zM=[["lateral",x_],["longitudinal",R_],["aligning",v_],["combined",k_],["scaling",M_]].flatMap(([e,t])=>t.map(([r,n,o])=>({key:r,section:e,text:n,fallback:o}))),NU=new Map(zM.map(e=>[e.key,e]));var S_=/^\$\s*EDITED\s+([A-Z][A-Z0-9_]*)\s+was\s+(absent|[-+0-9.eE]+)\s*$/;function YM(e){let t={};for(let r of e.split(/\r?\n/)){let n=r.trim().match(S_);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 w_=/^\s*\$\s*UNLOADED_RADIUS_STAND_IN\s*=\s*([0-9.eE+-]+)/,C_=/^\$-+ written by (?:PaceDynamics|PaceLab)\b/m,F_=/^\$\s*AXIS_SYSTEM\s*=\s*(ISO-W|SAE)\b/m;function T_(e){let t=e.match(F_);return t?{axisSystem:t[1]==="SAE"?"sae":"iso",trustSide:!0}:C_.test(e)?{axisSystem:"sae",trustSide:!1}:{axisSystem:"iso",trustSide:!0}}function P_(e){return e>=62?"6.2":e>=61?"6.1":"5.2"}var WM=new Map([["pa",1],["pascal",1],["kpa",1e3],["kilopascal",1e3],["mpa",1e6],["megapascal",1e6],["bar",1e5],["psi",6894.757293168]]);function L_(e,t,r){let n=r.PRESSURE?.trim().toLowerCase(),o=n===void 0?1:WM.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 D_=new Map([["radians",1],["radian",1],["rad",1],["degrees",Math.PI/180],["degree",Math.PI/180],["deg",Math.PI/180]]);function E_(e,t){let r=(s,i)=>s===void 0?1:i.get(s.trim().toLowerCase()),n=r(t.ANGLE,D_),o={fz:1,kappa:1,alpha:n,gamma:n,p:r(t.PRESSURE,WM)},a={};for(let s of Sc){let i=o[s.q];if(i===void 0)continue;let c={};for(let[l,u]of[["min",s.min],["max",s.max]]){let d=e[u];Number.isFinite(d)&&(c[l]=i===1?d:Number((d*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 Ac(e,t="imported",r={}){let n=T_(e),o=r.axisSystem??n.axisSystem,a={},s={},i={},c="",l;for(let g of e.split(/\r?\n/)){let y=g.match(w_);y&&(l=parseFloat(y[1]));let x=g.replace(/[$!].*$/,"").trim();if(!x)continue;if(x.startsWith("[")){c=(x.match(/^\[([^\]]*)/)?.[1]??"").trim().toUpperCase();continue}let v=x.indexOf("=");if(v<0)continue;let k=x.slice(0,v).trim().toUpperCase(),R=x.slice(v+1).trim(),M=R.match(/^'([^']*)'|^"([^"]*)"/);if(M){s[k]=M[1]??M[2]??"",c==="UNITS"&&(i[k]=s[k]);continue}let S=parseFloat(R);Number.isFinite(S)&&(a[k]=S)}let u=P_(a.FITTYP??62),d=YM(e),p=d?Object.fromEntries(Object.entries(d).filter(([g])=>a[g]!==void 0)):void 0,m=a.VERTICAL_STIFFNESS??a.KZ??0,f=L_(a,s,i),h=E_(a,i),b=[];return a.UNLOADED_RADIUS===void 0&&a.R0===void 0&&b.push("UNLOADED_RADIUS"),m<=0&&b.push("VERTICAL_STIFFNESS"),a.FNOMIN===void 0&&b.push("FNOMIN"),f===void 0&&b.push("NOMPRES"),{kind:"magic",name:t,version:u,coeffs:a,axisSystem:o,side:n.trustSide?s.TYRESIDE==="RIGHT"?"right":s.TYRESIDE==="LEFT"?"left":void 0:void 0,fnomin:a.FNOMIN??5e3,unloadedR0:a.UNLOADED_RADIUS??a.R0??(l!==void 0&&l>0?l:.3),...a.WIDTH!==void 0&&a.WIDTH>0?{sectionWidth:a.WIDTH}:{},verticalStiffness:m>0?m/1e3:0,...a.FREFF!==void 0&&!a.DREFF?{rollingFraction:a.FREFF}:{},...a.LATERAL_STIFFNESS!==void 0&&a.LATERAL_STIFFNESS>0?{relaxation:{sigma:0,carcassStiffness:a.LATERAL_STIFFNESS/1e3,source:"fitted"}}:{},nomPressure:f??0,missing:b,...p&&Object.keys(p).length?{edited:p}:{},...h?{range:h}:{}}}function on(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 Im(e){if(!e)return null;let t=e.sectionWidth;return t!==void 0&&t>0?t:null}function jM(e){if(!e||e.kind!=="magic")return null;let t=e.coeffs.RIM_RADIUS,r=e.coeffs.RIM_WIDTH;return typeof t=="number"&&t>0&&typeof r=="number"&&r>0?{diameter:2*t*1e3,width:r*1e3}:null}var zU=Math.PI/180;var XU=Math.PI/180,qU=180/Math.PI;function wc(){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 qM=`$ 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 rg(){return Ac(qM,"Example MF6.2")}var __=Math.PI/180,QM=2,ZM=2;function JM(e){let t=Math.sin(ZM*Math.atan(1/QM)),r=-e.corneringStiffness/(e.Fz0*t),n=e.camberStiffness/__/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(QM)}
|
|
174
174
|
PKY3 = 0.8
|
|
175
|
-
PKY4 = ${o(
|
|
175
|
+
PKY4 = ${o(ZM)}
|
|
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=Sc(XM(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 qM={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},QM={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},ZM={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},JM={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},eS={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},tS={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},rS={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},nS={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},tg=()=>En(qM),rg=()=>En(QM),ng=()=>En(ZM),og=()=>En(JM),ag=()=>En(eS),sg=()=>En(tS),ig=()=>En(rS),cg=()=>En(nS);var oS=e=>Number.isFinite(e)&&e>0;function Em(e,t){let r=oS(t.grip)?t.grip:1,n=oS(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 wc={ok:!0,violation:0},Zo=1e7;function In(e,t){let r;try{r=e.build(t)}catch(s){return{total:Zo*2,feasible:!1,terms:[],reason:`build failed: ${String(s)}`}}let n=e.feasible(r);if(!n.ok)return{total:Zo+Math.max(0,n.violation),feasible:!1,terms:[],reason:n.reason};let o;try{o=e.terms(r)}catch(s){return{total:Zo*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:Zo*2,feasible:!1,terms:o,reason:"objective was not finite"}}var Cc=(e,t)=>!t||(e.feasible!==t.feasible?e.feasible:e.total<t.total);function lg(e,t){return t.map((r,n)=>Math.min(e[n].hi,Math.max(e[n].lo,r)))}var Vr=e=>e.map(t=>t.start);function Im(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 P_(e){let t=0;for(;t===0;)t=e();return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e())}function ug(e,t){let{budget:r}=t,n=Math.max(1,Math.floor(t.progressEvery??1)),o=e.variables,a=m=>lg(o,m.map((f,h)=>o[h].lo+f*(o[h].hi-o[h].lo))),s=m=>m.map((f,h)=>(f-o[h].lo)/(o[h].hi-o[h].lo)),i=0,c=0,l=null,u=null,d=[];return{vars:o,denorm:a,norm:s,evaluate:m=>{if(i>=r)return l?.total??Number.POSITIVE_INFINITY;i++;let f=m.map(g=>Math.min(1,Math.max(0,g))),h=In(e,a(f));h.feasible||c++;let b=Cc(h,l)?h:l;return b===h&&(l=h,u=f),d.push(b.total),t.onProgress&&(i%n===0||i===r)&&t.onProgress({evaluations:i,budget:r,x:a(u),score:b,infeasible:c}),h.total},left:()=>r-i,result:m=>({method:m,x:u?a(u):Vr(o),score:l??In(e,Vr(o)),evaluations:i,history:d,infeasible:c})}}var mg=(e,t,r,n=0,o)=>{let a=t?r.norm(Vr(e.variables)):e.variables.map(()=>.5);return!(n>0)||!o?a:a.map(s=>Math.min(1,Math.max(0,s+n*2*(o()-.5))))};function aS(e,t){let r=ug(e,t),n=Im(t.seed??1),o=e.variables.length;for(r.evaluate(mg(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 Ds(e,t){let r=ug(e,t),n=e.variables.length,o=Im(t.seed??1),a=1,s=2,i=.5,c=.5,l=mg(e,t.warmStart!==!1,r,t.startJitter,o),u=.25;for(;r.left()>0;){let d=[{u:l,f:r.evaluate(l)}];for(let p=0;p<n&&r.left()>0;p++){let m=l.slice();m[p]+=m[p]+u>1?-u:u,d.push({u:m,f:r.evaluate(m)})}for(;r.left()>0;){d.sort((g,y)=>g.f-y.f);let p=d[n],m=new Array(n).fill(0);for(let g=0;g<n;g++)for(let y=0;y<n;y++)m[y]+=d[g].u[y]/n;let f=g=>m.map((y,x)=>y+g*(y-p.u[x])),h=f(a),b=r.evaluate(h);if(b<d[0].f){let g=f(s),y=r.evaluate(g);d[n]=y<b?{u:g,f:y}:{u:h,f:b}}else if(b<d[n-1].f)d[n]={u:h,f:b};else{let g=f(-i),y=r.evaluate(g);if(y<p.f)d[n]={u:g,f:y};else{let x=d[0],v=0;for(let k=1;k<=n;k++)for(let R=0;R<n;R++)v=Math.max(v,Math.abs(d[k].u[R]-x.u[R]));if(v<1e-4)break;for(let k=1;k<=n&&r.left()>0;k++){let R=d[k].u.map((M,S)=>x.u[S]+c*(M-x.u[S]));d[k]={u:R,f:r.evaluate(R)}}}}}d.sort((p,m)=>p.f-m.f),l=d[0].u.map(p=>Math.min(1,Math.max(0,p+.05*(o()-.5)))),u=Math.max(.02,u*.5)}return r.result("nelder-mead")}function sS(e,t){let r=ug(e,t),n=e.variables.length,o=Im(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,S)=>M+S,0);for(let M=0;M<s;M++)i[M]/=c;let l=1/i.reduce((M,S)=>M+S*S,0),u=(l+2)/(n+l+5),d=1+2*Math.max(0,Math.sqrt((l-1)/(n+1))-1)+u,p=(4+l/n)/(n+4+2*l/n),m=(n+2)/3,f=Math.min(1,m*2/((n+1.3)**2+l)),h=Math.min(1-f,m*2*(l-2+1/l)/((n+2)**2+l)),b=Math.sqrt(n)*(1-1/(4*n)+1/(21*n*n)),g=mg(e,t.warmStart!==!1,r,t.startJitter,o),y=.25,x=new Array(n).fill(1),v=new Array(n).fill(0),k=new Array(n).fill(0),R=0;for(;r.left()>0;){R++;let M=[];for(let A=0;A<a&&r.left()>0;A++){let C=[];for(let L=0;L<n;L++)C.push(P_(o));let P=g.map((L,E)=>L+y*x[E]*C[E]);M.push({z:C,u:P,f:r.evaluate(P)})}if(M.length<s)break;M.sort((A,C)=>A.f-C.f);let S=g.slice(),w=new Array(n).fill(0);g=new Array(n).fill(0);for(let A=0;A<s;A++)for(let C=0;C<n;C++)g[C]+=i[A]*M[A].u[C],w[C]+=i[A]*M[A].z[C];g=g.map(A=>Math.min(1,Math.max(0,A)));for(let A=0;A<n;A++)v[A]=(1-u)*v[A]+Math.sqrt(u*(2-u)*l)*w[A];let F=Math.sqrt(v.reduce((A,C)=>A+C*C,0)),T=F/Math.sqrt(1-(1-u)**(2*R))/b<1.4+2/(n+1)?1:0;for(let A=0;A<n;A++){let C=(g[A]-S[A])/(y*x[A]);k[A]=(1-p)*k[A]+T*Math.sqrt(p*(2-p)*l)*C}for(let A=0;A<n;A++){let C=0;for(let E=0;E<s;E++)C+=i[E]*M[E].z[A]*M[E].z[A];let P=x[A]*x[A],L=(1-f-h)*P+f*(k[A]*k[A]+(1-T)*p*(2-p)*P)+h*C*P;x[A]=Math.sqrt(Math.max(1e-12,L))}if(y*=Math.exp(u/d*(F/b-1)),y<1e-6||y>10)break}return r.result("sep-cma-es")}var Es=[{name:"random",run:aS},{name:"nelder-mead",run:Ds},{name:"sep-cma-es",run:sS}];var n9=Math.PI/180;var _m=Math.PI/180;var i9={Fz:100,alpha:.25*_m,kappa:.005,gamma:.5*_m,p:6900},iS={Fz:100,alpha:1*_m,kappa:.02,gamma:.5*_m,p:6900};var cS=Math.PI/180,p9={t:{s:1,sec:1,ms:.001},v:{"m/s":1,"km/h":1/3.6,"km/hr":1/3.6,kph:1/3.6},alpha:{rad:1,deg:cS},gamma:{rad:1,deg:cS},p:{pa:1,kpa:1e3,bar:1e5,mpa:1e6},rl:{m:1,mm:.001,cm:.01},Fz:{n:1},Fx:{n:1},Fy:{n:1},Mz:{nm:1,"n-m":1}};var y9=Math.PI/180;var K_=Math.PI/180;var A9=3*K_;var P9=Math.PI/180;var K9=Math.PI/180;var q_={RCX1:1,RCY1:1,REX1:0,REY1:0,RBY3:0,RHX1:0,RHY1:0},mS={RBX1:15,RBX2:15,RBY1:18,RBY2:19,...q_};var J9=Math.PI/180;var tN=Math.PI/180,Nm=[{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"}],fX=new Map(Nm.map(e=>[e.id,e]));var hX=.01*tN;var pt=Math.PI/180;var fS=new Set(Nm.filter(e=>e.group!=="inputs"&&(e.unit==="N"||e.unit==="N\xB7m"||e.unit==="N/rad")).map(e=>e.id)),hS={alpha:{from:-15*pt,to:15*pt,n:61},kappa:{from:-.25,to:.25,n:61},gamma:{from:-6*pt,to:6*pt,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}},bg={alpha:{from:0,to:12*pt,n:7},kappa:{from:-.2,to:.2,n:9},gamma:{from:-4*pt,to:4*pt,n:5},Fz:{from:400,to:1600,n:5},p:{from:6e4,to:12e4,n:4},V:{from:5,to:35,n:4}};var gg={alpha:{from:0,to:12*pt,n:25},kappa:{from:-.2,to:.2,n:25},gamma:{from:-4*pt,to:4*pt,n:17},Fz:{from:300,to:1800,n:16},p:{from:6e4,to:12e4,n:13},V:{from:5,to:35,n:13}};var Ee=(e,t,r,n={},o={})=>({id:e,form:"curves",sweep:[{input:t,...hS[t],...o}],x:t,y:r,...n}),Om=(e,[t,r],n,o,a={})=>({id:e,form:"carpet",sweep:[{input:t,...bg[t]},{input:r,...bg[r]}],x:n,y:[o],...a}),_n=(e,t)=>({id:e,fixed:t}),kr={input:"Fz",values:"car"},hg={alpha:0,kappa:0},Zt={kappa:0},dS={alpha:0},nN={input:"Fz",values:[500,1e3,1500]},oN=[{id:"overview",name:"Overview",cards:[_n("tyre","tyre"),Ee("fy","alpha",["Fy"],{title:"Lateral force",hold:Zt}),Ee("mz","alpha",["Mz"],{title:"Aligning moment",hold:Zt}),Ee("fx","kappa",["Fx"],{title:"Longitudinal force",hold:dS}),Om("combined-carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),_n("ellipse","ellipse")]},{id:"lateral",name:"Lateral",cards:[Ee("fy-load","alpha",["Fy"],{title:"Lateral force per wheel load",series:kr,hold:Zt}),Ee("muy-load","alpha",["muY"],{title:"Lateral force per unit load",series:kr,hold:Zt}),Ee("fy-peak","alpha",["Fy"],{title:"Lateral force over its peak",series:kr,hold:Zt,scale:{per:"peak"}},{from:0,to:15*pt,n:61}),Ee("muy-peak","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load"}),Ee("calpha","Fz",["Calpha"],{title:"Cornering stiffness over load"}),Ee("alpha-peak","Fz",["alphaPeak"],{title:"Slip angle at the peak over load"})]},{id:"aligning",name:"Aligning",cards:[Ee("mz-load","alpha",["Mz"],{title:"Aligning moment per wheel load",series:kr,hold:Zt}),Ee("trail","alpha",["t"],{title:"Pneumatic trail",series:kr,hold:Zt},{from:0,to:12*pt,n:49}),Ee("mzr","alpha",["Mzr"],{title:"Residual aligning moment",series:kr,hold:Zt},{from:0,to:12*pt,n:49}),Om("gough",["alpha","Fz"],"Fy","Mz",{title:"Gough plot",hold:Zt}),Ee("steering-feel","alpha",["t"],{title:"Steering feel",x:"FyRel",series:kr,hold:Zt},{from:0,to:12*pt,n:49})]},{id:"longitudinal",name:"Longitudinal",cards:[Ee("fx-load","kappa",["Fx"],{title:"Longitudinal force per wheel load",series:kr,hold:dS}),Ee("mux-peak","Fz",["muXPeak"],{title:"Peak longitudinal \u03BC over load"}),Ee("kx","Fz",["dFxdk"],{title:"Slip stiffness at zero slip over load",hold:hg}),Ee("kappa-peak","Fz",["kappaPeak"],{title:"Slip ratio at the peak over load"})]},{id:"combined",name:"Combined",cards:[Om("carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),Om("envelope-load",["kappa","alpha"],"Fy","Fx",{title:"Friction envelope per load",scale:{per:"Fz"},facet:nN}),Ee("fy-kappa","kappa",["Fy"],{title:"Side force while driving or braking",series:{input:"alpha",values:[2*pt,4*pt,8*pt]}}),Ee("fx-kappa","kappa",["Fx"],{title:"Driving force while cornering",series:{input:"alpha",values:[0,4*pt,8*pt]}}),_n("ellipse","ellipse")]},{id:"camber",name:"Camber",cards:[Ee("fy-gamma","alpha",["Fy"],{title:"Lateral force per inclination",series:{input:"gamma",values:[-4,-2,0,2,4].map(e=>e*pt)},hold:Zt}),Ee("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",...gg.gamma},{input:"Fz",...gg.Fz,follow:!0}],x:"gamma",y:["Fz"],z:"muYPeak"},Ee("camber-stiffness","alpha",["dFydg"],{title:"Camber stiffness at the point",series:kr,hold:Zt}),Ee("mx","alpha",["Mx"],{title:"Overturning moment",series:kr,hold:Zt})]},{id:"rolling",name:"Rolling and radius",cards:[Ee("my","V",["My"],{title:"Rolling-resistance moment",series:kr,hold:hg}),Ee("radius","Fz",["R0","Rl","Re"],{title:"Radius over load"},{from:0}),Ee("p-roll","V",["Proll"],{title:"Rolling power",series:kr,hold:hg})]},{id:"transient",name:"Transient",cards:[Ee("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},Ee("delta-fy","alpha",["Fy"],{title:"Lateral force, minus the reference",hold:Zt,scale:{delta:!0}}),Ee("delta-mu","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load, minus the reference",scale:{delta:!0}}),Ee("delta-calpha","Fz",["Calpha"],{title:"Cornering stiffness over load, minus the reference",scale:{delta:!0}})]},{id:"car",name:"Car",cards:[_n("operating","operating"),_n("wheels","wheels")]},{id:"fit",name:"Fit check",cards:[_n("fitLateral","fitLateral"),_n("fitLongitudinal","fitLongitudinal"),_n("fitCoupling","fitCoupling"),_n("fitEnvelope","fitEnvelope")]}];var dN=5670374e-14,yg=273.15,yS=.95,xS=60,Vm=10,pN=.55,lr=25,xg=-20,Rg=50,Tc={tempC:[20,100,200,550,650,750],factor:[.8,.92,1,1,.85,.65]},Pc={discMassKg:.5,discOuterMm:220,specificHeatJPerKgK:460,emissivity:.6,coolingWPerM2K:200,padCurve:{tempC:[...Tc.tempC],factor:[...Tc.factor]}},Bm={...Pc,discMassKg:.4,discOuterMm:200,padCurve:{tempC:[...Tc.tempC],factor:[...Tc.factor]}};function vg(e,t){let r=t==="front"?Pc:Bm,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 fN=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},Fc=(e,t,r,n)=>Math.min(r,Math.max(t,fN(e,n)));function hN(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 kg(e,t){return{discMassKg:Fc(e?.discMassKg,.05,20,t.discMassKg),discOuterMm:Fc(e?.discOuterMm,50,600,t.discOuterMm),specificHeatJPerKgK:Fc(e?.specificHeatJPerKgK,100,3e3,t.specificHeatJPerKgK),emissivity:Fc(e?.emissivity,.02,1,t.emissivity),coolingWPerM2K:Fc(e?.coolingWPerM2K,Vm,5e3,t.coolingWPerM2K),padCurve:hN(e?.padCurve,t.padCurve)}}function $m(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 Mg(e,t=1){let r=e.discMassKg*e.specificHeatJPerKgK,n=e.discOuterMm*.001/2,o=2*Math.PI*n*n,a=xS/3.6,s=e.emissivity*dN*o,i=d=>Vm+(e.coolingWPerM2K-Vm)*Math.pow(Math.max(0,d)*t/a,pN),c=(d,p,m)=>{let f=d+yg,h=m+yg;return i(p)*o*(d-m)+s*(f**4-h**4)},l=(d,p)=>i(p)*o+4*s*Math.max(0,d+yg)**3,u=(d,p)=>r/l(p,d);return{heatCapacityJPerK:r,areaM2:o,convectionAt:i,coolingW:c,timeConstantS:u,step(d,p,m,f,h){if(!(f>0))return d+p/r;let b=u(m,d+Math.max(0,p)/r),g=Math.max(1,Math.ceil(f/(.25*b))),y=f/g,x=p/g;for(let v=0;v<g;v++)d+=(x-c(d,m,h)*y)/r;return d},padFactor:d=>$m(e.padCurve,d),window:RS(e.padCurve)}}function Gm(e,t,r,n,o,a,s=lr){let i=n.length,c=new Array(i),l=new Array(i),u=new Array(i),d=yS/Math.max(1,t),p=a,m=p,f=0,h=0,b=0;for(let g=0;g<i;g++){let y=Math.max(0,r[g]??0);c[g]=p,l[g]=y*n[g],u[g]=e.padFactor(p);let x=y*(o[g]??0);f+=x,p<e.window.fromC?h+=x:p>e.window.toC&&(b+=x);let v=g+1<i?n[g+1]:n[g],k=.5*(n[g]+v),R=k>0?(o[g]??0)/k:0;p=e.step(p,d*x,k,R,s),p>m&&(m=p)}return{tempC:c,heatW:l,padFactor:u,startC:a,endC:p,maxC:m,workJ:f,coldWorkJ:h,hotWorkJ:b}}function RS(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])&&$m(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 Sg=e=>typeof e=="number"&&Number.isFinite(e);function Km(e){if(e==null)return null;if(typeof e!="object"||Array.isArray(e))return"disc and caliper are not readable.";let t=e;for(let[r,n]of[["discDiameter","disc diameter"],["caliperHeight","caliper height"],["caliperLength","caliper length"],["caliperWidth","caliper width"]]){let o=t[r];if(!Sg(o)||!(o>0))return`${n} must be a length above zero.`}return Sg(t.discOffset)?!Sg(t.caliperAngle)||Math.abs(t.caliperAngle)>180?"caliper angle must be between \u2212180\xB0 and 180\xB0.":null:"disc offset must be a length."}var Ag=1e5,SS=.001,Jo={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},Cg={fullAtBar:10,maxPowerKw:0,fadeBelowKmh:0,distribution:"equal"};var Fg=wS(zm(Jo,"Formula Student brakes")),Tg=40,AS={ideal:!1,barFront:Jo.barFront,pedalForceMaxN:0,testSpeedKmh:Tg,regen:Cg};function vS(e){let{heat:t,packaging:r,...n}=e;return{...n,...t?{heat:{...t,padCurve:{tempC:[...t.padCurve.tempC],factor:[...t.padCurve.factor]}}}:{},...r?{packaging:{...r}}:{}}}function wS(e){let t=(r,n)=>r.heat?r:{...r,heat:vg(r,n)};return{...e,front:t(e.front,"front"),rear:t(e.rear,"rear")}}function zm(e,t){return{name:t,pedalRatio:e.pedalRatio,masterFrontMm:e.masterFrontMm,masterRearMm:e.masterRearMm,valve:e.valve,valveKneeBar:e.valveKneeBar,valveSlope:e.valveSlope,front:vS(e.front),rear:vS(e.rear),adjusterPitchMm:e.adjusterPitchMm,barLengthMm:e.barLengthMm}}function Pg(e,t){return CS({...e,barFront:t.barFront,pedalForceMaxN:t.pedalForceMaxN})}function Lg(e,t){let r=On(t),n=e?an(e):void 0;return{mode:r.ideal?"tyre":n?"hydraulic":"balance",hydraulic:n?Pg(n,r):Jo,regen:r.regen}}var bN=["none","proportioning","limiter"],Hm=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},St=(e,t,r,n)=>Math.min(r,Math.max(t,Hm(e,n))),gN=(e,t)=>{let r=Hm(e,t);return r>0?r:t};function kS(e,t,r){let n=e?.location==="inboard"?"inboard":e?.location==="outboard"?"outboard":t.location;return{location:n,discs:Math.max(1,Math.min(4,Math.round(Hm(e?.discs,n==="inboard"?1:t.discs)))),pistonsPerSide:Math.max(1,Math.min(6,Math.round(Hm(e?.pistonsPerSide,t.pistonsPerSide)))),pistonDiaMm:St(e?.pistonDiaMm,5,80,t.pistonDiaMm),padMu:St(e?.padMu,.05,1.5,t.padMu),effRadiusMm:St(e?.effRadiusMm,20,300,t.effRadiusMm),ratio:n==="inboard"?St(e?.ratio,1,20,t.ratio):1,...e?.heat&&typeof e.heat=="object"?{heat:kg(e.heat,t.heat??r)}:{},...Km(e?.packaging)===null&&e?.packaging?{packaging:{...e.packaging}}:{}}}function CS(e){let t=Jo;return{pedalRatio:St(e?.pedalRatio,.5,15,t.pedalRatio),pedalForceMaxN:St(e?.pedalForceMaxN,0,5e3,t.pedalForceMaxN),barFront:St(e?.barFront,.05,.95,t.barFront),masterFrontMm:St(e?.masterFrontMm,8,40,t.masterFrontMm),masterRearMm:St(e?.masterRearMm,8,40,t.masterRearMm),valve:bN.includes(e?.valve)?e?.valve:t.valve,valveKneeBar:St(e?.valveKneeBar,0,200,t.valveKneeBar),valveSlope:St(e?.valveSlope,0,1,t.valveSlope),front:kS(e?.front,t.front,Pc),rear:kS(e?.rear,t.rear,Bm),adjusterPitchMm:gN(e?.adjusterPitchMm,t.adjusterPitchMm),barLengthMm:St(e?.barLengthMm,0,500,t.barLengthMm)}}function yN(e){let t=Cg;return{fullAtBar:St(e?.fullAtBar,0,200,t.fullAtBar),maxPowerKw:St(e?.maxPowerKw,0,1e3,t.maxPowerKw),fadeBelowKmh:St(e?.fadeBelowKmh,0,100,t.fadeBelowKmh),distribution:e?.distribution==="wheel"?"wheel":"equal"}}function an(e){let t=CS(e??void 0),r=typeof e?.name=="string"&&e.name.trim()?e.name:xN;return zm(t,r)}function On(e){return{ideal:e?.ideal===!0,barFront:St(e?.barFront,.05,.95,Jo.barFront),pedalForceMaxN:St(e?.pedalForceMaxN,0,5e3,0),testSpeedKmh:St(e?.testSpeedKmh,5,150,Tg),regen:yN(e?.regen)}}var xN="Formula Student brakes";var wg=e=>Math.PI/4*(e*SS)**2;function xo(e,t){let r=e.pistonsPerSide*wg(e.pistonDiaMm)*Ag;return e.discs*2*e.padMu*r*e.effRadiusMm*SS*e.ratio/Math.max(.05,t)}function FS(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 Lc(e,t){let r=Math.max(0,t)*e.pedalRatio,n=e.barFront*r/wg(e.masterFrontMm)/Ag,o=(1-e.barFront)*r/wg(e.masterRearMm)/Ag;return{front:n,rearIn:o,rear:FS(e,o)}}function RN(e,t){let r=Lc(e,1);return{front:xo(e.front,t)*r.front,rear:xo(e.rear,t)*r.rearIn}}function Dc(e,t){let r=RN(e,t);return r.front/Math.max(1e-12,r.front+r.rear)}function Ec(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=TS(t,l),d=t.maxPowerKw>0&&l>0?t.maxPowerKw*1e3/l:1/0,p=Math.max(0,e.fFront[c]),m=Math.max(0,e.fRear[c]),f=p+m>0?Math.min(1,d/(p+m)):1;r.push(l),n.push(p*f*u),o.push(m*f*u)}}function TS(e,t){let r=e.fadeBelowKmh/3.6;return r>0?Math.max(0,Math.min(1,t/r)):1}function Nn(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 MS=new WeakMap;function ea(e){let t=MS.get(e);return t||(t=e.mode==="hydraulic"&&e.hydraulic?kN(e,e.hydraulic):vN(e),MS.set(e,t)),t}function vN(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 kN(e,t){let r=xo(t.front,e.tyreRadiusM),n=xo(t.rear,e.tyreRadiusM),o=e.regen,a=(c,l)=>{let u=Lc(t,c),d=0,p=0;if(o&&u.front>0){let m=o.fullAtBar>0?Math.min(1,u.front/o.fullAtBar):1;d=m*Nn(o.v,o.front,l),p=m*Nn(o.v,o.rear,l)}return{front:r*u.front+d,rear:n*u.rear+p,regenFront:d,regenRear:p,pFront:u.front,pRear:u.rear,pedalN:c}},s=t.pedalForceMaxN>0?t.pedalForceMaxN:1/0,i=(c,l)=>{let u=a(c,l);return u.front+u.rear};return{mode:"hydraulic",equalLeftRight:!0,uMax:s,demand:a,controlFor:(c,l)=>{if(!(c>0))return 0;let u=100;for(;i(u,l)<c&&u<1e6;)u*=2;if(u=Math.min(u,s),i(u,l)<=c)return u;let d=0;for(let p=0;p<60;p++){let m=.5*(d+u);i(m,l)<c?d=m:u=m}return u}}}function Dg(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 Ym=uc,MN=.1,ta=(e,t)=>e.a*Math.sqrt(Math.max(0,1-(t/Math.max(1e-9,e.b))**2));function Wm(e,t,r){if(!(r>t))return t;let n=(Math.sqrt(5)-1)/2,o=t,a=r,s=a-n*(a-o),i=o+n*(a-o),c=e(s),l=e(i);for(let p=0;p<48;p++)c<l?(o=s,s=i,c=l,i=o+n*(a-o),l=e(i)):(a=i,i=s,l=c,s=a-n*(a-o),c=e(s));let u=.5*(o+a),d=e(u);for(let p of[t,r]){let m=e(p);m>d&&(u=p,d=m)}return u}function _g(e,t,r){let n=Math.max(0,r-Ym*t.b),o=Math.min(r,Ym*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 d=.5*(c+l);s(d)>0?c=d:l=d}i=.5*(c+l)}return{lo:n,hi:o,y1:i,c1:e.cap(i),c2:t.cap(r-i)}}function Ng(e,t,r,n,o=0){let a=Math.max(0,r),s=_g(e,t,a),i=s?s.c1:0,c=s?s.c2:0,l=s?Math.min(i,c):0,[u,d]=e.a<=t.a?[e,t]:[t,e],p=u.Fz/Math.max(1e-9,u.Fz+d.Fz),m=Math.max(0,Math.min(1,1-p/MN)),f=m>0&&a<Ym*d.b?d.cap(a):0,h=f>l?l+m*(f-l):0,b=Math.max(0,Math.min(u.slide,u.a)),g={xNoLock:l,xLock:h,slide:b,ceiling:Math.max(0,n)},y=Math.max(0,o);if(!(y>0)||!s)return{...g,regenWheel:s?y:0,mixedMax:2*l,regenRoom:T=>2*Math.max(0,l-T)};let{lo:x,hi:v}=s,k=Wm(T=>{let A=ta(e,T),C=ta(t,a-T);return Math.min(A+C,2*Math.min(A,C)+y)},x,v),R=e.cap(k),M=t.cap(a-k),S=Math.max(2*l,Math.min(R+M,2*Math.min(R,M)+y)),w=(T,A,C)=>Math.min(y,Math.max(0,T-C))+Math.min(y,Math.max(0,A-C));return{...g,regenWheel:y,mixedMax:S,regenRoom:T=>{let A=w(i,c,T);if(!(a>0))return A;let C=_=>Ym*_.b*Math.sqrt(Math.max(0,1-(T/Math.max(1e-9,_.a))**2)),P=Math.max(x,a-C(t)),L=Math.min(v,C(e));if(!(P<=L))return A;let E=Wm(_=>Math.min(y,ta(e,_)-T)+Math.min(y,ta(t,a-_)-T),P,L);return Math.max(A,w(e.cap(E),t.cap(a-E),T))}}}var Eg=e=>Math.max(e.xNoLock,e.xLock),Ig=e=>Math.max(e.mixedMax,2*e.xLock);function Is(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 _s(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 Ic(e,t,r,n){return e.shares?SN(e,e.shares,t,r,n):AN(e,t,r,n)}function PS(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 SN(e,t,r,n,o){let a=Ig(r),s=Ig(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=_s(r,t.front*b),y=_s(n,t.rear*b);return Number.isFinite(g)&&Number.isFinite(y)?g+y:-1/0},u=a>0?t.front*i/a:1/0,d=s>0?t.rear*i/s:1/0,p=[{u:i,by:c?"pedal":u>=d?"front":"rear"}];if(r.xLock>r.xNoLock){let b=t.front>0?r.mixedMax/t.front:1/0;b<i&&p.push({u:b,by:"front"})}if(n.xLock>n.xNoLock){let b=t.rear>0?n.mixedMax/t.rear:1/0;b<i&&p.push({u:b,by:"rear"})}let{cand:m,force:f}=PS(p,l),h=e.demand(m.u,o);return{force:Math.max(0,Number.isFinite(f)?f:0),control:m.u,demand:h,limitedBy:m.by,lockFront:h.front/2>r.mixedMax/2*(1+1e-9),lockRear:h.rear/2>n.mixedMax/2*(1+1e-9)}}function AN(e,t,r,n){let o=Eg(t),a=Eg(r),s=k=>(k.front-k.regenFront)/2,i=k=>(k.rear-k.regenRear)/2,c=k=>{let R=e.demand(k,n);return s(R)<=o*(1+1e-12)&&i(R)<=a*(1+1e-12)},l=(k,R)=>{if(k(e.demand(R,n)))return R;let M=0,S=R;for(let w=0;w<60;w++){let F=.5*(M+S);k(e.demand(F,n))?M=F:S=F}return M},u=Number.isFinite(e.uMax)?e.uMax:100;if(!Number.isFinite(e.uMax))for(;c(u)&&u<1e7;)u*=2;let d=c(u)?u:l(k=>s(k)<=o&&i(k)<=a,u),p=Number.isFinite(e.uMax)&&d>=e.uMax,m=k=>{let R=e.demand(k,n),M=Is(t,s(R),R.regenFront),S=Is(r,i(R),R.regenRear);return Number.isFinite(M)&&Number.isFinite(S)?M+S:-1/0},f=e.demand(d,n),h=o>0?s(f)/o:1/0,b=a>0?i(f)/a:1/0,g=[{u:d,by:p?"pedal":h>=b?"front":"rear"}];if(t.xLock>t.xNoLock){let k=l(R=>s(R)<=t.xNoLock,d);k<d&&g.push({u:k,by:"front"})}if(r.xLock>r.xNoLock){let k=l(R=>i(R)<=r.xNoLock,d);k<d&&g.push({u:k,by:"rear"})}let{cand:y,force:x}=PS(g,m),v=e.demand(y.u,n);return{force:Math.max(0,Number.isFinite(x)?x:0),control:y.u,demand:v,limitedBy:y.by,lockFront:s(v)>t.xNoLock*(1+1e-9),lockRear:i(v)>r.xNoLock*(1+1e-9)}}var Vn={regen:!0,regenEfficiency:.6};function Bn(e,t){let r=e.energy??t??Vn;return{regen:r.regen===!0,regenEfficiency:Math.min(1,Math.max(0,Number.isFinite(r.regenEfficiency)?r.regenEfficiency:0))}}function $n(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 LS(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 Ct(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 jm(e,t,r){let n=e.length;if(!(r>=e[0]&&r<=e[n-1]))return NaN;if(n<3)return n===1?t[0]:t[0]+(r-e[0])/(e[1]-e[0])*(t[1]-t[0]);let o=0,a=n-1;for(;a-o>1;){let f=o+a>>1;e[f]<=r?o=f:a=f}if(o===n-1)return t[n-1];let s=f=>e[f+1]-e[f],i=f=>(t[f+1]-t[f])/s(f),c=f=>{if(f===0||f===n-1){let[y,x]=f===0?[0,1]:[n-2,n-3],v=i(y)*(1+s(y)/(s(y)+s(x)))-i(x)*(s(y)/(s(y)+s(x)));return v*i(y)<=0?0:Math.abs(v)>2*Math.abs(i(y))?2*i(y):v}let h=i(f-1),b=i(f),g=(h*s(f)+b*s(f-1))/(s(f-1)+s(f));return(Math.sign(h)+Math.sign(b))*Math.min(Math.abs(h),Math.abs(b),.5*Math.abs(g))},l=s(o),u=i(o),d=c(o),p=c(o+1),m=r-e[o];return t[o]+m*(d+m*((3*u-2*d-p)/l+m*(d+p-2*u)/(l*l)))}function _c(e,t,r){return r.map(n=>Ct(e,t,n))}var Nc=e=>e.reduce((t,r)=>r>t?r:t,-1/0),Ns=e=>e.reduce((t,r)=>r<t?r:t,1/0);var wN=[-.906179845938664,-.538469310105683,0,.538469310105683,.906179845938664],CN=[.236926885056189,.478628670499366,.568888888888889,.478628670499366,.236926885056189];function Og(e,t,r){let n=.5*(r-t),o=.5*(t+r),a=0;for(let s=0;s<5;s++)a+=CN[s]*e(n*wN[s]+o);return n*a}var FN=Math.PI*2,TN=.5/3.6;function Oc(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 Vg(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*FN;c[g]=y*o/n,l[g]=s[g]*n/o}let u=Nc(c),d=$n(Ns(c),u,u/TN),p=_c(c,l,d),{front:m,rear:f}=Oc(t,r),h=p.map(g=>g*m),b=p.map(g=>g*f);return{vVehicle:d,fFront:h,fRear:b,vMax:u}}var DS=60/(2*Math.PI),ES=.1,IS=.08,_S=0;function Bg(e){let t=(r,n)=>r===void 0||!Number.isFinite(r)?n:Math.max(0,r);return{up:t(e.upshiftTime,ES),down:t(e.downshiftTime,IS)}}function $g(e){let t=e.driveKept;return t===void 0||!Number.isFinite(t)?_S:Math.max(0,Math.min(1,t))}function Gg(e,t,r){let{primary:n,ratios:o,efficiency:a}=e.gearbox,s=t>0&&r>0&&n>0,i=(b,g)=>b/DS*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),d=b=>b>e.limitRpm?0:Math.max(0,et(e.rpm,e.torque,b)),p=(b,g)=>{let y=c[g];return y?b*y.ratio/r*DS:0},m=(b,g)=>g===0&&c.length>0&&b<c[0].vIdle,f=(b,g)=>{let y=c[g];return y?m(b,g)?d(e.idleRpm)*y.ratio*l/r:b<y.vIdle||b>y.vLimit?0:d(p(b,g))*y.ratio*l/r:0},h=(b,g)=>{let y=c[g];return!y||m(b,g)?0:u*y.ratio*y.ratio/(r*r)};return{engine:e,gears:c,efficiency:l,rDyn:r,vMax:c.length?c[c.length-1].vLimit:0,rpm:p,torque:d,force:f,inertiaMass:h,slipping:m}}function Os(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 Kg(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 NS=9.81,OS=Math.PI*2;function ur(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 k=0;k<n;k++)o[k]=r[k]*t[k]*(OS/60),a[k]=t[k]/60*OS,s[k]=a[k]*u/l,i[k]=r[k]*l,c[k]=i[k]/u;let d=Nc(s),p=d,m=.5/3.6,f=$n(Ns(s),d,d/m),h=_c(s,c,f),b=$n(Ns(t),Nc(t),250),g=_c(t,o,b).map(k=>k*e.power_scale.value),y,x=p,v;if(e.motorModel?.kind==="ice"){v=Gg(e.motorModel,l,u);let k=$n(0,v.vMax,Math.max(2,Math.ceil(v.vMax/m)+1)),R=k.map(w=>Kg(v,w)),M=k.map(()=>0),S=e.motorPlacement==="front";y={vVehicle:k,fFront:S?R:M,fRear:S?M:R,vMax:v.vMax},x=v.vMax}else e.motorModel&&(y=Vg(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:NS,FG:e.m.value*NS,vMax:x,vVehicle:f,fRad:h,uMotor:b,pMotor:g,vRad:s,fAxle:y,...v?{engine:v}:{}}}var Br=e=>e.motorModel?.kind==="ice"?Oc(1,e.motorPlacement==="front"?"front":"rear"):Oc(Math.max(1,Math.round(e.motorCount??e.driven_wheels?.value??2)),e.motorPlacement??"rear");function VS(e){let t=Br(e);return t.front>=2||t.rear>=2}function BS(e){return VS(e)?e.motorMount??"hub":"chassis"}function Hg(e){if(!e.motorModel)return{front:!1,rear:!0};let t=Br(e);return{front:t.front>0,rear:t.rear>0}}function Um(e){let t=Br(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=BS(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 Yt(e){return Lg(e.brakeModel,e.brakeSetup)}function Vc(e){return On(e.brakeSetup).ideal?"tyre":e.brakeModel||e.brakeModelId?"hydraulic":"balance"}function Xm(e){let t=Vc(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 $S(e,t){if(!(kt(e.motorModel)||!Bn(e).regen))return Ec(qm(ur(e)),t??Yt(e).regen)}function qm(e){return e.fAxle??{vVehicle:e.vVehicle,fFront:e.vVehicle.map(()=>0),fRear:e.fRad.map(t=>t*e.params.driven_wheels.value)}}function zg(e,t=Yt(e)){if(t.mode==="hydraulic")return Dc(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 Yg(e,t=Yt(e)){return{front:t.hydraulic.front.location==="inboard",rear:t.hydraulic.rear.location==="inboard"}}function Wg(e){let t=Yt(e);return{brakeBalanceFront:zg(e,t),brakeInboard:Yg(e,t)}}function GS(e,t=Yt(e)){if(t.mode==="tyre"||t.regen.distribution!=="wheel"||kt(e.motorModel))return;let r=Br(e),n={front:r.front>=2,rear:r.rear>=2};return n.front||n.rear?n:void 0}function Bc(e){let t=Yt(e),r=e.r_dyn.value,n=Yg(e,t),o=zg(e,t),a=GS(e,t),s=t.mode==="hydraulic"||a?$S(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 LN=9.81;function Ug(e,t){let r=KS(e,t);return(n,o,a)=>r(n,o,a).total}var jg={front:0,rear:0,total:0};function KS(e,t){if(kt(e.motorModel))return()=>jg;let r=Yt(e),n=Ec(t,r.regen);if(r.mode==="hydraulic"){let a=ea({mode:"hydraulic",balanceFront:Dc(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 jg;let c=a.demand(a.controlFor(s,i),i),l=c.regenFront+c.regenRear,u=Math.min(s,l),d=l>0?u/l:0;return{front:c.regenFront*d,rear:c.regenRear*d,total:u}}}let o=r.mode==="tyre"?DN(e):()=>Math.min(.99,Math.max(.01,re(e,"brake_balance")));return(a,s,i)=>{if(!(a>0))return jg;let c=o(s,i),l=Math.min(c*a,Nn(n.v,n.front,s)),u=Math.min((1-c)*a,Nn(n.v,n.rear,s));return{front:l,rear:u,total:l+u}}}function DN(e){let t=e.m.value*LN,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 HS(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 Xg={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"},...HS("front"),...HS("rear")},qg={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 Qg(e){let t=Xg[e];return`${t.label}, ${t.section}`.toLowerCase()}function Zg(e){let t=qg[e];return t.section?`${t.section} ${t.label.charAt(0).toLowerCase()}${t.label.slice(1)}`:t.label}var zS=new WeakMap;function sn(e){if(e.brakes)return e.brakes;let t=zS.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},zS.set(e,t)}return t}var Gn=e=>ea(sn(e));var NN=Math.PI/180,Vs=Object.freeze({tbr:1,preloadN:0}),Qm=Object.freeze({tbr:1/0,preloadN:0}),e0=e=>e.faces*e.muClutch*e.rFrictionMm/e.rRampMm;function t0(e,t){if(!(e>0)||Number.isNaN(t))return 0;let r=Math.tan(Math.min(90,t)*NN);return r>0?Math.min(1,e/r):1}function WS(e){if(e>=1)return 1/0;let t=e>0?e:0;return(1+t)/(1-t)}function Zm(e){return e===1/0?1:e>1?(e-1)/(e+1):0}function ra(e,t){return e.tbr===1/0?1/0:(e.preloadN>0?e.preloadN:0)+Zm(e.tbr)*Math.abs(t)}function Gc(e,t,r){let n=o=>o!==void 0&&o>0&&r>0?o/r:0;switch(e.kind){case"open":return Vs;case"spool":return Qm;case"independent":return t==="hubs"?Vs:Qm;case"clutch":{let o=n(e.preloadNm);return t==="hubs"?{tbr:1,preloadN:o}:{tbr:WS(t0(e0(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 $c(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 YS=4;function Jg(e,t){let r=0;for(let a of e)r=Math.max(r,$c(a.m1,a.m2,t));let n=t.tbr>1?t.tbr:1,o=(t.preloadN>0?t.preloadN:0)*(1+n)/2;if(n===1/0||o===1/0)return r;for(let a=0;a+1<e.length;a++){let s=e[a],i=e[a+1].m1-s.m1,c=e[a+1].m2-s.m2,l=p=>{p>0&&p<1&&(r=Math.max(r,$c(s.m1+p*i,s.m2+p*c,t)))};i!==c&&l((s.m2-s.m1)/(i-c));let u=i+c-(1+n)*i,d=i+c-(1+n)*c;u!==0&&l(((1+n)*s.m1+o-s.m1-s.m2)/u),d!==0&&l(((1+n)*s.m2+o-s.m1-s.m2)/d)}return r}function Kc(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=_g(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 d=Wm(b=>ta(e,b)+ta(t,c-b),l.lo,l.hi),p=[{m1:l.c1,m2:l.c2}];for(let b=1;b<=YS&&d!==l.y1;b++){let g=l.y1+(d-l.y1)*b/YS;p.push({m1:e.cap(g),m2:t.cap(c-g)})}let m=Jg(p,Vs),f=Jg(p,Qm);if(!(f>m))return u;let h=(Jg(p,{tbr:s,preloadN:i})-m)/(f-m);return Math.min(a,u+(a-u)*Math.min(1,Math.max(0,h)))}function jS(e,t,r,n,o,a){return r0(e,o,Kc(t,r,n,o,a))}function r0(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 n0(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 d=s<0!=l<0,p=l-s,m=p!==0?i-l*(i-o)/p:NaN;d?m>Math.min(o,i)&&m<Math.max(o,i)||(m=.5*(o+i)):Number.isFinite(m)?Math.abs(m-i)>10*Math.abs(l)&&(m=i+Math.sign(m-i)*10*Math.abs(l)):m=c;let f=e(m),h=f-m;if(u++,d&&h<0==l<0?s*=.5:(o=i,s=l),i=m,c=f,l=h,s<0!=l<0&&Math.abs(i-o)<=r)break}return{x:i,fx:c,evals:u}}function US(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),d=Math.abs(r-t),p=0;for(let m=o;l<a;m*=2){if(p=Math.min(p+m,d),p>d-n)return null;let f=t+u*p,h=e(f),b=h-f;if(l++,!(Math.abs(b)>n))return{x:f,fx:h,evals:l};if(c<0!=b<0)return qS(e,s,c,f,h,b,n,l,a);s=f,c=b}return null}function XS(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),d=u-c;if(!(Math.abs(d)>r))return{x:c,fx:u,evals:l};if(s<0!=d<0)return qS(e,o,s,c,u,d,r,l,n);if(l>=n)return{x:c,fx:u,evals:l};let p=Math.abs(c-o),m=s!==d?d*(c-o)/(s-d):NaN,f=m*i>0?Math.min(Math.abs(m),10*Math.abs(d),2*p):2*p;o=c,s=d,c+=i*f}}function qS(e,t,r,n,o,a,s,i,c){let l=t,u=r,d=n,p=a,m=n,f=o,h=0;for(;i<c&&Math.abs(d-l)>s;){m=(l*p-d*u)/(p-u),f=e(m);let b=f-m;if(i++,!(Math.abs(b)>s))break;b<0==u<0?(l=m,u=b,h===-1&&(p*=.5),h=-1):(d=m,p=b,h===1&&(u*=.5),h=1)}return{x:m,fx:f,evals:i}}function Jm(e,t){return Math.abs(e.fx-e.x)>t?e.x:e.fx}var ON=(e,t)=>{let r=e.brakes?.hydraulic?.[t];return!!r&&r.location==="inboard"&&r.discs===1};function mr(e,t,r){let n=e.driveline?.[t];if(n)return r>=0?n.drive:ON(e,t)?n.coast:n.hubs}var QS=e=>e.tbr>1||e.preloadN>0;var VN=9.81,ZS=["FL","FR","RL","RR"],o0=e=>e==="FL"||e==="FR",ed=e=>o0(e)?"front":"rear",JS={front:["FL","FR"],rear:["RL","RR"]},Yc=()=>({peak:new Map,freeBrake:new Map}),zc=25;function Hc(e,t){let r=Math.max(0,e)/zc,n=Math.floor(r),o=r-n,a=t(n);return o>0?a+o*(t(n+1)-a):a}var Ro=1e-4,BN=.05;function Kn(e,t,r,n=Yc(),o=!1){let a=r,s=e.massTotal,i=n.peak,c=(A,C)=>{let P=`${A}:${C}`,L=i.get(P);return L||(L=lm(we(t,A),Math.max(1,C*zc)),i.set(P,L)),L},l=(A,C)=>({aPeak:Hc(C,P=>c(A,P).aPeak),fyPeak:Hc(C,P=>c(A,P).fyPeak)}),u=n.freeBrake,d=(A,C)=>{let P=`${A}:${C}`,L=u.get(P);if(L===void 0){let E=Math.max(1,C*zc);L=cr(we(t,A),E,0,!0,c(A,C)),u.set(P,L)}return L},p=(A,C)=>C>0?Hc(C,P=>d(A,P)):0,m=Gn(e),f=sn(e),h=A=>f.regen&&f.regenPerWheel?.[A]?Nn(f.regen.v,f.regen[A],a)/2:0,b=h("front"),g=h("rear"),y=(A,C,P)=>{let L=Math.max(0,C[A]),E=l(ed(A),L);return cr(we(t,ed(A)),L,P[A]*E.fyPeak,!0,E)},x=(A,C,P,L,E=!0,_=1)=>{let D=ne=>{let U=Math.max(0,C[ne]),Q=we(t,A),se=l(A,U),de={Fz:U,a:Math.abs(p(A,U)),b:se.fyPeak,slide:U>0?Math.abs(Q.forces({Fz:U,kappa:-1,alpha:0}).Fx):0,cap:ue=>Math.abs(cr(Q,U,ue,!0,se))};return _===1?de:{Fz:U,a:_*de.a,b:_*de.b,slide:_*de.slide,cap:ue=>_*de.cap(ue/_)}},I=ne=>_*Math.abs(P[ne])*l(ed(ne),Math.max(0,C[ne])).fyPeak,[V,O]=JS[A],B=D(V),z=D(O),j=I(V)+I(O),$=Ng(B,z,j,L,A==="front"?b:g),N=E?$:{...$,xLock:0},W=mr(e,A,-1),Z=W&&QS(W)?W:void 0;if(!Z)return{axle:A,eq:N,cap:N};let q=Number.isFinite(L)?L:B.cap(I(V))+z.cap(I(O)),Y=jS(N,B,z,j,Z,q);return{axle:A,eq:N,cap:Y,law:Z,strong:()=>B.cap(I(V))>=z.cap(I(O))?V:O}},v=(A,C,P,L,E=1)=>x(A,C,P,L,!0,E).cap,k=(A,C,P)=>{let L=A.demand,E=m.shares?_s(C,L.front):Is(C,(L.front-L.regenFront)/2,L.regenFront),_=m.shares?_s(P,L.rear):Is(P,(L.rear-L.regenRear)/2,L.regenRear);return{front:Number.isFinite(E)?E:0,rear:Number.isFinite(_)?_:0}},R=A=>({muX:C=>C>0?Math.abs(p(A,C))/C:0,muY:C=>C>0?l(A,C).fyPeak/C:0}),M={front:R("front"),rear:R("rear")},S={lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},w={front:e.trackFront/2e3,rear:e.trackRear/2e3},F=(A,C,P,L,E)=>{let _=L.cap,D=E.cap,I=Ic(m,_,D,a),V={arms:S,halfTrack:w,ayDir:Math.sign(A)};for(let O=0;O<2;O++){let B=k(I,_,D),z={};for(let $ of ZS){let N=Math.max(0,C[$]);z[$]={Fz:N,Fy:Math.abs(P[$])*l(ed($),N).fyPeak,Fx:-(o0($)?B.front:B.rear)/2}}let j=$=>{if(!$.law||!$.strong)return $.cap;let N={axle:$.axle,strong:$.strong(),full:2*$.cap.xNoLock,open:2*$.eq.xNoLock,sense:-1};return r0($.eq,$.law,Lm(N,z,M,V))};_=j(L),D=j(E),I=Ic(m,_,D,a)}return{limit:I,front:_,rear:D}};return{peakAt:l,axle:v,ceiling:(A,C,P)=>{let[L,E]=JS[A];return Math.abs(y(L,C,P)+y(E,C,P))},limitAt:(A,C,P,L=0)=>{let E={FL:0,FR:0,RL:0,RR:0},_=We(e,A,0,a,0,C),D,I=ne=>(D?.ax!==ne&&(D={ax:ne,loads:We(e,A,(ne+L)/VN,a,0,C)}),D.loads),V=um(ne=>ws(P,I(ne),_,l).short,-L,-1),O=P,B={front:0,rear:0},z,j,$=(ne,U=!0)=>{let Q=V.at(ne);E=I(Q),O=ws(P,E,_,l).util;let se=0,de=0,ue=0;for(let ie of ZS){let ve=y(ie,E,O);se+=ve,o0(ie)?de+=ve:ue+=ve}if(B={front:Math.abs(de),rear:Math.abs(ue)},m.mode!=="tyre"){let ie=x("front",E,O,Math.abs(de),U),ve=x("rear",E,O,Math.abs(ue),U);if(o&&(ie.law||ve.law)){let Ie=F(A,E,O,ie,ve);z=Ie.limit,j={front:Ie.front,rear:Ie.rear}}else z=Ic(m,ie.cap,ve.cap,a),j={front:ie.cap,rear:ve.cap};se=-z.force}return se/s},N=n0($,0,Ro),W=Jm(N,Ro),Z=W;if(z?.lockFront||z?.lockRear){let ne=n0(Q=>$(Q,!1),0,Ro);Z=Jm(ne,Ro);let U=US($,ne.x,N.x,Ro,BN);U||$(N.x),W=Jm(U??N,Ro)}let q=V.edge(),Y=q!==void 0&&W<q;Y&&(W=Math.min(0,q),$(W),Z=Math.max(Z,W));let K={loads:E,ceiling:B,limit:z,axles:j};return{ax:W,axUnlocked:Z,...Y?{edge:q}:{},...K,split:()=>K.limit&&K.axles?k(K.limit,K.axles.front,K.axles.rear):{...K.ceiling}}}}}var rd=9.81;function $N(e,t,r){let n=We(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 rA=(e,t)=>t.mode==="hydraulic"&&!!sn(e).regen;function Bs(e,t,r=0,n,o=0,a=1){if(!e.brakes&&e.brakeBalanceFront==null)return e.frontMassFrac;let s=Gn(e);if(s.shares&&s.mode!=="tyre")return s.shares.front;let i=n&&rA(e,s)?aA(e,n):void 0,c=i?nA(a):na,l=i?oA(i,c).shares:eA.get(e);l||eA.set(e,l=new Map);let u=Math.round(Math.abs(t)/.005),d=Math.round(Math.max(0,r)/.25),p=i?Math.round(o/.01):0,m=sA(u,d,p),f=l.get(m);if(f===void 0){let h=-u*.005,b=d*.25,g=e.massTotal*Math.abs(h)*rd;if(i){let y=cA(s,iA(e,i,u,d,p,c),g,b);f=y.front+y.rear>0?y.front/(y.front+y.rear):.5}else f=s.mode==="tyre"?$N(e,h,b):Dg(s,g,b);l.size>5e4&&l.clear(),l.set(m,f)}return f}var eA=new WeakMap;function nd(e,t,r,n,o=0,a=1){let s=Gn(e);if(!rA(e,s))return;let i=Math.round(Math.max(0,r)/(e.massTotal*rd)/.005),c=Math.round(Math.max(0,n)/.25);return cA(s,iA(e,aA(e,t),i,c,Math.round(o/.01),nA(a)),Math.max(0,r),n)}var na=100,nA=e=>e>0&&Number.isFinite(e)?Math.max(1,Math.round(e*na)):na;function oA(e,t){if(t===na)return e;let r=e.roads.get(t);return r||e.roads.set(t,r={shares:new Map,rooms:new Map}),r}var tA=new WeakMap;function aA(e,t){let r=tA.get(e);r||tA.set(e,r=new WeakMap);let n=r.get(t);return n||r.set(t,n={ev:t,tyres:Yc(),shares:new Map,rooms:new Map,speeds:new Map,roads:new Map}),n}var sA=(e,t,r)=>(r*1001+e)*100003+t;function iA(e,t,r,n,o,a=na){let s=sA(r,n,o),i=oA(t,a),c=a===na?1:a/na,l=i.rooms.get(s);if(!l){let u=n*.25,d=o*.01,p=t.speeds.get(n);p||(p={cap:Kn(e,t.ev,u,t.tyres),dragG:-Math.max(0,Yi(e,u).drag)/(e.massTotal*rd)},t.speeds.set(n,p));let{cap:m}=p,f=We(e,d,-r*.005+p.dragG,u),h=Math.abs(d)*e.massTotal*rd,b=x=>{let[v,k]=x==="front"?["FL","FR"]:["RL","RR"],R=h*(x==="front"?e.frontMassFrac:1-e.frontMassFrac),M=c*(m.peakAt(x,Math.max(0,f[v])).fyPeak+m.peakAt(x,Math.max(0,f[k])).fyPeak),S=R>0&&M>0?Math.min(1,R/M):0;return m.axle(x,f,{FL:S,FR:S,RL:S,RR:S},1/0,c)},g,y;l=(x,v)=>(x==="front"?g??=b("front"):y??=b("rear")).regenRoom(v),i.rooms.size>5e4&&i.rooms.clear(),i.rooms.set(s,l)}return l}function td(e,t,r,n){let o=e.demand(r,n),a=o.front-o.regenFront,s=o.rear-o.regenRear,i=o.regenFront>0?Math.min(o.regenFront,t("front",a/2)):0,c=o.regenRear>0?Math.min(o.regenRear,t("rear",s/2)):0;return{front:i===o.regenFront?o.front:a+i,rear:c===o.regenRear?o.rear:s+c,regenFront:i,regenRear:c,demand:o}}function cA(e,t,r,n){if(!(r>0))return td(e,t,1,n);let o=c=>c.front+c.rear,a=e.controlFor(r,n),s=td(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=td(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=td(e,t,l,n);o(u)<r?a=l:(i=l,s=u)}return s}var $s={rel:.003,abs:2,kappa:1e-5,iters:12},Gs={rel:1e-6,abs:.001,kappa:1e-12,iters:40},ad={...Gs,settle:1e-9};function vo(e,t,r,n=$s,o,a){let s=t>=0?1:-1,i=Math.abs(t),c=Math.max(n.abs,n.rel*i),l={kappa:NaN,forces:null},u=o??(S=>{let w=e(S);return l.kappa=S,l.forces=w,w.Fx}),d=u(0);if(Math.abs(d)-i>=0)return od(e,l,0);let p=a?s>0?a.drive:a.brake:void 0;if(p&&p.mag<i)return p.stop;let m=0,f=d,h=Math.abs(d)-i,b=Math.min(.3,Math.max(.004,Math.abs(r)||.02)),g=u(s*b),y=Math.abs(g)-i,x=NaN,v=0;for(;y<0&&b<.3;){let S=Math.min(.3,b*1.9),w=u(s*S),F=Math.abs(w);if(F<Math.abs(g)){x=S,v=w;break}m=b,f=g,h=y,b=S,g=w,y=F-i}if(y<0){let S=HN(u,s,m,f,b,g,x,v);if(S.mag<i){let w=od(e,l,s*S.kappa);return a&&(a[s>0?"drive":"brake"]={mag:S.mag,stop:w}),w}b=S.kappa,y=S.mag-i}let k=s*b,R=n.settle;if(R!==void 0){let S=m,w=h,F=b,T=y;Math.abs(w)<Math.abs(T)&&([S,w,F,T]=[F,T,S,w]);let A=0;for(let C=0;C<n.iters&&b-m>n.kappa;C++){let P=T-w,L=A<2&&Math.abs(P)>1e-12?F-T*(F-S)/P:NaN;if(!(L>m&&L<b)){let D=y-h;L=A<2&&Math.abs(D)>1e-12?(m*y-b*h)/D:.5*(m+b),L>m&&L<b||(L=.5*(m+b)),A=0}let E=Math.abs(u(s*L))-i;k=s*L;let _=E!==T?Math.abs(E*(L-F)/(E-T)):1/0;if(Math.abs(E)<c&&(Math.abs(L-F)<=R||_<=R))break;A=Math.abs(E)>.5*Math.abs(T)?A+1:0,E<0?(m=L,h=E):(b=L,y=E),S=F,w=T,F=L,T=E}return od(e,l,k)}let M=NaN;for(let S=0;S<n.iters&&b-m>n.kappa;S++){let w=y-h,F=Math.abs(w)>1e-12?(m*y-b*h)/w:.5*(m+b);F>m&&F<b||(F=.5*(m+b));let T=Math.abs(u(s*F))-i;if(k=s*F,Math.abs(T)<c&&(R===void 0||Math.abs(F-M)<=R))break;M=F,T<0?(m=F,h=T,y*=.5):(b=F,y=T,h*=.5)}return od(e,l,k)}function od(e,t,r){return t.forces!==null&&Object.is(t.kappa,r)?{kappa:r,forces:t.forces}:{kappa:r,forces:e(r===0?0:r)}}var lA=1e-6,GN=40,KN=(3-Math.sqrt(5))/2;function HN(e,t,r,n,o,a,s,i){let c,l,u,d=-Math.abs(a),p,m,f=-Math.abs(n);if(Number.isNaN(s)){c=.3;let g=.3*(1-lA),y=-Math.abs(e(t*g));if(y>=d)return{kappa:o,mag:-d};[l,p,u,m]=[o,d,r,f],o=g,d=y}else{c=s;let g=-Math.abs(i);[l,p,u,m]=g<=f?[c,g,r,f]:[r,f,c,g]}f<d&&([l,p]=[o,d],o=r,d=f);let h=c-r,b=0;for(let g=0;g<GN;g++){let y=lA*Math.abs(o)+1e-10,x=.5*(r+c);if(Math.abs(o-x)<=2*y-.5*(c-r))break;let v=!0;if(Math.abs(h)>y){let M=(o-l)*(d-m),S=(o-u)*(d-p),w=(o-u)*S-(o-l)*M;S=2*(S-M),S>0&&(w=-w),S=Math.abs(S);let F=h;if(h=b,Math.abs(w)<Math.abs(.5*S*F)&&w>S*(r-o)&&w<S*(c-o)){b=w/S;let T=o+b;(T-r<2*y||c-T<2*y)&&(b=x>=o?y:-y),v=!1}}v&&(h=o>=x?r-o:c-o,b=KN*h);let k=Math.abs(b)>=y?o+b:o+(b>=0?y:-y),R=-Math.abs(e(t*k));R<=d?(k>=o?r=o:c=o,u=l,m=p,l=o,p=d,o=k,d=R):(k<o?r=k:c=k,R<=p||l===o?(u=l,m=p,l=k,p=R):(R<=m||u===o||u===l)&&(u=k,m=R))}return{kappa:o,mag:-d}}var sd=e=>Math.max(2,.003*Math.abs(e)),zN=(e,t)=>Math.max(t.abs,t.rel*Math.abs(e)),a0=.5,YN=.03;function WN(e,t,r,n,o,a=!1){let s=jN(e,t,r,n,o,a);return{kappaM:s.kappaM,kl:s.kl,kr:s.kr,fl:e.at(s.kl),fr:t.at(s.kr)}}function jN(e,t,r,n,o,a){let s=.5*(e.vx+t.vx),i=e.fxAt??(w=>e.at(w).Fx),c=t.fxAt??(w=>t.at(w).Fx),l=w=>{let F=(1+w)*s/e.vx-1,T=(1+w)*s/t.vx-1;return{kappaM:w,kl:F,kr:T,g:i(F)+c(T)-r}},u=zN(r,o),d=Math.max(-a0,Math.min(a0,n)),p=l(d);if(Math.abs(d)>YN){let w=l(.8*d);(p.g-w.g)/(d-w.kappaM)>0||(p=l(0))}if(Math.abs(p.g)<u)return p;let m=p.g<0?1:-1,f=p,h=p,b=.004,g=p,y=p;for(let w=0;w<12;w++){let F=f.kappaM+m*b;if(Math.abs(F)>a0)break;let T=l(F);if(Math.abs(T.g)<u)return T;if(Math.abs(T.g)<Math.abs(g.g)&&(g=T),Math.sign(T.g)!==Math.sign(f.g)){h=T;break}if(m*(T.g-f.g)<=0){if(!a)return g;let A=(Math.sqrt(5)-1)/2,C=y.kappaM,P=T.kappaM,L=l(P-A*(P-C)),E=l(C+A*(P-C));for(let D=0;D<40&&Math.abs(P-C)>1e-7;D++)m*(L.g-E.g)<0?(C=L.kappaM,L=E,E=l(C+A*(P-C))):(P=E.kappaM,E=L,L=l(P-A*(P-C)));let _=m*(L.g-E.g)>0?L:E;if(Math.abs(_.g)<u||Math.sign(_.g)===Math.sign(p.g))return Math.abs(_.g)<Math.abs(g.g)?_:g;f=m*(_.kappaM-f.kappaM)>0?f:y,h=_;break}y=f,f=T,b*=1.9}if(h===p)return g;let x=f,v=h,k=x.g,R=v.g,M=Math.abs(k)<Math.abs(R)?x:v,S=Math.min(1e-7,o.kappa);for(let w=0;w<30&&Math.abs(v.kappaM-x.kappaM)>S;w++){let F=R-k,T=Math.abs(F)>1e-12?(x.kappaM*R-v.kappaM*k)/F:.5*(x.kappaM+v.kappaM),A=Math.min(x.kappaM,v.kappaM),C=Math.max(x.kappaM,v.kappaM);T>A&&T<C||(T=.5*(A+C));let P=l(T);if(M=P,Math.abs(P.g)<u)break;Math.sign(P.g)===Math.sign(k)?(x=P,k=P.g,R*=.5):(v=P,R=P.g,k*=.5)}return M}function uA(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 Wc(e,t,r,n,o,a=$s,s=!1){let i=WN(e,t,r,o,a,s),c=i.fr.Fx-i.fl.Fx,l=ra(n,r);if(Math.abs(c)<=l){let v=r-(i.fl.Fx+i.fr.Fx),k=Math.max(0,Math.abs(v)-sd(r))/2;return{left:{kappa:i.kl,forces:i.fl,want:i.fl.Fx+v/2,short:k},right:{kappa:i.kr,forces:i.fr,want:i.fr.Fx+v/2,short:k},locked:!0,spoolKappa:i.kappaM}}let u=Math.sign(c),d=r/2-u*l/2,p=r/2+u*l/2,m=vo(e.at,d,e.seed||i.kl,a,e.fxAt),f=vo(t.at,p,t.seed||i.kr,a,t.fxAt),h=Math.abs(d-m.forces.Fx)>sd(d),b=Math.abs(p-f.forces.Fx)>sd(p),g=Math.max(0,n.preloadN),y=Zm(n.tbr);h&&!b?f=vo(t.at,uA(m.forces.Fx,u,g,y),f.kappa,a,t.fxAt):b&&!h&&(m=vo(e.at,uA(f.forces.Fx,-u,g,y),m.kappa,a,e.fxAt));let x=(v,k)=>({kappa:v.kappa,forces:v.forces,want:k,short:Math.max(0,Math.abs(k-v.forces.Fx)-sd(k))});return{left:x(m,d),right:x(f,p),locked:!1,spoolKappa:i.kappaM}}var UN={front:["FL","FR"],rear:["RL","RR"]},XN=Object.freeze({Fx:0,Fy:0,Mz:0});function id(e,t,r,n){let o=r;for(let a of["front","rear"]){let[s,i]=UN[a],c=r[s]+r[i],l=mr(e,a,c);if(!l||!(ra(l,c)>0))continue;let u=we(t,a),d=n.alpha[a],p=(a==="front"?e.trackFront:e.trackRear)/2e3,m=n.grip??1,f=x=>v=>u.forces({Fz:x,kappa:v,alpha:d,gamma:0}),h=x=>v=>{let k=u.forces({Fz:x,kappa:v,alpha:d,gamma:0});return{Fx:m*k.Fx,Fy:m*k.Fy,Mz:m*k.Mz}},b=nn(u),g=(x,v)=>{let k=Math.max(0,n.Fz[x]);return{at:k>0?m===1?f(k):h(k):()=>XN,fxAt:k>0?m===1?R=>b(k,R,d,0):R=>m*b(k,R,d,0):()=>0,vx:Math.max(.05,1-v*n.curvature),seed:0}},y=Wc(g(s,p),g(i,-p),c,l,n.seed?.[a]??0);n.seed&&(n.seed[a]=y.spoolKappa),o===r&&(o={...r}),o[s]=y.left.want,o[i]=y.right.want}return o}var oa=["FL","FR","RL","RR"];function s0(e,t,r,n={}){let o={FL:0,FR:0,RL:0,RR:0},a={FL:!1,FR:!1,RL:!1,RR:!1},s={FL:!1,FR:!1,RL:!1,RR:!1};if(t===0&&!e.tvRearDiffN)return{want:o,held:a,left:0,atTop:s};let i=t>=0?1:-1,c=Math.abs(t),l={FL:0,FR:0,RL:0,RR:0},u={FL:1/0,FR:1/0,RL:1/0,RR:1/0};if(i>0){let f=["front","rear"].filter(h=>e.drive[h]);for(let h of f){let[b,g]=h==="front"?["FL","FR"]:["RL","RR"],y=e.drive[h],x=r[b]+r[g];y==="ideal"?(l[b]=r[b],l[g]=r[g],a[b]=a[g]=!0):l[b]=l[g]=x/2}for(let h of oa){let b=e.motorCap?.[h];b!==void 0&&(u[h]=Math.max(0,b))}}else if(e.brake.kind==="ideal")for(let f of oa)l[f]=r[f],a[f]=!0;else{let f=Math.min(1,Math.max(0,e.brake.front));l.FL=l.FR=f/2,l.RL=l.RR=(1-f)/2;for(let h of oa)a[h]=e.brake.abs;if(e.brake.abs){let h=Math.min(1,Math.max(0,e.brake.absUse??.9));if(h<1)for(let b of oa)u[b]=h*r[b]}}let d=Math.max(-1,Math.min(1,e.idealShift??0));if(d!==0){let f={front:i>0?e.drive.front==="ideal":e.brake.kind==="ideal",rear:i>0?e.drive.rear==="ideal":e.brake.kind==="ideal"};for(let h of["front","rear"]){if(!f[h])continue;let[b,g]=h==="front"?["FL","FR"]:["RL","RR"],[y,x]=(e.turn??1)>0?[b,g]:[g,b],[v,k]=d>0?[y,x]:[x,y],R=Math.abs(d)*l[v];l[v]-=R,l[k]+=R}}for(let f of oa){let h=n[f];a[f]&&h!==void 0&&(u[f]=Math.min(u[f],Math.max(0,h)))}let p=qN(c,l,u);for(let f of oa)o[f]=i*p.each[f],s[f]=l[f]>0&&Number.isFinite(u[f])&&p.each[f]>=u[f];let m=e.tvRearDiffN??0;return m&&(o.RL-=m/2,o.RR+=m/2),{want:o,held:a,left:p.left,atTop:s}}function qN(e,t,r){let n={FL:0,FR:0,RL:0,RR:0},o=oa.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((d,p)=>d+t[p],0),l=a/c,u=s.filter(d=>l*t[d]>=r[d]);if(u.length===0){for(let d of s)n[d]=l*t[d];a=0,s=[];break}for(let d of u)n[d]=r[d],a-=r[d];s=s.filter(d=>!u.includes(d))}return{each:n,left:Math.max(0,a)}}var Le=9.81,he=Math.PI/180,QN=8,ZN=.02,JN=12,mA=e=>10*Math.max(Gs.abs,Gs.rel*Math.abs(e)),dA=1e-6,Wt=["FL","FR","RL","RR"],_t=e=>e==="FL"||e==="FR",zn=e=>_t(e)?"front":"rear";function Hs(e,t){let r=we(e,"front"),n=we(e,"rear");return r===n?sa(r,t):{front:sa(r,t),rear:sa(n,t)}}function sa(e,t){return Zb(e,Math.min(t,Or(e)))}var jc=e=>e==="FL"||e==="RL",pA=new WeakMap;function eO(e,t){let r=pA.get(e);r||pA.set(e,r=new Map);let n=100*Math.ceil(2*t*Le/100),o=r.get(n);if(!o){let a=Hs(e,n);o="front"in a?a:{front:a,rear:a},r.set(n,o)}return o}function zs(e,t,r=0,n,o=0,a=1){let s=t?.axG??0;if(t?.balance)return{axG:Number.isFinite(s)?s:0,fx:{FL:0,FR:0,RL:0,RR:0},balance:t.balance};let i=Number.isFinite(t?.tvRearDiffN)?t?.tvRearDiffN:0;if(!(!!s&&Number.isFinite(s))&&!i)return null;let l=e.massTotal*s*Le,u=s>=0?Math.min(1,Math.max(0,t?.driveFrontFrac??0)):Math.min(.99,Math.max(.01,Bs(e,s,r,n,o,a))),d=l*u/2,p=l*(1-u)/2;return{axG:s,fx:{FL:d,FR:d,RL:p-i/2,RR:p+i/2}}}function p0(e,t,r,n){return Math.abs(ia(e,t,r,n!==void 0?{steerMaxDeg:n}:{}).peak.steerDeg)}function f0(e,t,r,n){let o=e.tv;if(!o?.enabled)return 0;let a=IA(o)(t,Math.abs(r),n);return r<0?-a:a}function h0(e,t,r=0,n,o=0,a=0,s,i=1){let c=zs(e,{axG:t,driveFrontFrac:a},r,n,o,i),l=c?c.fx:{FL:0,FR:0,RL:0,RR:0};return c&&s&&n?id(e,n,l,s):l}var Xc=e=>jc(e)?-1:1,ld=(e,t,r,n,o)=>t*e.Fy(t*r,n,t*o);function m0(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 tO(e,t,r){let n=Math.abs(t),o=e.steerFront;if(o&&o.meanDeg.length>1){let u=t>=0,d=r&&o.travelSurface?ks(o,n/he,u?r.FL:r.FR,u?r.FR:r.FL):Ms(o,n/he);return{innerMag:d.innerDeg*he,outerMag:d.outerDeg*he,innerCamber:d.innerCamber,outerCamber:d.outerCamber,atLock:d.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),d=Math.atan(s/Math.max(.05,u-a/2)),p=Math.atan(s/(u+a/2));c=n+i*(d-n),l=n+i*(p-n)}return{innerMag:c,outerMag:l,innerCamber:0,outerCamber:0,atLock:!1}}function ca(e,t,r){let n=(e.toeFrontDeg??0)*he,o=(e.toeRearDeg??0)*he,a=tO(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 ud(e,t,r){if(r.Fz<=0)return 0;let n=zt(we(e,zn(t))),o=Xc(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 fA(e,t,r,n){if(!Qo(e))return null;let o=zt(we(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:ud(o,s,i)}}return kc(e,r/he,a,bo(o.model),{FL:n.FL.travelMm,FR:n.FR.travelMm})}var hA=()=>({totalNm:[],aligningNm:[],lateralNm:[],longitudinalNm:[],jackingNm:[]});function bA(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 rO=Object.freeze({Fx:0,Fy:0,Mz:0});function gA(e,t,r){let n=t==="front"?(r?.FL??0)+(r?.FR??0):(r?.RL??0)+(r?.RR??0),o=mr(e,t,n);return o&&ra(o,n)>0?{F:n,law:o}:null}function dr(e,t,r,n,o,a,s,i,c,l){let u=s?.fx,d=s?.axG??0,{wb:p,lf:m,lr:f,m:h}=m0(e),b=gA(e,"front",u),g=gA(e,"rear",u),y=l?.spool??{front:0,rear:0},x=i!==void 0&&i>0&&Number.isFinite(i)?i:null,v=ee=>x===null?r:Math.sqrt(Math.max(0,ee)*x),k=zt(we(t,"front")),R=zt(we(t,"rear")),M=nn(k),S=nn(R),w=e.trackFront/2e3,F=e.trackRear/2e3,T=!!(e.kinFront&&e.kinRear),A=T&&x===null?l?.travel??yo(e,e.kinFront,e.kinRear,r):null;l&&A&&(l.travel=A);let C=NaN,P=null,L=ee=>{if(!T)return null;if(x===null)return A;let ae=v(ee);return ae!==C&&(C=ae,P=yo(e,e.kinFront,e.kinRear,ae)),P},E={},_=l?.kap??{FL:0,FR:0,RL:0,RR:0},D=e.kinFront?.compliance,I=e.kinRear?.compliance,V=!!(D||I),O=!!(D?.toePerMz||I?.toePerMz),B=ee=>_t(ee)?D:I,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}},j=!1,$=s?.balance,N=0,W=0,Z=0,q=$?eO(t,h):null,Y=(ee,ae)=>ae>0&&q?q[zn(ee)].muX(ae)*ae:0,K=ee=>{let ae=ee/r,Ce=x===null?n+m*ae/r:n+m/x,pe=x===null?n-f*ae/r:n-f/x,me=L(ee),xe=v(ee),ge=$!==void 0,ke=ge?ee/Le*Math.cos(n)+d*Math.sin(n):ee/Le,Re=ge?d*Math.cos(n)-ee/Le*Math.sin(n):d,ye=me?me(ke,Re,n/he,o/he):null,Me=ye?{FL:ye.FL.travel,FR:ye.FR.travel}:void 0,fe=im(e,ke,Re,xe,n/he,o/he,Me,ye?.steeringJacking),be=fe.loads;j=fe.overturned;let Te=ca(e,o,Me),Fe=Te.steer,Gt=0,mt=De=>{let Be=Math.max(0,be[De]),gt=Xc(De),_e=_t(De)?k:R,Ze=B(De),Tr=0,Xt=0;if(Ze){let Ur=z[De];Tr=Ze.toePerFy*Ur.fy+Ze.toePerFx*Ur.fx+Ze.toePerMz*Ur.mz,Xt=Ze.camberPerFy*Ur.fy+Ze.camberPerFx*Ur.fx}let vt=Fe[De]+(ye?gt*ye[De].bumpToe*he:0)+gt*Tr*he,or=vt-(_t(De)?Ce:pe),At=(ye?ye[De].camberRoad:0)*he+gt*(Te.camber[De]+Xt)*he;return{Fz:Be,mir:gt,t:_e,gains:Ze,complianceToe:Tr,steerK:vt,slip:or,camberRad:At}},Kt=(De,Be)=>{let gt=x===null?ae/r:1/x,_e=_t(De)?m:-f,Ze=(jc(De)?1:-1)*(_t(De)?w:F),Tr=(Math.cos(n)-Ze*gt)*Math.cos(Be.steerK)+(Math.sin(n)+_e*gt)*Math.sin(Be.steerK),Xt=_t(De)?M:S;return{at:Be.Fz>0?vt=>Be.t.forces({Fz:Be.Fz,kappa:vt,alpha:Be.mir*Be.slip,gamma:Be.mir*Be.camberRad}):()=>rO,fxAt:Be.Fz>0?vt=>Xt(Be.Fz,vt,Be.mir*Be.slip,Be.mir*Be.camberRad):()=>0,vx:Math.max(.05,Tr),seed:_[De]}};if($){let De=h*(d*Le-($.axDrag??0)),Be=0,gt=()=>({FL:mt("FL"),FR:mt("FR"),RL:mt("RL"),RR:mt("RR")}),_e=or=>({FL:Y("FL",or.FL.Fz),FR:Y("FR",or.FR.Fz),RL:Y("RL",or.RL.Fz),RR:Y("RR",or.RR.Fz)}),Ze=V?null:gt(),Tr=Ze?_e(Ze):null,Xt={},vt={};for(let or=0;or<JN;or++){let At=Ze??gt(),Ur=Tr??_e(At),io=De-N,Vo={...$.spec,turn:o<0?-1:1,...io<0&&$.brakeFront&&$.spec.brake.kind==="shares"?{brake:{...$.spec.brake,front:$.brakeFront(io)}}:{}},Ue={},Qe=s0(Vo,io,Ur,Ue),xr={},Mn={},rs={},co=(Ne,Oe)=>Ue[Ne]!==void 0&&Math.abs(Math.abs(Oe)-Ue[Ne])<=1e-9*Math.max(1,Ue[Ne]);for(let Ne=0;Ne<5;Ne++){let Oe=!1;for(let Xe of["front","rear"]){let[$e,it]=Xe==="front"?["FL","FR"]:["RL","RR"],Dr=Qe.want[$e]+Qe.want[it],Lu=mr(e,Xe,Dr);if(Lu&&ra(Lu,Dr)>0){let He=Ir=>Math.max(0,Math.abs(Dr-Ir.left.forces.Fx-Ir.right.forces.Fx)-mA(Dr)),Ve=rs[Xe],Er=Ve!==void 0&&co($e,Qe.want[$e])&&co(it,Qe.want[it]),dt=Er?Ve:Wc(Kt($e,At[$e]),Kt(it,At[it]),Dr,Lu,y[Xe],ad,!0);if(!Er&&He(dt)>0&&(y[Xe]!==0||_[$e]!==0||_[it]!==0)){let Ir=Wc({...Kt($e,At[$e]),seed:0},{...Kt(it,At[it]),seed:0},Dr,Lu,0,ad,!0);He(Ir)<He(dt)&&(dt=Ir)}y[Xe]=dt.spoolKappa,_[$e]=dt.left.kappa,_[it]=dt.right.kappa;let ns=Qe.held[$e]&&Qe.held[it],os=He(dt);if(ns&&os>0){let Ir=Math.abs(Dr),_r=Math.abs(dt.left.forces.Fx+dt.right.forces.Fx),$i=Qe.want[$e]*Qe.want[it]>=0&&Ir>0,Gi=$i?Math.abs(Qe.want[$e])*_r/Ir:Math.abs(dt.left.forces.Fx),ph=$i?Math.abs(Qe.want[it])*_r/Ir:Math.abs(dt.right.forces.Fx);(Ue[$e]===void 0||Ue[it]===void 0||Gi<Ue[$e]-1e-6||ph<Ue[it]-1e-6)&&(Ue[$e]=Math.min(Gi,Ue[$e]??1/0),Ue[it]=Math.min(ph,Ue[it]??1/0),rs[Xe]=dt,Oe=!0)}xr[$e]={kappa:dt.left.kappa,Fx:dt.left.forces.Fx,Fy:At[$e].mir*dt.left.forces.Fy,short:ns?0:os/2},xr[it]={kappa:dt.right.kappa,Fx:dt.right.forces.Fx,Fy:At[it].mir*dt.right.forces.Fy,short:ns?0:os/2};continue}for(let He of[$e,it]){let Ve=At[He],Er=Qe.want[He];if(Er===0||Ve.Fz<=0){let Sn=Ve.Fz<=0&&!Qe.held[He]?Math.abs(Er):0;Ve.Fz<=0&&Qe.held[He]&&Er!==0&&Ue[He]===void 0&&(Ue[He]=0,Oe=!0);let fh=Ze?Xt[He]??={}:null,cv=Ve.Fz>0?fh?.fy??ld(Ve.t,Ve.mir,Ve.slip,Ve.Fz,Ve.camberRad):0;fh&&(fh.fy=cv),xr[He]={kappa:0,Fx:0,Fy:cv,short:Sn};continue}let dt=Sn=>Ve.t.forces({Fz:Ve.Fz,kappa:Sn,alpha:Ve.mir*Ve.slip,gamma:Ve.mir*Ve.camberRad}),ns=_t(He)?M:S,os=Ze?Xt[He]??={}:null,Ir=Sn=>Sn!==0||!os?ns(Ve.Fz,Sn,Ve.mir*Ve.slip,Ve.mir*Ve.camberRad):os.fx??=ns(Ve.Fz,0,Ve.mir*Ve.slip,Ve.mir*Ve.camberRad),_r=(co(He,Er)?Mn[He]:void 0)??vo(dt,Er,_[He],ad,Ir,Ze?vt[He]??={}:void 0);_[He]=_r.kappa;let $i=mA(Er),Gi=Math.abs(Er-_r.forces.Fx);if(Gi>$i&&Math.abs(_r.forces.Fx)<Math.abs(Er)&&Qe.held[He]){let Sn=Math.abs(_r.forces.Fx);(Ue[He]===void 0||Sn<Ue[He])&&(Ue[He]=Sn,Mn[He]=_r,Oe=!0)}xr[He]={kappa:_r.kappa,Fx:_r.forces.Fx,Fy:Ve.mir*_r.forces.Fy,short:Qe.held[He]?0:Math.max(0,Gi-$i)}}}if(!Oe)break;Qe=s0(Vo,io,Ur,Ue)}W=0,Z=0;for(let Ne=0;Ne<Wt.length;Ne++)(Ue[Wt[Ne]]!==void 0||Qe.atTop[Wt[Ne]])&&(W|=1<<Ne),Ue[Wt[Ne]]!==void 0&&(Z|=1<<Ne);let Xr=0,Pr=0;Be=0;for(let Ne of Wt){let Oe=At[Ne],Xe=xr[Ne];if(E[Ne]={Fz:Oe.Fz,travelMm:ye?.[Ne].travel??0,steerRad:Oe.steerK,slipRad:Oe.slip,camberRad:Oe.camberRad,Fy:Xe.Fy,Fx:Xe.Fx,kappa:Xe.kappa,fxShort:Xe.short+Qe.left/4,lifted:fe.lifted[Ne]},Oe.gains){let it=O&&Oe.gains.toePerMz?ud(Oe.t,Ne,E[Ne]):0;z[Ne]={fy:-Oe.mir*Xe.Fy,fx:Xe.Fx,mz:-Oe.mir*it*1e3};let Dr=z[Ne];Pr=Math.max(Pr,Math.abs(Oe.gains.toePerFy*Dr.fy+Oe.gains.toePerFx*Dr.fx+Oe.gains.toePerMz*Dr.mz-Oe.complianceToe))}let $e=Oe.steerK-n;Xr+=Xe.Fx*(Math.cos($e)-1)-Xe.Fy*Math.sin($e),Be+=Xe.Fy*Math.cos($e)+Xe.Fx*Math.sin($e)}let Lr=Math.abs(Xr-N);if(N=Xr,Lr<ZN&&Pr<dA)break}return Be/h}for(let De=0;De<(V?QN:1);De++){Gt=0;let Be=0,gt={};for(let _e of Wt){let Ze=_t(_e)?b:g;if(Ze&&!gt[_e]){let[Pr,Lr]=_t(_e)?["FL","FR"]:["RL","RR"],Ne=mt(Pr),Oe=mt(Lr),Xe=zn(_e),$e=Wc(Kt(Pr,Ne),Kt(Lr,Oe),Ze.F,Ze.law,y[Xe],Gs);y[Xe]=$e.spoolKappa,gt[Pr]={w:Ne,share:$e.left},gt[Lr]={w:Oe,share:$e.right}}let Tr=gt[_e]?.w??mt(_e),{Fz:Xt,mir:vt,t:or,gains:At,complianceToe:Ur,steerK:io,slip:Vo,camberRad:Ue}=Tr,Qe=u?.[_e]??0,xr,Mn=0,rs=0,co=0,Xr=gt[_e]?.share;if(Xr)_[_e]=Xr.kappa,rs=Xr.kappa,Mn=Xr.forces.Fx,co=Xr.short,xr=vt*Xr.forces.Fy;else if(Qe===0||Xt<=0)xr=ld(or,vt,Vo,Xt,Ue),co=Xt<=0?Math.abs(Qe):0;else{let Pr=Xe=>or.forces({Fz:Xt,kappa:Xe,alpha:vt*Vo,gamma:vt*Ue}),Lr=_t(_e)?M:S,Ne=Xe=>Lr(Xt,Xe,vt*Vo,vt*Ue),Oe=vo(Pr,Qe,_[_e],Gs,Ne);_[_e]=Oe.kappa,rs=Oe.kappa,Mn=Oe.forces.Fx,co=Math.max(0,Math.abs(Qe-Mn)-Math.max($s.abs,$s.rel*Math.abs(Qe))),xr=vt*Oe.forces.Fy}if(E[_e]={Fz:Xt,travelMm:ye?.[_e].travel??0,steerRad:io,slipRad:Vo,camberRad:Ue,Fy:xr,Fx:Mn,kappa:rs,fxShort:co,lifted:fe.lifted[_e]},At){let Pr=O&&At.toePerMz?ud(or,_e,E[_e]):0;z[_e]={fy:-vt*xr,fx:Mn,mz:-vt*Pr*1e3};let Lr=z[_e];Be=Math.max(Be,Math.abs(At.toePerFy*Lr.fy+At.toePerFx*Lr.fx+At.toePerMz*Lr.mz-Ur))}Gt+=xr*Math.cos(io)+Mn*Math.sin(io)}if(Be<dA)break}return Gt/h},ne=ee=>{let ae=We(e,0,d,ee,0,o/he);return ae.FL+ae.FR+ae.RL+ae.RR},U=Math.max(20,3.5*ne(r)/h);if(x!==null){U=4*Le;for(let ee=0;ee<8;ee++){let ae=Math.min(40*Le,3.5*ne(v(U))/h);if(ae<=U)break;U=ae}U=Math.max(20,U)}let Q=ee=>K(ee)-ee,se=Math.max(.001,U*1e-4),de=(ee,ae,Ce,pe)=>{let me=ee,xe=Ce,ge=ae,ke=pe,Re=me;for(let ye=0;ye<40;ye++){let Me=ke-ge,fe=Math.abs(Me)>1e-12?(me*ke-xe*ge)/Me:.5*(me+xe),be=Math.min(me,xe),Te=Math.max(me,xe);fe>be&&fe<Te||(fe=.5*(me+xe));let Fe=Q(fe);if(Re=fe,Math.abs(Fe)<1e-4||Te-be<1e-6)break;Fe<0==ge<0?(me=fe,ge=Fe,ke*=.5):(xe=fe,ke=Fe,ge*=.5)}return Re},ue=(ee,ae,Ce,pe=!1)=>{let me=(ye,Me)=>Ce>0?ye>0&&Me<0:Me>0&&ye<0,xe=ee,ge=ae,ke=ee+Ce*Math.min(Math.abs(ae),U);if(!pe&&Math.abs(ke-ee)>se){let ye=Q(ke);if(me(ge,ye))return{root:de(xe,ge,ke,ye),last:xe};xe=ke,ge=ye}let Re=pe?U/24:Math.max(U/24,Math.abs(ke-ee)/4);for(let ye=1;ye<=24;ye++){let Me=xe+Ce*Re;if(Math.abs(Me)>U)break;let fe=Q(Me);if(me(ge,fe))return{root:de(xe,ge,Me,fe),last:xe};if(pe&&fe*Ce<0&&(fe-ge)*Ce<0)break;xe=Me,ge=fe}return{root:null,last:xe}},ie=c??null;if(c===void 0&&a!==void 0&&Number.isFinite(a)&&Math.abs(a)<=U){let ee=Q(a);if(Math.abs(ee)<=1e-4)Q(a+se)<0&&Q(a-se)>0&&(ie=a);else{let ae=ue(a,ee,Math.sign(ee)).root;ie=ae!==null&&(ae===0||Math.sign(ae)===Math.sign(a))?ae:null}}let ve=ie===null;if(ie===null){let ee=Q(0),ae=Q(se),Ce=Math.abs(ee)<=1e-4,pe=Ce?x!==null?1:o!==0?Math.sign(o):ae>0?1:-1:Math.sign(ee),me=Ce?pe*se:0,xe=Ce?pe>0?ae:Q(-se):ee,ge=ue(me,xe,pe);ie=ge.root??(Ce?0:ge.last)}let Ie=K(ie);if(ve&&o!==0&&x===null){let ee=Math.sign(o);if(ie*ee<=0||(E.RL.Fy+E.RR.Fy)*ee<0){let ae={...E},Ce=j,pe=ee*Math.max(ie*ee+se,n*ee*r*r/f),me=null;if(pe*ee<U){let xe=Q(pe);if(xe*ee>0)me=ue(pe,xe,ee).root;else{let ge=pe+ee*U/24,ke=Q(ge);(ke-xe)*ee>0&&(me=ue(ge,ke,ee,ke*ee<=0).root)}}me!==null&&me*ee>0?(ie=me,Ie=K(ie)):(Object.assign(E,ae),j=Ce)}}let je=m*(E.FL.Fy*Math.cos(E.FL.steerRad)+E.FR.Fy*Math.cos(E.FR.steerRad))-f*(E.RL.Fy+E.RR.Fy);if($){je=0;for(let ee of Wt){let ae=E[ee],Ce=_t(ee)?m:-f,pe=(jc(ee)?1:-1)*(_t(ee)?w:F),me=Math.cos(ae.steerRad),xe=Math.sin(ae.steerRad);je+=Ce*(ae.Fy*me+ae.Fx*xe)-pe*(ae.Fx*me-ae.Fy*xe)}}else if(s||b||g){let ee=ae=>(jc(ae)?1:-1)*(_t(ae)?w:F);for(let ae of Wt){let Ce=E[ae],pe=_t(ae)?m:-f;je+=pe*Ce.Fx*Math.sin(Ce.steerRad)-ee(ae)*Ce.Fx*Math.cos(Ce.steerRad)}}return l&&(l.held=W,l.ceiling=Z),x!==null&&ie<-1e-6?{ay:NaN,cn:NaN,wheels:E,overturned:j,res:NaN}:{ay:ie/Le,cn:je/(h*Le*p),wheels:E,overturned:j,res:Ie-ie}}function nO(e,t,r,n,o,a,s,i=0){let c=20*he,l=.001,u=(h,b)=>{let g=dr(e,t,r,h,n,b,s);return{cn:g.cn-i,ay:g.ay*Le}},d=h=>n===0||i!==0||Math.abs(h)<.05||Math.sign(h)===Math.sign(n),p=(h,b,g,y)=>{let x=u(h,y);if(Math.abs(x.cn)<1e-5)return{beta:h,trimmed:!0};let v=y===void 0?void 0:x.ay,k={pos:{b:h,cn:x.cn,ay:v},neg:{b:h,cn:x.cn,ay:v}},R=null,M=h,S=Math.abs(x.cn);for(let w=0;w<b.length&&!R;w++)for(let F of[k.pos,k.neg]){let T=F===k.pos?1:-1,A=h+T*b[w];if(Math.abs(A)>c)continue;let C=u(A,F.ay);if(Math.abs(C.cn)<S&&d(C.ay)&&(S=Math.abs(C.cn),M=A),C.cn===0&&d(C.ay))return{beta:A,trimmed:!0};if(C.cn<0!=F.cn<0){let P={lo:F.b,hi:A,ayLo:F.ay},L=yA(u,P),E=u(L,F.ay);if(Math.abs(E.cn)<l&&d(E.ay))return R=P,{beta:L,trimmed:!0}}F.b=A,F.cn=C.cn,y!==void 0&&(F.ay=C.ay)}return R?{beta:yA(u,R),trimmed:!0}:g?{beta:M,trimmed:!1}:null},m=[.25,.75,2,5].map(h=>h*he);if(o!==void 0&&Number.isFinite(o)&&Math.abs(o)<=c){let h=p(o,m,!1,a);if(h)return h;if(!s&&i===0&&a!==void 0&&Number.isFinite(a)){let b=oO(e,t,r,n,o,a,c);if(b&&d(b.ay))return{beta:b.beta,trimmed:!0,ay:b.ay}}}let f=[1,3,7,15,20].map(h=>h*he).filter(h=>h<=c);return p(0,f,!0)??{beta:0,trimmed:!1}}function yA(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 d=e(u,o),p=d.cn;if(o!==void 0&&(o=d.ay),i=u,Math.abs(p)<1e-5||Math.abs(n-r)<1e-5)break;p<0==a<0?(r=u,a=p,s*=.5):(n=u,s=p,a*=.5)}return i}function oO(e,t,r,n,o,a,s){let i=(p,m)=>{let f=dr(e,t,r,p,n,void 0,null,void 0,m);return{r:f.res,c:f.cn}},c=o,l=a,u=i(c,l),d=0;for(let p=0;p<aO;p++){let m=i(c+i0,l),f=i(c,l+c0),h=(m.r-u.r)/i0,b=(f.r-u.r)/c0,g=(m.c-u.c)/i0,y=(f.c-u.c)/c0,x=h*y-b*g;if(!Number.isFinite(x)||x===0||Math.abs(x)<lO*(Math.abs(h*y)+Math.abs(b*g)))return null;if(p===0)d=Math.sign(x);else if(Math.sign(x)!==d)return null;if(Math.abs(u.r)<=1e-4&&Math.abs(u.c)<=1e-5)return{beta:c,ay:l};let v=(u.c*b-u.r*y)/x,k=(u.r*g-u.c*h)/x,R=Math.min(1,sO/Math.max(Math.abs(v),1e-300),iO/Math.max(Math.abs(k),1e-300));if(c+=R*v,l+=R*k,Math.abs(c-o)>cO||Math.abs(c)>s||l*a<0)return null;u=i(c,l)}return null}var aO=8,i0=1e-5,c0=.001,sO=1*he,iO=2,cO=5*he,lO=.5;function AA(e,t,r,n,o,a,s,i){let c=dr(e,t,r,n,o,a,s,void 0,i),l=c.ay*Le/r,u={},d=0;for(let f of Wt){let h=c.wheels[f],b=we(t,zn(f)),g=Or(b),y=b.muY(Math.min(h.Fz,g)),x=b.muX(Math.min(h.Fz,g));d+=h.fxShort,u[f]={Fz:h.Fz,steerDeg:h.steerRad/he,slipDeg:h.slipRad/he,camberDeg:h.camberRad/he,Fy:h.Fy,Fx:h.Fx,Mz:ud(b,f,h),gripUtil:y*h.Fz>0?Math.hypot(h.Fy/(y*h.Fz),x*h.Fz>0?h.Fx/(x*h.Fz):0):0,...h.Fz>g?{pastTurnover:!0}:{},lifted:h.lifted}}let p=kc(e,o/he,u,bo(we(t,"front").model),{FL:c.wheels.FL.travelMm,FR:c.wheels.FR.travelMm}),m=ca(e,o,e.kinFront&&e.kinRear?{FL:c.wheels.FL.travelMm,FR:c.wheels.FR.travelMm}:void 0);return{wheels:u,ay:c.ay,ax:s?.axG??0,beta:n/he,yawRate:l*180/Math.PI,steerDeg:o/he,...m.atLock?{lockDeg:(m.steer.FL+m.steer.FR)/2/he}:{},converged:!0,trimmed:!c.overturned,overturned:c.overturned,driving:!1,fxShortfall:d,...p?{steering:p}:{}}}function Yn(e,t,r,n,o,a,s=0){let i=Math.max(8,r),c=aa(e,t,i,n,o,a,s);return n!==0&&o?.driving===void 0&&(c.driving=SO(e,t,i,c,a,s)),c}function aa(e,t,r,n,o,a,s){let i=n*he,c=zs(e,a,r,t),l=o&&Number.isFinite(o.ay)?o.ay*Le:void 0,u=o&&Number.isFinite(o.beta)?o.beta*he:void 0,{beta:d,trimmed:p,ay:m}=nO(e,t,r,i,u,l,c,s),f=AA(e,t,r,d,i,l,c,m),h={...f,trimmed:p&&!f.overturned};return h.driving=n===0?h.trimmed:o?.driving!==void 0&&o.driving&&h.trimmed&&Math.abs(h.beta-o.beta)<=uO,h}var uO=3;function ia(e,t,r,n={}){let o=Math.max(8,r),a=n.direction??1,s=n.yawDemandCn??0,i=n.steerMaxDeg??mO,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=l0.get(e)?.get(t)?.get(l);if(R)return R}let u=(R,M)=>M.trimmed&&Math.abs(M.beta-R.beta)<=md&&Math.abs(M.ay-R.ay)*Le<=dd,d=!1,p=(R,M)=>{let S=aa(e,t,o,a*R,M,c(a*R),s);return u(M,S)?(S.driving=!0,S):(d=S.overturned,null)},m=[aa(e,t,o,0,void 0,c(0),s)],f=null,h=!1,b,g=R=>{let M=m.length-1;for(;M>1&&R.sb*(m[M].beta-m[M-1].beta)>=0;)M--;let S=a*(R.state.ay-m[M].ay)>0,w=F=>R.sb*(F.beta-R.state.beta)>0||a*F.steerDeg>=a*R.state.steerDeg||S&&a*F.ay>=a*R.state.ay;for(;m.length>Math.max(2,M)&&w(m[m.length-1]);)m.pop();b={state:R.state,stall:m[m.length-1]},m.push(R.state),f=Math.abs(R.state.steerDeg)},y=(R,M=!1)=>M||vO(m[m.length-1],R)?kO(e,t,o,a,m,R,c,s):null,x=m[0].trimmed?m[0]:null;if(!x){let R=0;for(let M=xA;M<=i&&!x;M+=xA){let S=aa(e,t,o,a*M,void 0,c(a*M),s);if(S.trimmed){let w=M;x=S;for(let F=0;F<6;F++){let T=.5*(R+w),A=aa(e,t,o,a*T,void 0,c(a*T),s);A.trimmed?(w=T,x=A):R=T}}else R=M}x&&(x.driving=!0,m.push(x))}if(x){let R=Math.abs(x.steerDeg),M=Math.min(u0,100/(o*o)),S=x;for(;R<i;){let w=Math.min(i,R+M),F=p(w,S);if(F){let L=y(F);if(L){g(L);break}if(m.push(F),w>=i||EA(e,a*w))break;Math.abs(F.beta-S.beta)<.5*md&&Math.abs(F.ay-S.ay)*Le<.5*dd&&(M=Math.min(u0,1.5*M)),R=w,S=F;continue}if(M>dO){M*=.5;continue}let T=d,A=!1,C=null;for(let L of pO){let E=Math.min(i,R+L);if(E<=R)continue;let _=p(E,S);if(_){if(C=y(_,!0),C)break;m.push(_),R=E,S=_,M=Math.min(u0,100/(o*o)),A=!0;break}}if(A)continue;if(C){g(C);break}f=R,h=T;let P=T?null:RO(e,t,o,a,m,c,s);P&&g(P);break}}else f=0;let v=m[0];for(let R of m)a*R.ay>a*v.ay&&(v=R);let k={states:m,foldDeg:f,rollover:h,peak:v,...b?{fold:b}:{}};if(l!==null){let R=l0.get(e);R||(R=new WeakMap,l0.set(e,R));let M=R.get(t);M||(M=new Map,R.set(t,M)),M.size>256&&M.clear(),M.set(l,k)}return k}var l0=new WeakMap,mO=90,md=1.5,dd=2.5,u0=5,dO=.002,pO=[.5,1],xA=2.5,wA=.01,Hn=.001,fO=.05,hO=.25,bO=5,gO=2,RA=1e-8,yO=1e-7,xO=1e-6;function CA(e,t,r,n,o,a,s){let i=n*he,c=o.ay*Le,l=b=>{let g=dr(e,t,r,i,b*he,c,zs(e,a(b),r,t));return{g:g.cn-s,ay:g.ay}},u=o.steerDeg,d=l(u),p=u+(u<0?-.001:.001),m=l(p),f=()=>m.g===0||Math.abs(p-u)<RA;for(let b=0;b<40&&Math.sign(d.g)===Math.sign(m.g)&&!f();b++){let g=(m.g-d.g)/(p-u),y=g!==0?p-m.g/g:p+2*(p-u);if(!Number.isFinite(y))return null;let x=2*Math.abs(p-u)+.001;if(y=p+Math.max(-x,Math.min(x,y-p)),u=p,d=m,p=y,m=l(p),Math.abs(p-o.steerDeg)>gO)return null}let h={x:p,ay:m.ay};if(Math.sign(d.g)!==Math.sign(m.g)){let b=u,g=d.g,y=p,x=m.g;for(let v=0;v<60&&x!==0&&Math.abs(y-b)>RA;v++){let k=(b*x-y*g)/(x-g),R=l(k);if(h={x:k,ay:R.ay},R.g===0)break;Math.sign(R.g)===Math.sign(g)?(b=k,g=R.g,x*=.5):(y=k,x=R.g,g*=.5)}}else if(!f())return null;return Math.abs(h.ay-o.ay)*Le>dd?null:{steerDeg:h.x,ay:h.ay}}function Uc(e,t,r,n,o){let a=AA(e,t,r,n.beta*he,n.steerDeg*he,n.ay*Le,zs(e,o(n.steerDeg),r,t));return{...a,trimmed:!a.overturned,driving:!a.overturned}}function RO(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],d=Math.sign(c.beta-u.beta);if(d===0||!u.driving)return null;let p=FA(e,t,r,a,s),m=p(u.beta,u),f=p(c.beta,c);if(!m||!f)return null;let h=n*f.steerDeg>=n*m.steerDeg,b=h?m:f,g=h?f:m,y=h?d:-d,x=null;for(let R=wA;Math.abs(g.beta-c.beta)<=md;R*=1.5){let M=p(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 v=TA(p,n,b,g,x);if(!v)return null;let k=Uc(e,t,r,v,a);return!k.trimmed||Math.abs(k.beta-c.beta)>md||Math.abs(k.ay-c.ay)*Le>dd?null:{state:k,sb:d}}function FA(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=CA(e,t,r,s,i,n,o);if(!c)return null;let l={beta:s,...c};return a.push(l),l}}function vO(e,t){let r=Math.abs(t.beta-e.beta);return r>hO&&r>bO*Math.abs(t.steerDeg-e.steerDeg)}function kO(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 d=o[u],p=Math.sign(a.beta-l.beta);if(p===0||Math.sign(l.beta-d.beta)!==p||!d.driving)return null;let m=FA(e,t,r,s,i),f=m(d.beta,d),h=m(l.beta,l);if(!f||!h||n*h.steerDeg<n*f.steerDeg)return null;let b=f,g=h,y=null;for(let x=wA;p*(a.beta-g.beta)>0;x=Math.min(fO,1.5*x)){let v=m(p*(a.beta-g.beta)>x?g.beta+p*x:a.beta);if(!v)return null;let k=n*v.steerDeg<=n*g.steerDeg;if(!y)k&&(y=[b,g,v]);else if(!k){let R=TA(m,n,...y);if(!R)return null;let M=Uc(e,t,r,R,s);return M.trimmed?{state:M,sb:p}:null}b=g,g=v}return null}function TA(e,t,r,n,o){let a=m=>-t*m.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,d=i-s,p=0;for(let m=0;m<100;m++){let f=.5*(s+i);if(Math.abs(c.beta-f)<=2*Hn-.5*(i-s))break;let h=!0;if(Math.abs(d)>Hn){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 v=d;if(d=p,Math.abs(x)<Math.abs(.5*y*v)&&x>y*(s-c.beta)&&x<y*(i-c.beta)){p=x/y;let k=c.beta+p;(k-s<2*Hn||i-k<2*Hn)&&(p=f>=c.beta?Hn:-Hn),h=!1}}h&&(d=c.beta>=f?s-c.beta:i-c.beta,p=LA*d);let b=e(Math.abs(p)>=Hn?c.beta+p:c.beta+(p>=0?Hn:-Hn));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 b0(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})),d=u[0],p=u[u.length-1],m=l(d),f=l(p);if(m>0||f<0)return null;if(f===0)return Uc(e,t,r,p,i);let h=d;for(let b=0;b<60&&Math.abs(p.beta-d.beta)>1e-9;b++){let g=(d.beta*f-p.beta*m)/(f-m),y=u[0];for(let R of u)Math.abs(R.beta-g)<Math.abs(y.beta-g)&&(y=R);let x=CA(e,t,r,g,y,i,c);if(!x)return null;let v={beta:g,...x};u.push(v),h=v;let k=l(v);if(Math.abs(k)<("steerDeg"in a?yO:xO))break;k<0?(d=v,m=k,f*=.5):(p=v,f=k,m*=.5)}return Uc(e,t,r,h,i)}function MO(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 b0(e,t,r,n.fold,a,{steerDeg:o});let u=typeof a.op=="function"?a.op(o):a.op,d=aa(e,t,r,o,l,u,a.yawDemandCn??0);return d.driving?d:null}function SO(e,t,r,n,o,a){if(!n.trimmed)return!1;let s=n.steerDeg<0?-1:1,{states:i}=ia(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],d=i[Math.min(l+1,i.length-1)],p=Math.abs(d.steerDeg)-Math.abs(u.steerDeg),m=p>0?Math.min(1,Math.max(0,(c-Math.abs(u.steerDeg))/p)):0,f=u.beta+m*(d.beta-u.beta),h=u.ay+m*(d.ay-u.ay);return Math.abs(n.beta-f)<=1&&Math.abs(n.ay-h)<=.05}function ko(e,t,r,n,o){let a=Math.max(8,r),s=n>=0?1:-1,i=Math.abs(n),c=(b,g)=>Yn(e,t,a,s*b,g,o),l=ia(e,t,a,{direction:s,op:o}),{fold:u}=l;if(u&&Math.abs(u.state.steerDeg)<=Ks){if(i>Math.abs(u.state.ay))return kA(e,t,a,s,i,o);if(i>Math.abs(u.stall.ay)){let b=b0(e,t,a,u,{direction:s,op:o},{ayG:i});if(b)return b}}let d=l.states.filter(b=>Math.abs(b.steerDeg)<=Ks),p=d[d.length-1],m=l.states.length>d.length;m&&Math.abs(p.steerDeg)<Ks&&d.push(c(Ks,p));let f=d.findIndex(b=>Math.abs(b.ay)>=i);if(f===0)return Yn(e,t,a,0,void 0,o);if(f>0)return vA(d[f-1],d[f],i,c);let h=PA(d,c,void 0,m||l.foldDeg===null);return h.ay>=i?vA(h.below,h.state,i,c):l.foldDeg!==null&&l.foldDeg<Ks?kA(e,t,a,s,i,o):h.state}var Ks=20;function vA(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 d=0;d<60;d++){let p=a.f===o.f?.5*(o.steer+a.steer):o.steer-o.f*(a.steer-o.steer)/(a.f-o.f),m=n(p,i),f=Math.abs(m.ay)-r;if(Math.abs(f)<u&&(l=m,u=Math.abs(f)),Math.abs(f)<=AO||a.steer-o.steer<=wO)break;f<0?(o={steer:p,f},c===-1&&(a.f*=.5),c=-1):(a={steer:p,f},c===1&&(o.f*=.5),c=1)}return l}var AO=1e-9,wO=1e-7;function PA(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=CO/4,c,l,u,d,p,m,f,h,b=null,g;if(o>0&&o<e.length-1){let R=e[o+1];g=w=>{if(w<s)return t(w,a);let F=t(w,e[o]);return F.ay===e[o].ay?t(w,a):F},c=Math.abs(a.steerDeg),l=Math.abs(R.steerDeg),u=s,d=-Math.abs(e[o].ay);let[M,S]=Math.abs(a.ay)>=Math.abs(R.ay)?[a,R]:[R,a];p=Math.abs(M.steerDeg),m=-Math.abs(M.ay),f=Math.abs(S.steerDeg),h=-Math.abs(S.ay)}else{let R=Math.abs(e[o].lockDeg??e[o].steerDeg),M=R-FO,S=o>0&&n&&M>Math.abs(a.steerDeg)?t(M,a):null;if(!S||Math.abs(S.ay)<=Math.abs(e[o].ay)){let w=t(s,a);return{state:w,below:a,ay:Math.abs(w.ay)}}g=w=>t(w,a),c=Math.abs(a.steerDeg),l=R,u=M,d=-Math.abs(S.ay),b=S,p=R,m=-Math.abs(e[o].ay),f=c,h=-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 S=!0;if(Math.abs(y)>i){let A=(u-p)*(d-h),C=(u-f)*(d-m),P=(u-f)*C-(u-p)*A;C=2*(C-A),C>0&&(P=-P),C=Math.abs(C);let L=y;if(y=x,Math.abs(P)<Math.abs(.5*C*L)&&P>C*(c-u)&&P<C*(l-u)){x=P/C;let E=u+x;(E-c<2*i||l-E<2*i)&&(x=M>=u?i:-i),S=!1}}S&&(y=u>=M?c-u:l-u,x=LA*y);let w=Math.abs(x)>=i?u+x:u+(x>=0?i:-i),F=g(w),T=-Math.abs(F.ay);T<=d?(w>=u?c=u:l=u,f=p,h=m,p=u,m=d,u=w,d=T,b=F):(w<u?c=w:l=w,T<=m||p===u?(f=p,h=m,p=w,m=T):(T<=h||f===u||f===p)&&(f=w,h=T))}let v=b??t(s,a),k=Math.abs(v.steerDeg)>s?e[o]:a;return{state:v,below:k,ay:Math.abs(v.ay)}}var CO=.001,FO=.01,LA=(3-Math.sqrt(5))/2;function kA(e,t,r,n,o,a){let s=l=>Math.abs(Yn(e,t,r,n*l,void 0,a).ay),i=0,c=Ks;if(s(c)<o)return Yn(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 Yn(e,t,r,n*.5*(i+c),void 0,a)}function g0(e,t,r,n,o){let a=ko(e,t,r,n,o);return a.steering?Math.abs(a.steering.totalNm):NaN}function y0(e,t,r,n,o){if(!Qo(e))return NaN;let a=n<0?-1:1,s=Math.abs(n),i=ko(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),d=c+l,p=Yn(e,t,r,a*u,void 0,o),m=Yn(e,t,r,a*d,void 0,o),f=p.steering?Math.abs(p.steering.totalNm):NaN,h=m.steering?Math.abs(m.steering.totalNm):NaN,b=Math.abs(m.ay)-Math.abs(p.ay);if(Number.isFinite(f)&&Number.isFinite(h)&&b>=.01||l===.4&&Number.isFinite(f)&&Number.isFinite(h)&&b>.001)return(h-f)/b}return NaN}function d0(e,t,r,n,o,a,s){let i=Math.max(8,r),c=s!==void 0&&Number.isFinite(s)?s*Le:void 0,l=dr(e,t,i,n*he,o*he,c,zs(e,a,i,t)),u=0;for(let d of Wt)u+=l.wheels[d].fxShort;return{ay:l.ay,cn:l.cn,fxShortfall:u}}function x0(e,t,r,n,o){let a=Math.max(8,r),s=ko(e,t,a,n,o),i=.5,c=d0(e,t,a,s.beta+i,s.steerDeg,o).cn,l=d0(e,t,a,s.beta-i,s.steerDeg,o).cn;return(c-l)/(2*i*he)*e.massTotal*Le*(e.wheelbase/1e3)}function R0(e,t,r,n){let o=Math.max(8,r),{branch:a,opts:s}=TO(e,t,o,n);return DA(e,t,o,a,s)}function TO(e,t,r,n){if(!e.tv?.enabled||n?.balance){let s=n?{op:n}:{};return{branch:ia(e,t,r,s),opts:s}}let o=p0(e,t,r),a={op:s=>{let i=f0(e,r,s,o);return i===0?n:{axG:n?.axG??0,driveFrontFrac:n?.driveFrontFrac,tvRearDiffN:i}}};return{branch:ia(e,t,r,a),opts:a}}function DA(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 Uc(e,t,r,n.peak,a);let i=(l,u)=>aa(e,t,r,l,u,a(l),s),c=n.states[0].driving||!n.peak.driving?n.states:n.states.slice(1);return PA(c,i,c.indexOf(n.peak),n.foldDeg===null).state}function v0(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(Le*o)),s=(n.betaMaxDeg??10)*he,i=(n.deltaMaxDeg??10)*he,[c,l]=n.betaRangeDeg?[n.betaRangeDeg[0]*he,n.betaRangeDeg[1]*he]:[-s,s],[u,d]=n.deltaRangeDeg?[n.deltaRangeDeg[0]*he,n.deltaRangeDeg[1]*he]:[-i,i],{lf:p,lr:m}=m0(e),f=o===void 0?0:m/o,h=o===void 0?0:(p+m)/o,b=n.nLines??9,g=n.nPts??21,y=n.steering!==!1&&Qo(e),x=y?bo(we(t,"front").model):void 0,v=(O,B,z,j)=>z===1?O:O+(B-O)*j/(z-1),k=e.tv?.enabled?p0(e,t,a):0,R=O=>{let B=f0(e,a,O/he,k);return!n.axG&&B===0?null:zs(e,{axG:n.axG??0,driveFrontFrac:n.driveFrontFrac,tvRearDiffN:B},a,t)},{lf:M,lr:S}=m0(e),w=n.reserves?Hs(t,e.massTotal*Le*1.2):null,F=O=>w?Dn(w,{FL:O.FL,FR:O.FR,RL:O.RL,RR:O.RR},{lf:M,lr:S}):null,T=[],A={ay:[],cn:[]},C=0;for(let O=0;O<b;O++){let B=v(u,d,b,O),z=R(B),j=[],$=[],N=[],W=[],Z=w?{stabil:[],agil:[]}:void 0,q=y?hA():void 0,Y;for(let U=0;U<g;U++){let Q=v(c,l,g,U),se=dr(e,t,a,Q,B,Y,z,o);if(Y=Number.isFinite(se.ay)?se.ay*Le:void 0,j.push(se.ay),$.push(se.cn),N.push(Q/he),W.push(B/he),Z){let de=F(se.wheels);Z.stabil.push(de.stabil),Z.agil.push(de.agil)}q&&bA(q,fA(e,t,B,se.wheels)),Math.abs(se.ay)>C&&(C=Math.abs(se.ay))}T.push({label:`\u03B4 ${(B/he).toFixed(0)}\xB0`,ay:j,cn:$,betaDeg:N,deltaDeg:W,reserve:Z,steering:q});let K=null,ne=1/0;for(let U=1;U<$.length;U++){if(!Number.isFinite($[U-1])||!Number.isFinite($[U])||$[U-1]!==0&&$[U-1]<0==$[U]<0)continue;let Q=$[U-1]===$[U]?0:$[U-1]/($[U-1]-$[U]),se=j[U-1]+Q*(j[U]-j[U-1]);if(o===void 0&&B!==0&&Math.abs(se)>=.05&&Math.sign(se)!==Math.sign(B))continue;let de=Math.abs(N[U-1]+Q*(N[U]-N[U-1])-f/he);de<ne&&(ne=de,K=se)}K!==null&&(A.ay.push(K),A.cn.push(0))}let P=[];for(let O=0;O<b;O++){let B=v(c,l,b,O),z=[],j=[],$=[],N=[],W=w?{stabil:[],agil:[]}:void 0,Z=y?hA():void 0,q;for(let Y=0;Y<g;Y++){let K=v(u,d,g,Y),ne=dr(e,t,a,B,K,q,R(K),o);if(q=Number.isFinite(ne.ay)?ne.ay*Le:void 0,z.push(ne.ay),j.push(ne.cn),$.push(B/he),N.push(K/he),W){let U=F(ne.wheels);W.stabil.push(U.stabil),W.agil.push(U.agil)}Z&&bA(Z,fA(e,t,K,ne.wheels))}P.push({label:`\u03B2 ${(B/he).toFixed(0)}\xB0`,ay:z,cn:j,betaDeg:$,deltaDeg:N,reserve:W,steering:Z})}let L=.5*he,E=R(h),_,D;if(o===void 0)_=(dr(e,t,a,f+L,h,void 0,E,o).cn-dr(e,t,a,f-L,h,void 0,E,o).cn)/(2*L),D=(dr(e,t,a,f,h+L,void 0,R(h+L),o).cn-dr(e,t,a,f,h-L,void 0,R(h-L),o).cn)/(2*L);else{let O=(j,$)=>dr(e,t,a,j,$,void 0,R($),o).cn,B=(j,$,N)=>Number.isFinite(j)?(-3*j+4*$-N)/(2*L):(N-$)/L,z=O(f,h);_=-B(z,O(f-L,h),O(f-2*L,h)),D=B(z,O(f,h+L),O(f,h+2*L))}let I=0;if(E&&E.axG){let O=dr(e,t,a,f,h,void 0,E,o),B=0;for(let z of Wt)B+=O.wheels[z].fxShort;I=B/Math.abs(e.massTotal*E.axG*Le)}let V=A.ay.reduce((O,B)=>Math.max(O,Math.abs(B)),0);return{isoBeta:P,isoDelta:T,trim:A,maxAy:C,stability:_,control:D,speed:o===void 0?a:Math.sqrt(V*Le*o),...o!==void 0?{radius:o}:{},axG:E?.axG??0,axShortfall:I,...x?{steeringAligningSource:x}:{}}}function EA(e,t){return ca(e,t*he).atLock}function PO(e,t,r,n,o=Kn(e,t,r)){let a=r,s=e.massTotal,i=Wt.filter(g=>_t(g)?n.drivenFront:n.drivenRear),c=o.peakAt,l={front:n.drivenFront?mr(e,"front",1):void 0,rear:n.drivenRear?mr(e,"rear",1):void 0},u=new Map,d=(g,y)=>{let x=`${g}:${y}`,v=u.get(x);if(v===void 0){let k=Math.max(1,y*zc);v=cr(we(t,g),k,0,!1,c(g,k)),u.set(x,v)}return v},p=(g,y)=>y>0?Hc(y,x=>d(g,x)):0,m=(g,y,x,v)=>{let k=we(t,g),R=E=>{let _=Math.max(0,x[E]),D=c(g,_);return{Fz:_,a:p(g,_),b:D.fyPeak,slide:0,cap:I=>_>0?cr(k,_,I,!1,D):0}},[M,S]=g==="front"?["FL","FR"]:["RL","RR"],w=R(M),F=R(S),T=v[M]*w.b,A=v[S]*F.b,C=w.cap(T)+F.cap(A),P=Kc(w,F,T+A,y,C);return{l:M,r:S,full:P,asHeld:()=>({axle:g,strong:w.cap(T)>=F.cap(A)?M:S,full:P,open:Kc(w,F,T+A,Vs,C),sense:1})}},f=g=>({muX:y=>y>0?p(g,y)/y:0,muY:y=>y>0?c(g,y).fyPeak/y:0}),h={front:f("front"),rear:f("rear")},b=g=>({arms:{lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},halfTrack:{front:e.trackFront/2e3,rear:e.trackRear/2e3},ayDir:Math.sign(g)});return{limitAt:(g,y,x,v=0)=>{let k={FL:0,FR:0,RL:0,RR:0},R=We(e,g,0,a,0,y),M,S=I=>(M?.ax!==I&&(M={ax:I,loads:We(e,g,(I+v)/Le,a,0,y)}),M.loads),w=um(I=>ws(x,S(I),R,c).short,-v,1),F=x,T={FL:0,FR:0,RL:0,RR:0},A,C=I=>{let V=w.at(I);k=S(V),F=ws(x,k,R,c).util;let O={FL:0,FR:0,RL:0,RR:0};T=O;let B=0,z=n.diffYaw?{fx:{FL:0,FR:0,RL:0,RR:0},axles:[]}:null;for(let j of i){let $=l[zn(j)];if($){if(jc(j)){let q=m(zn(j),$,k,F);B+=q.full,O[q.l]=O[q.r]=q.full/2,z&&(z.fx[q.l]=z.fx[q.r]=q.full/2,z.axles.push(q.asHeld()))}continue}let N=Math.max(0,k[j]),W=c(zn(j),N),Z=cr(we(t,zn(j)),N,F[j]*W.fyPeak,!1,W);B+=Z,O[j]=Z,z&&(z.fx[j]=Z)}if(z){let j={};for(let $ of Wt){let N=Math.max(0,k[$]);j[$]={Fz:N,Fy:F[$]*c(zn($),N).fyPeak,Fx:z.fx[$]}}for(let $ of z.axles){let N=Lm($,j,h,b(g))-$.full;B+=N;let[W,Z]=$.axle==="front"?["FL","FR"]:["RL","RR"];O[W]+=N/2,O[Z]+=N/2}}if(A)for(let j of A){let $=0;for(let N of j.wheels)$+=O[N];$>j.cap&&(B-=$-j.cap)}return B/s},P=()=>{let I=XS(C,-v,Ro).fx,V=w.edge();return V!==void 0&&I>V&&(I=V,C(I)),{ax:I,loads:k,wheels:T}},L=P(),E=n.motorCaps;if(!E)return L;if(!E.some(I=>I.wheels.reduce((V,O)=>V+L.wheels[O],0)>I.cap))return{...L,held:L.ax};A=E;let D=P();return{...L,held:D.ax,heldWheels:D.wheels}}}}var cd=.05,MA=.001,SA=16,pd=8;function k0(e,t,r,n){let o=Math.max(pd,r),a=n.nSteer??7,s=e.tv?.enabled?p0(e,t,o,n.steerMaxDeg):0,i=N=>{let W=f0(e,o,N,s);return W===0?void 0:{axG:0,tvRearDiffN:W}},c=n.yawDemandCn??0,l={op:i,yawDemandCn:c,...n.steerMaxDeg!==void 0?{steerMaxDeg:n.steerMaxDeg}:{}},u=ia(e,t,o,l),d=N=>{let W={},Z={};for(let q of Wt)W[q]=N.wheels[q].slipDeg*he,Z[q]=Math.min(1,N.wheels[q].gripUtil);return{steerDeg:N.steerDeg,ayMs:Math.max(0,N.ay*Le),ayG:N.ay,slip:W,util:Z,scrub:N.ay>0?LO(N,e.massTotal):0}},p=null,m=N=>{if(p&&N===p.steerDeg)return d(p);let W=MO(e,t,o,u,N,l);if(W)return d(W);let Z=u.states[0];for(let q of u.states)q.steerDeg<=N&&(Z=q);return d(Z)},f=u.peak.driving&&u.peak.ay>0?DA(e,t,o,u,l):null,h=f?Math.max(0,f.ay*Le):0,b=f?[...u.states.filter(N=>N.steerDeg<f.steerDeg),f]:u.states,g=f?b.findIndex(N=>N.ay*Le>=.995*h):0,y=b[g].steerDeg,{fold:x}=u;if(f&&x&&u.peak===x.state){let N=.995*h/Le,W=u.states.indexOf(x.stall),Z=W-1;for(;Z>0&&u.states[Z].beta===x.stall.beta;)Z--;let q=Math.sign(x.stall.beta-u.states[Z].beta),Y=W;for(;Y>0&&u.states[Y].ay>=N&&Math.sign(u.states[Y].beta-u.states[Y-1].beta)!==-q;)Y--;u.states[Y].ay<N&&(p=b0(e,t,o,x,l,{ayG:N},u.states.slice(Y,W+1)))}if(p)y=p.steerDeg;else if(g>0){let N=b[g-1].steerDeg,W=y;for(let Z=0;Z<8&&W-N>.001;Z++){let q=.5*(N+W);m(q).ayMs>=.995*h?W=q:N=q}y=W}let v=[];for(let N=0;N<(h>0?a:1);N++){let W=N/(a-1);v.push(m(y*(W+Math.sin(Math.PI/2*W))/2))}v[0].ayMs=0;let k=[],R=[],M=[],S=[],w=[],F=Kn(e,t,o,void 0,n.diffYaw===!0),T=PO(e,t,o,n,F),A=n.axDrag??0,C=N=>{let W=F.limitAt(N.ayMs/Le,N.steerDeg,N.util,A+N.scrub);return{axD:W.edge!==void 0&&W.edge>0?W.edge:W.ax,locked:W.axUnlocked-W.ax>cd}},P=N=>{let W=T.limitAt(N.ayMs/Le,N.steerDeg,N.util,A+N.scrub);return{axA:W.ax,wA:{wheels:W.wheels,held:W.held??W.ax,...W.heldWheels?{heldWheels:W.heldWheels}:{}}}},L=v.map(N=>({p:N,...P(N),...C(N)})),E=[];for(let N=0;N+1<L.length;N++){let W=L[N],Z=L[N+1],q=[];W.locked!==Z.locked?q.push({read:C,past:Y=>Y.locked===Z.locked,braking:!0}):(Z.axA>W.axA+cd&&q.push({read:P,past:Y=>(Y.axA??-1/0)>W.axA}),-Z.axD>-W.axD+cd&&q.push({read:C,past:Y=>-(Y.axD??0)>-W.axD}));for(let{read:Y,past:K,braking:ne}of q){let U=W.p.steerDeg,Q=Z.p.steerDeg,se=null,de=W.axD,ue=Z.axD;for(let ie=0;ie<SA&&Q-U>MA&&!(ne&&Math.abs(ue-de)<=cd);ie++){let ve=.5*(U+Q),Ie=m(ve),je=Y(Ie);K(je)?(Q=ve,se={p:Ie,r:je},ue=je.axD??ue):(U=ve,de=je.axD??de)}if(se){let{p:ie,r:ve}=se,Ie=ve.axD!==void 0&&ve.locked!==void 0?{axD:ve.axD,locked:ve.locked}:C(ie),je=ve.axA!==void 0&&ve.wA!==void 0?{axA:ve.axA,wA:ve.wA}:P(ie);E.push({p:ie,...je,...Ie})}}}L.push(...E),L.sort((N,W)=>N.p.steerDeg-W.p.steerDeg);let _=N=>N.axA+A+N.p.scrub,D=.001*Math.max(1,v[v.length-1].ayMs),I=[];for(let N=0;N+1<L.length;N++){let W=L[N],Z=L[N+1];if(!(_(W)>=0&&_(Z)<0))continue;let q=W.p.steerDeg,Y=Z.p.steerDeg,K=null,ne=null;for(let se=0;se<SA&&Y-q>MA;se++){let de=.5*(q+Y),ue=m(de),ie=P(ue);_({p:ue,axA:ie.axA})>=0?(q=de,K={p:ue,wA:ie.wA}):(Y=de,ne={p:ue,wA:ie.wA})}let U=K??ne,Q=U?.p;if(U&&Q&&Q.ayMs>W.p.ayMs&&Q.ayMs<Z.p.ayMs){let se=-(A+Q.scrub);I.push({p:Q,axA:se,wA:{wheels:U.wA.wheels,held:Math.min(U.wA.held,se)},steady:!0,...C(Q)})}}L.push(...I),L.sort((N,W)=>N.p.steerDeg-W.p.steerDeg);let V=!1;for(let{p:N,axA:W,wA:Z,axD:q,steady:Y}of L){let K=k.length-1,ne=K>=0&&(Y||V?!(N.ayMs>k[K]):N.ayMs-k[K]<D);V=Y===!0&&!ne,ne?(W>R[K]&&(M[K]=Z),R[K]=Math.max(R[K],W),S[K]=Math.min(S[K],q)):(k.push(N.ayMs),R.push(W),M.push(Z),S.push(q),w.push(N.scrub))}for(let N=k.length-2;N>=0;N--)R[N+1]>R[N]&&(M[N]=M[N+1]),R[N]=Math.max(R[N],R[N+1]),S[N]=Math.min(S[N],S[N+1]);let O=k[k.length-1],B=e.massTotal,z=M.map(({wheels:N})=>({FL:N.FL/B,FR:N.FR/B,RL:N.RL/B,RR:N.RR/B})),j=N=>N?{FL:N.FL/B,FR:N.FR/B,RL:N.RL/B,RR:N.RR/B}:void 0,$=n.motorCaps?{axAccelHeld:M.map(N=>N.held),axAccelWheelsHeld:M.map(N=>j(N.heldWheels))}:{};return{ayMax:O,ay:k,axAccel:R,axAccelWheels:z,...$,axDecel:S,axScrub:w,rollover:u.rollover,atLock:f!==null&&EA(e,f.steerDeg)}}function LO(e,t){let r=e.beta*he,n=0;for(let o of Wt){let a=e.wheels[o],s=a.steerDeg*he-r;n+=a.Fx*(Math.cos(s)-1)-a.Fy*Math.sin(s)}return n/t}var BJ=Math.PI/180,$J={speeds:Array.from({length:23},(e,t)=>8+t),steerMaxDeg:14,steerSteps:29};function _A(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 Ys={enabled:!1,kp:3e3,ffLow:150,ffHigh:300,vLow:18,vHigh:25},IA=e=>_A(e.ffLow,e.ffHigh,e.vLow,e.vHigh);var cn={power_limit_kw:{value:0,label:"battery power limit (0 = none)",unit:"kW"},v_limit_endurance:{value:0,label:"endurance speed limit (0 = none)",unit:"km/h"},endurance_reserve:{value:0,label:"endurance energy reserve (0 = flat out)",unit:"%"},grip_scale:{value:1,label:"grip scale (rig \u2192 road)",unit:"-"},stiffness_scale:{value:1,label:"stiffness scale (rig \u2192 road)",unit:"-"},camber_front_deg:{value:0,label:"static camber front (\u2212 top in)",unit:"\xB0"},camber_rear_deg:{value:0,label:"static camber rear (\u2212 top in)",unit:"\xB0"},cg_height:{value:300,label:"CG height",unit:"mm"},tire_vertical_rate:{value:100,label:"tyre vertical rate",unit:"N/mm"},tire_vertical_damping:{value:0,label:"tyre vertical damping",unit:"N\xB7s/mm"},arb_front:{value:20,label:"ARB front (@wheel)",unit:"N/mm"},arb_rear:{value:15,label:"ARB rear (@wheel)",unit:"N/mm"},heave_spring_front:{value:0,label:"Heave spring front (@wheel)",unit:"N/mm"},heave_spring_rear:{value:0,label:"Heave spring rear (@wheel)",unit:"N/mm"},unsprung_mass:{value:8,label:"unsprung mass/corner",unit:"kg"},brake_balance:{value:.6,label:"brake balance (front)",unit:"-"},damper_front:{value:2.5,label:"damper front",unit:"N\xB7s/mm"},damper_rear:{value:2.5,label:"damper rear",unit:"N\xB7s/mm"},cop_long:{value:.5,label:"CoP aft of front",unit:"\xB7wb"},cop_height:{value:300,label:"CoP height",unit:"mm"},ride_height_front:{value:30,label:"static ride height front (laden)",unit:"mm"},ride_height_rear:{value:35,label:"static ride height rear (laden)",unit:"mm"},I_yaw:{value:295,label:"yaw inertia Izz",unit:"kg\xB7m\xB2"},I_roll:{value:95,label:"roll inertia Ixx",unit:"kg\xB7m\xB2"},I_pitch:{value:380,label:"pitch inertia Iyy",unit:"kg\xB7m\xB2"},chassis_torsion:{value:0,label:"chassis torsional stiffness (0 = rigid)",unit:"N\xB7m/\xB0"},I_twist_front:{value:0,label:"twist inertia, front end (0 = lumped)",unit:"kg\xB7m\xB2"},I_twist_rear:{value:0,label:"twist inertia, rear end (0 = lumped)",unit:"kg\xB7m\xB2"},I_wheel:{value:0,label:"rotating inertia per wheel",unit:"kg\xB7m\xB2"},I_rotor:{value:0,label:"driveline inertia at the motor",unit:"kg\xB7m\xB2"},ackermann_pct:{value:50,label:"Ackermann",unit:"%"},toe_front_deg:{value:0,label:"static toe front (+ in)",unit:"\xB0"},toe_rear_deg:{value:0,label:"static toe rear (+ in)",unit:"\xB0"},spring_front:{value:35,label:"spring front (@spring)",unit:"N/mm"},spring_rear:{value:40,label:"spring rear (@spring)",unit:"N/mm"},mr_front:{value:1,label:"motion ratio front",unit:"-"},mr_rear:{value:1,label:"motion ratio rear",unit:"-"},track_front:{value:1200,label:"track front",unit:"mm"},track_rear:{value:1200,label:"track rear",unit:"mm"},wheelbase:{value:1535,label:"wheelbase",unit:"mm"},rc_front:{value:30,label:"roll centre front",unit:"mm"},rc_rear:{value:40,label:"roll centre rear",unit:"mm"},tv_enabled:{value:0,label:"torque vectoring",unit:"0/1"},tv_kp:{value:3e3,label:"TV yaw-rate gain",unit:"N per rad/s"},tv_ff_low:{value:150,label:"TV feedforward, low speed",unit:"N"},tv_ff_high:{value:300,label:"TV feedforward, high speed",unit:"N"},tv_v_low:{value:18,label:"TV feedforward ramp start",unit:"m/s"},tv_v_high:{value:25,label:"TV feedforward ramp end",unit:"m/s"}},DO=["k_yaw","k_roll","k_pitch"];function qc(e){for(let t of DO)delete e[t];for(let t of Object.keys(cn)){let r=e[t];if(!r){e[t]={...cn[t]};continue}e[t]={...r,label:cn[t].label,unit:cn[t].unit}}return e}function re(e,t){return e[t]?.value??cn[t].value}function la(e){let t=re(e,"chassis_torsion");return t>0&&Number.isFinite(t)?t:void 0}function Qc(e,t){if(la(e)===void 0)return;let r=re(e,t==="front"?"I_twist_front":"I_twist_rear");return r>0&&Number.isFinite(r)?r:void 0}function fd(e){let t=(r,n)=>e[r]?.value??n;return{enabled:t("tv_enabled",0)>=.5,kp:t("tv_kp",Ys.kp),ffLow:t("tv_ff_low",Ys.ffLow),ffHigh:t("tv_ff_high",Ys.ffHigh),vLow:t("tv_v_low",Ys.vLow),vHigh:t("tv_v_high",Ys.vHigh)}}var NA=[10,25,50,100,200,300];function M0(e,t,r,n,o){let s=NA.map(i=>Math.round(i<=25?r*i:r*25+n*(i-25)));return{id:e,label:t,speedMmS:[...NA],reboundN:s,bumpN:s.map(i=>Math.round(i*o))}}var hd={name:"Generic FS damper",curves:[M0("c1","Soft",1.6,1,.65),M0("c2","Medium",3,1.6,.65),M0("c3","Firm",8,2.4,.65)]};function bd(e){let t=e.curves.length;return t>0?e.curves[Math.floor((t-1)/2)].id:""}var Mo=25;function Ws(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 OA(e,t){return t>=0?Ws(e.rebound,t):-Ws(e.bump,-t)}function VA(e,t,r){return t*OA(e,t*r)}var S0=(e,t)=>e.curves.find(r=>r.id===t);function Zc(e,t){let r=S0(e,bd(e)),n=(t&&S0(e,t.bump))??r,o=(t&&S0(e,t.rebound))??r;return{bump:{speedMmS:n?.speedMmS??[],forceN:n?.bumpN??[]},rebound:{speedMmS:o?.speedMmS??[],forceN:o?.reboundN??[]}}}var gd=5e3;function Jc(e,t){let r=t>0?t:1,n=[],o=[],a=e.bump.speedMmS.map(c=>c/r).filter(c=>c<gd),s=e.rebound.speedMmS.map(c=>c/r).filter(c=>c<gd),i=c=>{n.push(c),o.push(VA(e,r,c))};i(-gd);for(let c=a.length-1;c>=0;c--)i(-a[c]);i(0);for(let c of s)i(c);return i(gd),{kind:"map",input:"velocity",x:n,y:o}}var A0=64;function el(e,t,r){let n=t>0?t:1,o=Math.max(r,1e-6),a=0;for(let s=0;s<A0;s++){let i=Math.sin((s+.5)*Math.PI/A0),c=n*o*i;a+=n*(Ws(e.rebound,c)+Ws(e.bump,c))*i}return a*(Math.PI/A0)/(Math.PI*o)}function ua(e,t,r,n,o=e){let a=(c,l,u)=>{if(!c||c.curves.length===0)return;let d=Zc(c,l);return{law:d,curve:Jc(d,u),rate:el(d,u,Mo)}},s=a(e,t?.front,r),i=a(o??e,t?.rear,n);return!s&&!i?null:{...s?{front:s}:{},...i?{rear:i}:{}}}var BA=(e,t)=>({...e,y:e.y.map(r=>r*t)}),EO=e=>({...e,x:e.x.map(t=>-t).reverse(),y:e.y.map(t=>-t).reverse()});function w0(e,t,r){let n=Math.abs(r)>0?Math.abs(r):1,o=Zc(e,t);return{law:o,curve:BA(Jc(o,n),.5),rate:el(o,n,Mo)/2,mr:n,ratio:n,share:.5}}function C0(e,t,r,n,o){let a=n*(Math.abs(r)>0?Math.abs(r):1),s=Zc(e,t),i=BA(Jc(s,a),1/n);return{law:s,curve:o?EO(i):i,rate:el(s,a,Mo)/n,mr:a/n,ratio:a,share:1/n}}function tl(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 yd=["front","rear","heaveFront","heaveRear","rollFront","rollRear"];function rl(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 Wn(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 ol(e){return e.kind==="coil"?2:1}function nl(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 GA(e){return nl(e)/2}function KA(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 $A(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 IO(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 al(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*nl(e.section)/e.barLength,a=2*o/(n*n),s=GA(e.armSection??e.section),i=3*e.E*s/n**3,c=e.dropLinkRate??1/0;return{rateAtLink:$A([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*nl(e.section)/e.barLength,a=2*o/(n*n),s=3*e.E*KA(e.blade)/n**3,i=e.dropLinkRate??1/0;return{rateAtLink:$A([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*nl(e.section)/e.length,a=2*o/(n*n);return{rateAtLink:a,contributions:{barTwist:a},torsional:o}}case"coil":{let n=Wn(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=IO(e.linkTravel,e.force,t);return{rateAtLink:Math.max(0,n),contributions:{},torsional:0}}}}function xd(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?db(t,r):1,o=t?pb(t,r):0,a=al(e,o).rateAtLink;return{wheelRate:Math.max(0,a*n*n),motionRatio:n,rateAtLink:a}}function sl(e,t){let r=e.damper??0;return!r||e.design.kind==="none"?0:ol(e.design)*r*t*t}var _O=150;function NO(e){return J(e,[0,-.5,1])<-1e-9?X(e,-1):e}function HA(e){let t=e.hardpoints,r=H(t.rockerPivotB,t.rockerPivotA),n=oe(t.rockerPivotA,X(H(t.rockerToDamper,t.rockerPivotA),.6)),o=NO(te(le(r,H(t.rockerToDamper,t.rockerPivotA))));return{outer:n,inner:oe(n,X(o,_O)),attach:"rocker"}}function zA(e,t,r,n){let o=H(r,t),a=qr(o);if(a<1e-9)return[...t];let s=X(o,1/a),i=zv(t,r,.5),c=s[0]<0?-1:1,l=n!==void 0?n*c:J(H(Fn(e,t,s),i),s),u=Math.max(-a/2,Math.min(a/2,l));return oe(i,X(s,u))}function F0(e){switch(e.kind){case"ubar":case"blade":return e.armLength;case"torsionTube":return e.leverArm;default:return}}var P0=[0,1,0];function T0(e,t,r){let n=H(r,t),o=J(n,n);if(o<1e-12)return[...t];let a=Math.max(0,Math.min(1,J(H(e,t),n)/o));return oe(t,X(n,a))}var OO=(e,t,r)=>Pe(e,t)<=Pe(e,r)?t:r,VO=2;function BO(e,t,r){let n=r.geometry,o;switch(e.attach){case"rocker":o=zA(t,n.rockerPivotA,n.rockerPivotB,e.shaftStationOuter);break;case"lowerArm":o=OO(t,T0(t,n.lcaFront,n.uprightLower),T0(t,n.lcaRear,n.uprightLower));break;case"upright":o=T0(t,n.uprightLower,n.mcpherson?n.pushrodOuter:n.uprightUpper);break}return Pe(o,t)>VO?o:void 0}function $O(e,t){let r=le(P0,e),n=t?-1:1;if(qr(r)<1e-6)return[n,0,0];let o=te(r);return(Math.abs(o[0])>.5?o[0]*n<0:o[2]>0)?X(o,-1):o}function YA(e,t,r,n){let o=e.linkage,a=r.placement,s=rt(Ye(t,o,r.state),a),i=rt(o.outer,a),c=rt(o.inner,a),l=te(H(i,c)),u=J(H(s,i),l),d=$O(l,a.isFront),p=oe(c,X(d,n)),m=J(le(P0,X(d,-1)),l),f=n>0&&Math.abs(m)>1e-9?u/(n*m):0,h=oe(p,sr(H(c,p),P0,f)),b=BO(o,s,r);return{outer:s,...b?{mount:b}:{},tip:h,root:p,linkTravel:u,twist:f}}function pr(e,t){let r={};for(let o of Zr)r[o]=wt(qe(e,o));let n={vehicle:e,ctx:r};return t&&(n.kc=om(n,t)),n}function GO(e,t,r,n){let o=e.corner.hardpoints,a=ps(e.rocker,t.points.rockerAngle),s=i=>rt(i,r);return{ucaFront:s(o.ucaFront),ucaRear:s(o.ucaRear),lcaFront:s(o.lcaFront),lcaRear:s(o.lcaRear),tieInner:s(Go(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:Tn(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 Rd(e,t,r,n){let o=ze(t,e.vehicle.config),a=o.isFront?o.sideSign*n:0,s;try{s=Ht(Ae(e.ctx[t],r,a))}catch{return null}if(!s)return null;let i=qe(e.vehicle,t).config.loadedRadius,c=GO(e.ctx[t],s,o,{loadedRadius:i,tyreDeflection:0,load:NaN,lifted:!1,contactLength:0});return c.wheelCenter.every(Number.isFinite)?{id:t,placement:o,solved:!0,state:s,geometry:c}:null}var vd=.5;function KO(e,t){let r=([i,c,l])=>{let u=te(H(c,i)),d=H(l,i),p=te(H(d,X(u,J(d,u))));return[u,p,le(u,p)]},n=r(e),o=r(t),a=[0,1,2].map(i=>[0,1,2].map(c=>o[0][i]*n[0][c]+o[1][i]*n[1][c]+o[2][i]*n[2][c]));return{rot:a,move:i=>{let c=H(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 WA=e=>[(e[2][1]-e[1][2])/2,(e[0][2]-e[2][0])/2,(e[1][0]-e[0][1])/2];function kd(e,t,r){let n=ze(t,e.vehicle.config),o=e.ctx[t],a=r.rigid?void 0:{loadedRadius:r.loadedRadius},s=r.state?null:Ae(o,r.travel,r.steer,void 0,a),i=r.state??Et(s),c=Ae(o,r.travel+vd,r.steer,void 0,a),l=Ae(o,r.travel-vd,r.steer,void 0,a),u=(s?s.ok:r.converged)&&c.ok&&l.ok,d=Et(c),p=Et(l),m=(F,T)=>rt(F.points[T],n),f=o.inv.strut?"pushrodOuter":"uprightUpper",h=m(i,f),b=m(i,"uprightLower"),g=F=>{let T=H(b,h);return Math.hypot(...le(T,H(m(i,F),h)))/Math.hypot(...T)},y=g("tieOuter")>=g("wheelCenter")?"tieOuter":"wheelCenter",x=[h,b,m(i,y)],v=F=>KO(x,[m(F,f),m(F,"uprightLower"),m(F,y)]),k=v(d),R=v(p),M=WA(k.rot),S=WA(R.rot),w=[NaN,NaN,NaN];return{solved:u,state:i,at:F=>m(i,F),velocity:F=>u?X(H(k.move(F),R.move(F)),1/(2*vd)):w,omega:u?X(H(M,S),1/(2*vd)):w}}function Md(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 jA(e,t,r){let n=kd(e,t,Qt(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 UA(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 XA(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 HO(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 zO=.1*Math.PI/180;function L0(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]))*zO<=o*n}function Sd(e,t){return!e.valid||!e.cpLeft||!e.cpRight?!1:L0([e.lateral,e.height],e.cpLeft,e.cpRight,e.sinAngle,t)}function js(e){let t=(o,a,s)=>{let i=o&&a?[a[0]-o[0],a[1]-o[1]]:s;return!o||!i||!(Math.abs(i[0])>1e-9)?Number.NaN:o[1]-o[0]*i[1]/i[0]},r=t(e.cpLeft,e.icLeft,e.lineLeft),n=t(e.cpRight,e.icRight,e.lineRight);return Number.isFinite(r)&&Number.isFinite(n)?{left:r,right:n}:null}function Us(e){let t=js(e);if(!t||!e.cpLeft||!e.cpRight)return null;let r=(t.left+t.right)/2,n=e.cpRight[0]-e.cpLeft[0],o=e.cpRight[1]-e.cpLeft[1],a=Math.hypot(n,o)||1;return{height:r,heightAboveGround:(0-e.cpLeft[0])*(-o/a)+(r-e.cpLeft[1])*(n/a)}}var YO=1;function qA(e){let t=js(e);return!t||Math.abs(t.left-t.right)>YO?null:Us(e)}function Xs(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 $r(e,t,r){let n=r==="front"?"FL":"RL",o=r==="front"?"FR":"RR",a=jA(e,n,t),s=jA(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=UA(a),c=UA(s),l=XA(a,i),u=XA(s,c),d={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 d;let p=i?[i[0]-a.cp[0],i[1]-a.cp[1]]:l,m=c?[c[0]-s.cp[0],c[1]-s.cp[1]]:u,f=Math.hypot(p[0],p[1]),h=Math.hypot(m[0],m[1]),b=f>0&&h>0?Math.abs(p[0]*m[1]-p[1]*m[0])/(f*h):0,g=Md(a.cp,p,s.cp,m)??HO(a.cp,l,s.cp);if(!g)return{...d,sinAngle:b};let y=s.cp[0]-a.cp[0],x=s.cp[1]-a.cp[1],v=Math.hypot(y,x)||1,k=y/v,R=x/v,M=(a.cp[0]+s.cp[0])/2,S=(a.cp[1]+s.cp[1])/2,w=(g[0]-a.cp[0])*-R+(g[1]-a.cp[1])*k,F=(g[0]-M)*k+(g[1]-S)*R;return{lateral:g[0],height:g[1],heightAboveGround:w,lateralAlongGround:F,valid:!0,icLeft:i,icRight:c,lineLeft:l,lineRight:u,sinAngle:b,cpLeft:a.cp,cpRight:s.cp}}function jn(e,t){return{front:$r(e,t,"front"),rear:$r(e,t,"rear")}}function Ad(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 WO(e,t){return{camber:Ad(e.travel,e.camber,t),toe:Ad(e.travel,e.toe,t),motionRatio:Ad(e.travel,e.motionRatio,t),damperLen:e.damperLen?Ad(e.travel,e.damperLen,t):0}}var QA=e=>WO(e,0).motionRatio;function D0(e,t){if(e.kind!=="coil")return null;let r=t??e.motionRatio,n=Wn(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 wd(e,t){if(e.kind==="none")return 0;if(e.kind==="tabulated"){let n=a=>jO(e,a);return(n(.5)-n(-.5))/(2*.5)/2}if((e.gap??0)>0)return 0;let r=t??e.motionRatio;return Wn(e.rate,0)*r*r/2}function il(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 jO(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 E0={kind:"coil",rate:120,motionRatio:.7,gap:5,bothWays:!1};var ZA=new WeakMap;function Fd(e,t){let r=ZA.get(e);r||(r=new Map,ZA.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=Ho(e,t);return r.set(n,a),a}var XO=32,cl=new Map,JA=new WeakMap,qO=1;function QO(e){let t=JA.get(e);return t===void 0&&(t=qO++,JA.set(e,t)),t}function I0(e,t){if(!t.linkage)return null;let r=en(e,t.linkage,t.design.kind),n=`${QO(e)}|${r?"unit":"bar"}|${JSON.stringify(t.linkage)}`,o=cl.get(n);if(o)return o;let a=xs(e,t.linkage,{kind:t.design.kind});return cl.size>=XO&&cl.delete(cl.keys().next().value),cl.set(n,a),a}function da(e,t,r=0){let n=(o,a)=>{if(!(!o||o.design.kind==="none"))return xd(o.design,I0(a,o),r).wheelRate};return{front:n(t.arbFrontDesign,e.front),rear:n(t.arbRearDesign,e.rear)}}function qs(e,t){let r=(n,o)=>{if(!n||n.design.kind==="none")return;let a=n.linkage?Fd(o,n.linkage).atDesign:void 0;return wd(n.design,a)};return{front:r(t.heaveFrontDesign,e.front),rear:r(t.heaveRearDesign,e.rear)}}function ow(e,t){let r=(a,s)=>{if(!a||a.design.kind!=="coil")return;let i=a.linkage?Fd(s,a.linkage).atDesign:void 0;return D0(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 Td(e,t){let r=(o,a)=>o?il(o,_0(o,a)):0,n=(o,a)=>o?sl(o,N0(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 _0=(e,t)=>e.linkage?Fd(t,e.linkage).atDesign:void 0,N0=(e,t)=>xd(e.design,I0(t,e),0).motionRatio;function aw(e,t){let r=t.damperSetup,n=t.heaveDamperModel??t.damperModel,o=t.rollDamperModel??t.damperModel,a=(p,m,f)=>{if(!p||!n?.curves.length)return;let h=_0(p,m);if(il(p,h)>0)return w0(n,r?.[f],h??(p.design.kind==="coil"?p.design.motionRatio:1))},s=(p,m,f)=>{if(!p||!o?.curves.length)return;let h=N0(p,m);if(!(sl(p,h)>0))return;let b=I0(m,p)!==null;return C0(o,r?.[f],h,ol(p.design),b&&h>0)},i={},c=a(t.heaveFrontDesign,e.front,"heaveFront"),l=a(t.heaveRearDesign,e.rear,"heaveRear"),u=s(t.arbFrontDesign,e.front,"rollFront"),d=s(t.arbRearDesign,e.rear,"rollRear");return c&&(i.heaveFront=c),l&&(i.heaveRear=l),u&&(i.rollFront=u),d&&(i.rollRear=d),i}function Pd(e,t){let r=t.heaveDamperModel??t.damperModel,n=t.rollDamperModel??t.damperModel,o=(i,c)=>ma(i)?{source:"none"}:rl(i.config.coilover,c),a=(i,c)=>{if(!i)return{source:"none"};let l=il(i,_0(i,c))>0;return rl(i.coilover,l?r:void 0)},s=(i,c)=>{if(!i||i.design.kind!=="coil")return{source:"none"};let l=sl(i,N0(i,c))>0;return rl(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 sw(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 ma=e=>e.config.actuation==="decoupled",pa="a decoupled axle damps in its heave and roll elements, set below";function iw(e,t,r={}){let n={...t},o=(d,p)=>{let m=n[d];m&&typeof m=="object"&&"value"in m&&(n[d]={...m,value:p})},{front:a,rear:s}=da(e,t);a!==void 0&&o("arb_front",a),s!==void 0&&o("arb_rear",s);for(let[d,p,m]of[[t.heaveFrontDesign,e.front,"heave_spring_front"],[t.heaveRearDesign,e.rear,"heave_spring_rear"]]){if(!d||d.design.kind==="none")continue;let f=d.linkage?Fd(p,d.linkage).atDesign:void 0;o(m,wd(d.design,f))}let i=JO(e,t,r),c=ZO(e,i);n.kinFront=c.kinFront,n.kinRear=c.kinRear;let l=rV(e,i);n.steerFront=c.steerFront,Number.isFinite(l.ackermannPct)&&o("ackermann_pct",l.ackermannPct);let u=d=>ma(d)?0:d.measured?.springRate??d.config.springRate;o("spring_front",u(e.front)),o("spring_rear",u(e.rear));for(let[d,p]of[[e.front,"spring_front"],[e.rear,"spring_rear"]])ma(d)&&(n.readouts={...n.readouts,[p]:"a decoupled axle has no corner spring; its heave and roll elements carry the car"});for(let[d,p]of[[e.front,"damper_front"],[e.rear,"damper_rear"]])ma(d)&&(o(p,0),n.readouts={...n.readouts,[p]:pa});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 ZO(e,t){return{kinFront:tw(e.front),kinRear:tw(e.rear),steerFront:e.front.measured?void 0:Ld(e.front,t)}}var ew=new WeakMap;function tw(e){let t=ew.get(e);return t||ew.set(e,t=Ps(e)),t}function JO(e,t,r={}){return eV(e,t,r.front,r.rear)}function eV(e,t,r,n){let o=e.front.config.loadedRadius;if(!((on(r??t.tireModel)??0)>0))return o;let a={...t,surveyedRadiusFront:o,surveyedRadiusRear:e.rear.config.loadedRadius};return Dd(a,r,n).front??o}var rw=new WeakMap;function Ld(e,t=e.config.loadedRadius){let r=rw.get(e);r||(r=new Map,rw.set(e,r));let n=r.get(t);if(n)return n;let o=t===e.config.loadedRadius?void 0:{loadedRadius:t},a=Db(e,It(e.config),void 0,void 0,void 0,void 0,o);return r.size>=4&&r.clear(),r.set(t,a),a}var nw=new WeakMap;function tV(e){return ct(e,{travelMin:-1,travelMax:1,steps:3}).samples[1].metrics.motionRatio??1}var Cd=e=>e.measured?QA(e.measured):tV(e);function rV(e,t=e.front.config.loadedRadius){let r=()=>e.front.measured?void 0:Ld(e.front,t);return{...nV(e),get steerFront(){return r()},get ackermannPct(){let n=r();return n?Eb(n,qt(e.front),e.config.wheelbase):Number.NaN}}}function nV(e){let t=nw.get(e);if(t)return t;let r=e.front.measured,n=e.rear.measured,a=!r||!n?jn(pr(e),{heave:0,pitch:0,roll:0,steer:0}):null,s={wheelbase:e.config.wheelbase,trackFront:r?r.track:qt(e.front),trackRear:n?n.track:qt(e.rear),mrFront:Cd(e.front),mrRear:Cd(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:Xs(a.front),rcGainRear:n||!a?0:Xs(a.rear),rcFrontValid:r?!0:!!a?.front.valid,rcRearValid:n?!0:!!a?.rear.valid};return nw.set(e,s),s}var Jt={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}},uw=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ln=(e,t,r,n=1/0)=>typeof e=="number"&&Number.isFinite(e)?Math.min(n,Math.max(r,e)):t;function fa(e){if(uw(e))switch(e.kind){case"open":case"spool":return{kind:e.kind};case"clutch":{let t=Jt.clutch;return{kind:"clutch",preloadNm:ln(e.preloadNm,t.preloadNm,0),rampDriveDeg:ln(e.rampDriveDeg,t.rampDriveDeg,1,90),rampCoastDeg:ln(e.rampCoastDeg,t.rampCoastDeg,1,90),faces:Math.round(ln(e.faces,t.faces,0)),muClutch:ln(e.muClutch,t.muClutch,0,1),rFrictionMm:ln(e.rFrictionMm,t.rFrictionMm,1),rRampMm:ln(e.rRampMm,t.rRampMm,1)}}case"torsen":{let t=Jt.torsen,r=ln(e.preloadNm,0,0);return{kind:"torsen",tbrDrive:ln(e.tbrDrive,t.tbrDrive,1),tbrCoast:ln(e.tbrCoast,t.tbrCoast,1),...r>0?{preloadNm:r}:{}}}default:return}}function Ed(e){if(!uw(e))return;let t=fa(e.front),r=fa(e.rear);return t||r?{...t?{front:t}:{},...r?{rear:r}:{}}:void 0}function ha(e){let t=Br(e),r=n=>n>=2?"independent":n===1?"diff":"none";return{front:r(t.front),rear:r(t.rear)}}function ll(e){if(!e.driveline)return;let t=ha(e),r=e.r_dyn.value,n=s=>{if(t[s]!=="diff")return;let i=fa(e.driveline?.[s]);if(!(!i||i.kind==="independent"))return{kind:i.kind,drive:Gc(i,"drive",r),coast:Gc(i,"coast",r),hubs:Gc(i,"hubs",r)}},o=n("front"),a=n("rear");return o||a?{...o?{front:o}:{},...a?{rear:a}:{}}:void 0}var oV={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"}},cw=e=>{let t=e==="front"?"Front":"Rear";return Object.fromEntries(Object.entries(oV).map(([r,n])=>[`${e}.${r}`,{section:t,...n}]))},Id={...cw("front"),...cw("rear")},lw=e=>e.motorModel?.kind==="ice"?e.motorPlacement==="front"?"front":"rear":null;function mw(e,t){let r=lw(t);if(!(!r||lw(e)===r||t.driveline?.[r]))return{...t.driveline,[r]:{...Jt.clutch}}}function Mr(e,t,r,n){return e>0?!(r>0)||!Number.isFinite(r)?e:Math.max(1,e-t/r):n}function _d(e,t,r){let n=Math.max(0,Math.min(1,r)),o=Mr(e.freeRadius,e.staticLoad,e.tyreRate,e.surveyed),a=Mr(t.freeRadius,t.staticLoad,t.tyreRate,t.surveyed);return n*o+(1-n)*a}function Qs(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 Un(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 ul(e,t){if(!e)return sV(t);let r=t-go(e,0).camber;return r?{...e,camber:e.camber.map(n=>n+r)}:e}function aV(e){return{kinFront:ul(e.kinFront,re(e,"camber_front_deg")),kinRear:ul(e.kinRear,re(e,"camber_rear_deg"))}}function sV(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 dw=9.81,pw=e=>e>1?e/100:e;function ba(e,t,r){let n=t??e.tireModel??Ac(),o=r??e.tireModelRear??n,a={grip:re(e,"grip_scale"),stiffness:re(e,"stiffness_scale")},s=Em(n,a);return{front:s,rear:o===n?s:Em(o,a)}}function un(e,t,r){let n=ba(e,t,r),o=Ke(n.front);return zt(n.rear===n.front?o:km(o,Ke(n.rear)))}function O0(e,t,r){let n=pw(e.front_mass_diss.value),o=ba(e,t,r),a=Ke(o.front),s=o.rear===o.front?a:Ke(o.rear),i=t??e.tireModel,c=r??e.tireModelRear??i,l=e.m.value*dw*n/2,u=e.m.value*dw*(1-n)/2,d=(i?a.verticalStiffness():0)||re(e,"tire_vertical_rate"),p=(c?s.verticalStiffness():0)||re(e,"tire_vertical_rate"),m=on(i)??0,f=on(c)??0,h=e.surveyedRadiusFront&&e.surveyedRadiusRear?_d({freeRadius:m,staticLoad:l,tyreRate:d,surveyed:e.surveyedRadiusFront},{freeRadius:f,staticLoad:u,tyreRate:p,surveyed:e.surveyedRadiusRear},n):void 0,b=e.surveyedRadiusFront?Mr(m,l,d,e.surveyedRadiusFront):void 0,g=e.surveyedRadiusRear?Mr(f,u,p,e.surveyedRadiusRear):void 0;return{ev:a,evR:s,Wf:l,Wr:u,tireRate:d,tireRateRear:p,tyreFreeRadius:m,tyreFreeRadiusRear:f,cgStandingRadius:h,standingFront:b,standingRear:g}}function Dd(e,t,r){let n=O0(e,t,r);return{front:n.standingFront,rear:n.standingRear}}function fw(e,t,r){return O0(e,t,r).cgStandingRadius}function jt(e,t,r){let n=pw(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:d,tyreFreeRadius:p,tyreFreeRadiusRear:m,cgStandingRadius:f,standingFront:h,standingRear:b}=O0(e,t,r),g=Bc(e),y=ll(e),x=ua(e.damperModel,e.damperSetup,o,a,e.damperModelRear??e.damperModel),v=e.readouts?.damper_front===pa,k=e.readouts?.damper_rear===pa,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:fd(e),cgHeight:Qs(re(e,"cg_height"),e.cgReference?.standingRadius,f),...f!==void 0?{cgStandingRadius:f}:{},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,...d!==u?{tireRateRear:d}:{},tireDamping:re(e,"tire_vertical_damping"),arbFront:re(e,"arb_front"),arbRear:re(e,"arb_rear"),...la(e)?{chassisTorsion:la(e)}:{},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:iV(e,{Wf:c,Wr:l,tireRate:u,tireRateRear:d,tyreFreeRadius:p,tyreFreeRadiusRear:m,standingFront:h,standingRear:b}),tyreFreeRadius:p,...m!==p?{tyreFreeRadiusRear:m}:{},rcHeightFront:Un(re(e,"rc_front"),e.rcRoad?.gainFront,e.rcRoad?.radiusFront,h),rcHeightRear:Un(re(e,"rc_rear"),e.rcRoad?.gainRear,e.rcRoad?.radiusRear,b),corneringStiffnessFront:s.corneringStiffness(c),corneringStiffnessRear:i.corneringStiffness(l),damperFront:x?.front&&!v?x.front.rate:re(e,"damper_front")*o*o,damperRear:x?.rear&&!k?x.rear.rate:re(e,"damper_rear")*a*a,...x?.front&&!v?{damperCurveFront:x.front.curve}:{},...x?.rear&&!k?{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,...aV(e)}}function iV(e,t){let r=(a,s,i,c)=>a??(s>0?Mr(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 Nd={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 hw(e,t=e.batteryModel){if(!t)return e;let r=An(t),n=(o,a)=>({...o,value:a});return{...e,capacity:n(e.capacity,r.capacityAh),ocv:n(e.ocv,r.voltageAtFull)}}var gw={damper_front:`the damper part sets it: its front curve at ${Mo} mm/s`,damper_rear:`the damper part sets it (the rear's own, where the car names one): its rear curve at ${Mo} mm/s`};function Od(e){let t=!!(e.damperModelId||e.damperModel),r=t||!!(e.damperModelIdRear||e.damperModelRear);return{...t?{damper_front:gw.damper_front}:{},...r?{damper_rear:gw.damper_rear}:{}}}function yw(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=ua(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!==pa&&(i.damper_front=s(e.damper_front,"damper front",a.front.rate/(n*n))),a.rear&&e.readouts?.damper_rear!==pa&&(i.damper_rear=s(e.damper_rear,"damper rear",a.rear.rate/(o*o))),i}var xw={how:"scripts/paramTiers.ts: each row \xB120 % (switches flipped, springs on the suspension), first car of every gallery template, largest change to any event time, % of it",templates:["fs-ev-comparison","fs-ev-single","fs-combustion","fs-ev-awd","fs-ev-rwd-hubs","fs-ev-one-motor","formula-1","touring-car","street-car","cup-car","stock-car","hill-climb","suspension","direct-coilover","pushrod","pullrod","third-spring","mcpherson-strut","tyre-study"],rows:{endurance_reserve:{group:"Powertrain",score:"infinite",byTemplate:{"fs-ev-comparison":"infinite","fs-ev-single":"infinite","fs-combustion":null,"fs-ev-awd":0,"fs-ev-rwd-hubs":"infinite","fs-ev-one-motor":"infinite","formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:0,"direct-coilover":null,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":null,"tyre-study":"infinite"}},gear_ratio:{group:"Powertrain",score:11.9893,byTemplate:{"fs-ev-comparison":11.9893,"fs-ev-single":11.9893,"fs-combustion":5.6255,"fs-ev-awd":5.8819,"fs-ev-rwd-hubs":11.5358,"fs-ev-one-motor":7.2758,"formula-1":.2473,"touring-car":.2195,"street-car":.0998,"cup-car":.2431,"stock-car":.0645,"hill-climb":3.1703,suspension:1.8984,"direct-coilover":.2195,pushrod:1.9001,pullrod:1.9126,"third-spring":1.9001,"mcpherson-strut":.111,"tyre-study":11.9893}},driven_wheels:{group:"Powertrain",score:11.9893,byTemplate:{"fs-ev-comparison":11.9893,"fs-ev-single":11.9893,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:1.9216,"direct-coilover":0,pushrod:1.9171,pullrod:1.919,"third-spring":1.9171,"mcpherson-strut":0,"tyre-study":11.9893}},power_scale:{group:"Powertrain",score:11.9893,byTemplate:{"fs-ev-comparison":11.9893,"fs-ev-single":11.9893,"fs-combustion":10.2883,"fs-ev-awd":4.2843,"fs-ev-rwd-hubs":11.6138,"fs-ev-one-motor":7.2758,"formula-1":2.6682,"touring-car":2.5337,"street-car":1.938,"cup-car":2.6155,"stock-car":1.2193,"hill-climb":1.869,suspension:1.9216,"direct-coilover":2.5337,pushrod:1.9171,pullrod:1.919,"third-spring":1.9171,"mcpherson-strut":1.9778,"tyre-study":11.9893}},grip_scale:{group:"Tyres",score:11.4886,byTemplate:{"fs-ev-comparison":10.9135,"fs-ev-single":10.9135,"fs-combustion":11.4886,"fs-ev-awd":11.3513,"fs-ev-rwd-hubs":11.3513,"fs-ev-one-motor":11.3905,"formula-1":10.9225,"touring-car":7.4484,"street-car":7.2578,"cup-car":7.1946,"stock-car":10.4642,"hill-climb":9.5384,suspension:8.3679,"direct-coilover":7.4484,pushrod:8.3929,pullrod:8.3807,"third-spring":8.3929,"mcpherson-strut":7.35,"tyre-study":10.9135}},front_mass_diss:{group:"Mass & chassis",score:10.3816,byTemplate:{"fs-ev-comparison":1.1854,"fs-ev-single":1.1854,"fs-combustion":1.5398,"fs-ev-awd":1.9682,"fs-ev-rwd-hubs":1.9682,"fs-ev-one-motor":4.5048,"formula-1":5.2182,"touring-car":1.241,"street-car":3.5067,"cup-car":.7277,"stock-car":2.2367,"hill-climb":10.3816,suspension:.5046,"direct-coilover":1.241,pushrod:.4796,pullrod:.4587,"third-spring":.4796,"mcpherson-strut":3.4131,"tyre-study":1.1854}},m:{group:"Mass & chassis",score:9.7815,byTemplate:{"fs-ev-comparison":9.7815,"fs-ev-single":9.7815,"fs-combustion":7.2245,"fs-ev-awd":5.6765,"fs-ev-rwd-hubs":9.2239,"fs-ev-one-motor":7.0296,"formula-1":5.3736,"touring-car":3.7044,"street-car":1.9146,"cup-car":2.6724,"stock-car":3.7623,"hill-climb":5.4157,suspension:3.8549,"direct-coilover":3.7044,pushrod:3.8507,pullrod:3.8527,"third-spring":3.8507,"mcpherson-strut":1.9399,"tyre-study":9.7815}},cop_long:{group:"Aerodynamics",score:6.6543,byTemplate:{"fs-ev-comparison":1.032,"fs-ev-single":1.032,"fs-combustion":1.0669,"fs-ev-awd":1.0452,"fs-ev-rwd-hubs":1.0452,"fs-ev-one-motor":1.0521,"formula-1":5.9878,"touring-car":.1327,"street-car":.0018,"cup-car":.2696,"stock-car":.6469,"hill-climb":6.6543,suspension:.3644,"direct-coilover":.1327,pushrod:.3575,pullrod:.355,"third-spring":.3575,"mcpherson-strut":.0072,"tyre-study":1.032}},front_aero_diss:{group:"Aerodynamics",score:5.2168,byTemplate:{"fs-ev-comparison":.9064,"fs-ev-single":.9064,"fs-combustion":.8657,"fs-ev-awd":.8967,"fs-ev-rwd-hubs":.8967,"fs-ev-one-motor":.8574,"formula-1":4.2912,"touring-car":.0708,"street-car":.0018,"cup-car":.2207,"stock-car":.5291,"hill-climb":5.2168,suspension:.2835,"direct-coilover":.0708,pushrod:.2831,pullrod:.2823,"third-spring":.2831,"mcpherson-strut":.0072,"tyre-study":.9064}},power_limit_kw:{group:"Powertrain",score:4.5916,byTemplate:{"fs-ev-comparison":.4828,"fs-ev-single":.4828,"fs-combustion":null,"fs-ev-awd":4.5916,"fs-ev-rwd-hubs":.5453,"fs-ev-one-motor":3.6198,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:.0626,"direct-coilover":null,pushrod:.0625,pullrod:.0626,"third-spring":.0625,"mcpherson-strut":null,"tyre-study":.4828}},soc:{group:"Powertrain",score:3.5618,byTemplate:{"fs-ev-comparison":3.2245,"fs-ev-single":3.2245,"fs-combustion":0,"fs-ev-awd":1.6179,"fs-ev-rwd-hubs":3.3095,"fs-ev-one-motor":3.5618,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":3.2245}},effi_pgb:{group:"Powertrain",score:3.5269,byTemplate:{"fs-ev-comparison":3.5269,"fs-ev-single":3.5269,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:.0626,"direct-coilover":0,pushrod:.0625,pullrod:.0626,"third-spring":.0625,"mcpherson-strut":0,"tyre-study":3.5269}},c_l:{group:"Aerodynamics",score:3.4342,byTemplate:{"fs-ev-comparison":.9751,"fs-ev-single":.9751,"fs-combustion":.9539,"fs-ev-awd":1.0777,"fs-ev-rwd-hubs":.9886,"fs-ev-one-motor":1.0797,"formula-1":3.4342,"touring-car":.8979,"street-car":.0715,"cup-car":.2158,"stock-car":.5467,"hill-climb":1.2705,suspension:.9751,"direct-coilover":.8979,pushrod:.9734,pullrod:.9708,"third-spring":.9734,"mcpherson-strut":.0704,"tyre-study":.9751}},ocv:{group:"Powertrain",score:3.3244,byTemplate:{"fs-ev-comparison":3.0446,"fs-ev-single":3.0446,"fs-combustion":0,"fs-ev-awd":1.4595,"fs-ev-rwd-hubs":3.1854,"fs-ev-one-motor":3.3244,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":3.0446}},capacity:{group:"Powertrain",score:3.3244,byTemplate:{"fs-ev-comparison":3.0446,"fs-ev-single":3.0446,"fs-combustion":0,"fs-ev-awd":1.4595,"fs-ev-rwd-hubs":3.1854,"fs-ev-one-motor":3.3244,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":3.0446}},A:{group:"Aerodynamics",score:2.3707,byTemplate:{"fs-ev-comparison":.802,"fs-ev-single":.802,"fs-combustion":.7928,"fs-ev-awd":.9333,"fs-ev-rwd-hubs":.7926,"fs-ev-one-motor":.961,"formula-1":2.3707,"touring-car":.6374,"street-car":.4904,"cup-car":.2428,"stock-car":.1932,"hill-climb":1.1486,suspension:.802,"direct-coilover":.6374,pushrod:.7991,pullrod:.7982,"third-spring":.7991,"mcpherson-strut":.4873,"tyre-study":.802}},rho:{group:"Aerodynamics",score:2.3707,byTemplate:{"fs-ev-comparison":.802,"fs-ev-single":.802,"fs-combustion":.7928,"fs-ev-awd":.9333,"fs-ev-rwd-hubs":.7926,"fs-ev-one-motor":.961,"formula-1":2.3707,"touring-car":.6374,"street-car":.4904,"cup-car":.2428,"stock-car":.1932,"hill-climb":0,suspension:.802,"direct-coilover":.6374,pushrod:.7991,pullrod:.7982,"third-spring":.7991,"mcpherson-strut":.4873,"tyre-study":.802}},cg_height:{group:"Mass & chassis",score:2.2005,byTemplate:{"fs-ev-comparison":1.8282,"fs-ev-single":1.8282,"fs-combustion":1.6978,"fs-ev-awd":2.2005,"fs-ev-rwd-hubs":1.8919,"fs-ev-one-motor":1.9269,"formula-1":.6248,"touring-car":1.2858,"street-car":1.4681,"cup-car":.992,"stock-car":1.2052,"hill-climb":.6037,suspension:1.8282,"direct-coilover":1.2858,pushrod:1.8142,pullrod:1.8229,"third-spring":1.8142,"mcpherson-strut":1.7176,"tyre-study":1.8282}},l_to_d_ratio:{group:"Aerodynamics",score:1.4351,byTemplate:{"fs-ev-comparison":.7905,"fs-ev-single":.7905,"fs-combustion":.6962,"fs-ev-awd":.5843,"fs-ev-rwd-hubs":.8444,"fs-ev-one-motor":.9611,"formula-1":1.4351,"touring-car":.3671,"street-car":.528,"cup-car":.5631,"stock-car":.4634,"hill-climb":.2349,suspension:.2456,"direct-coilover":.3671,pushrod:.2491,pullrod:.2456,"third-spring":.2491,"mcpherson-strut":.5265,"tyre-study":.7905}},tv_enabled:{group:"Torque vectoring",score:1.2381,byTemplate:{"fs-ev-comparison":1.2381,"fs-ev-single":1.2381,"fs-combustion":0,"fs-ev-awd":1.2293,"fs-ev-rwd-hubs":1.2293,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":.1209,"cup-car":.1617,"stock-car":0,"hill-climb":9e-4,suspension:.3086,"direct-coilover":0,pushrod:.2933,pullrod:.3089,"third-spring":.2933,"mcpherson-strut":.1326,"tyre-study":1.2381}},c_w:{group:"Aerodynamics",score:1.1499,byTemplate:{"fs-ev-comparison":.6319,"fs-ev-single":.6319,"fs-combustion":.5577,"fs-ev-awd":.462,"fs-ev-rwd-hubs":.6559,"fs-ev-one-motor":.7504,"formula-1":1.1499,"touring-car":.2914,"street-car":.4211,"cup-car":.4486,"stock-car":.3694,"hill-climb":.1625,suspension:.1945,"direct-coilover":.2914,pushrod:.1979,pullrod:.1948,"third-spring":.1979,"mcpherson-strut":.4196,"tyre-study":.6319}},brake_balance:{group:"Brakes",score:1.0132,byTemplate:{"fs-ev-comparison":.8303,"fs-ev-single":.8303,"fs-combustion":.6932,"fs-ev-awd":.9772,"fs-ev-rwd-hubs":.8148,"fs-ev-one-motor":1.0132,"formula-1":.97,"touring-car":.9585,"street-car":.7184,"cup-car":.1468,"stock-car":.0764,"hill-climb":.9096,suspension:.8303,"direct-coilover":.9585,pushrod:.8578,pullrod:.8454,"third-spring":.8578,"mcpherson-strut":.7099,"tyre-study":.8303}},stiffness_scale:{group:"Tyres",score:.871,byTemplate:{"fs-ev-comparison":.5088,"fs-ev-single":.5088,"fs-combustion":.4874,"fs-ev-awd":.3745,"fs-ev-rwd-hubs":.4753,"fs-ev-one-motor":.5706,"formula-1":.5776,"touring-car":.4346,"street-car":.1077,"cup-car":.4012,"stock-car":.1613,"hill-climb":.871,suspension:.5088,"direct-coilover":.4346,pushrod:.5253,pullrod:.5172,"third-spring":.5253,"mcpherson-strut":.1518,"tyre-study":.5088}},cop_height:{group:"Aerodynamics",score:.2837,byTemplate:{"fs-ev-comparison":.155,"fs-ev-single":.155,"fs-combustion":.1546,"fs-ev-awd":.1557,"fs-ev-rwd-hubs":.1557,"fs-ev-one-motor":.1542,"formula-1":.1173,"touring-car":.0072,"street-car":.0023,"cup-car":.0745,"stock-car":.1568,"hill-climb":.2837,suspension:.0421,"direct-coilover":.0072,pushrod:.0437,pullrod:.04,"third-spring":.0437,"mcpherson-strut":.0076,"tyre-study":.155}},spring_rear:{group:"Suspension",score:.2822,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":.0355,"touring-car":.1169,"street-car":.2242,"cup-car":.0902,"stock-car":.2822,"hill-climb":.1929,suspension:0,"direct-coilover":.1169,pushrod:.1142,pullrod:.2148,"third-spring":.1142,"mcpherson-strut":.1786,"tyre-study":0}},spring_front:{group:"Suspension",score:.2388,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":.0189,"touring-car":.0958,"street-car":.2388,"cup-car":.1462,"stock-car":.1719,"hill-climb":.1873,suspension:0,"direct-coilover":.0958,pushrod:.1257,pullrod:.0612,"third-spring":.1257,"mcpherson-strut":.1911,"tyre-study":0}},arb_front:{group:"Suspension",score:.1792,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":.0235,"touring-car":.0589,"street-car":.1792,"cup-car":.0215,"stock-car":.0926,"hill-climb":.1095,suspension:null,"direct-coilover":.0589,pushrod:.0455,pullrod:.049,"third-spring":.0455,"mcpherson-strut":.1435,"tyre-study":null}},fr_0:{group:"Tyres",score:.158,byTemplate:{"fs-ev-comparison":.158,"fs-ev-single":.158,"fs-combustion":.1097,"fs-ev-awd":.0708,"fs-ev-rwd-hubs":.1442,"fs-ev-one-motor":.1168,"formula-1":.07,"touring-car":.0492,"street-car":.1006,"cup-car":.065,"stock-car":.0262,"hill-climb":.0334,suspension:.0217,"direct-coilover":.0492,pushrod:.0229,pullrod:.0223,"third-spring":.0229,"mcpherson-strut":.0989,"tyre-study":.158}},arb_rear:{group:"Suspension",score:.1047,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":.0224,"touring-car":.0365,"street-car":.0832,"cup-car":.1047,"stock-car":.0436,"hill-climb":.0734,suspension:null,"direct-coilover":.0365,pushrod:.0411,pullrod:.0332,"third-spring":.0411,"mcpherson-strut":.0643,"tyre-study":null}},unsprung_mass:{group:"Mass & chassis",score:.102,byTemplate:{"fs-ev-comparison":.0477,"fs-ev-single":.0477,"fs-combustion":.0512,"fs-ev-awd":.0545,"fs-ev-rwd-hubs":.0514,"fs-ev-one-motor":.0799,"formula-1":.0313,"touring-car":.0471,"street-car":.102,"cup-car":.0315,"stock-car":.042,"hill-climb":.0278,suspension:.0477,"direct-coilover":.0471,pushrod:.0452,pullrod:.0468,"third-spring":.0452,"mcpherson-strut":.0876,"tyre-study":.0477}},camber_front_deg:{group:"Steering & alignment",score:.0576,byTemplate:{"fs-ev-comparison":.0065,"fs-ev-single":.0065,"fs-combustion":.008,"fs-ev-awd":.0075,"fs-ev-rwd-hubs":.0075,"fs-ev-one-motor":.0098,"formula-1":.0358,"touring-car":.0272,"street-car":.0025,"cup-car":.0191,"stock-car":.0576,"hill-climb":.0389,suspension:.0019,"direct-coilover":.0272,pushrod:.0017,pullrod:.0016,"third-spring":.0017,"mcpherson-strut":.002,"tyre-study":.0065}},camber_rear_deg:{group:"Steering & alignment",score:.0262,byTemplate:{"fs-ev-comparison":.0081,"fs-ev-single":.0081,"fs-combustion":.0085,"fs-ev-awd":.0054,"fs-ev-rwd-hubs":.0096,"fs-ev-one-motor":.0097,"formula-1":.0028,"touring-car":.0106,"street-car":8e-4,"cup-car":5e-4,"stock-car":.0035,"hill-climb":.0262,suspension:.0081,"direct-coilover":.0106,pushrod:.0082,pullrod:.0083,"third-spring":.0082,"mcpherson-strut":3e-4,"tyre-study":.0081}},I_yaw:{group:"Mass & chassis",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},I_roll:{group:"Mass & chassis",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},I_pitch:{group:"Mass & chassis",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},ride_height_front:{group:"Aerodynamics",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},ride_height_rear:{group:"Aerodynamics",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tire_vertical_rate:{group:"Tyres",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tire_vertical_damping:{group:"Tyres",score:0,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":0,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},r_dyn:{group:"Tyres",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},damper_front:{group:"Suspension",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},damper_rear:{group:"Suspension",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_kp:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_ff_low:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_ff_high:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_v_low:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_v_high:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},wheelbase:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},track_front:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},track_rear:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},rc_front:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},rc_rear:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},chassis_torsion:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_twist_front:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_twist_rear:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_wheel:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_rotor:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},v_limit_endurance:{group:"Powertrain",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},mr_front:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},mr_rear:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},heave_spring_front:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},heave_spring_rear:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},toe_front_deg:{group:"Steering & alignment",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},toe_rear_deg:{group:"Steering & alignment",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},ackermann_pct:{group:"Steering & alignment",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}}}};function Xn(e){return!!e&&typeof e=="object"&&"value"in e&&"label"in e}var mV={Batteriekapazit\u00E4t:"pack capacity",Rollwiderstandsbeiwert:"rolling-resistance coefficient"},vw=e=>mV[e]??e;function Vd(e){let t=[];for(let r of Object.keys(e)){if(r==="motor"||r==="name")continue;let n=e[r];Xn(n)&&t.push({key:r,label:vw(n.label),value:n.value,unit:n.unit})}return t}var dV=[{title:"Mass & chassis",keys:["m","front_mass_diss","cg_height","unsprung_mass","wheelbase","track_front","track_rear","rc_front","rc_rear","chassis_torsion","I_twist_front","I_twist_rear","I_yaw","I_roll","I_pitch","I_wheel","I_rotor"]},{title:"Aerodynamics",keys:["A","c_l","c_w","l_to_d_ratio","front_aero_diss","cop_long","cop_height","ride_height_front","ride_height_rear","rho"]},{title:"Tyres",keys:["grip_scale","stiffness_scale","tire_vertical_rate","tire_vertical_damping","fr_0","r_dyn"]},{title:"Powertrain",keys:["gear_ratio","driven_wheels","effi_pgb","power_scale","power_limit_kw","v_limit_endurance","endurance_reserve","capacity","ocv","soc"]},{title:"Suspension",keys:["spring_front","spring_rear","mr_front","mr_rear","arb_front","arb_rear","heave_spring_front","heave_spring_rear","damper_front","damper_rear"]},{title:"Steering & alignment",keys:["camber_front_deg","camber_rear_deg","toe_front_deg","toe_rear_deg","ackermann_pct"]},{title:"Brakes",keys:["brake_balance"]},{title:"Torque vectoring",keys:["tv_enabled","tv_kp","tv_ff_low","tv_ff_high","tv_v_low","tv_v_high"]}],pV=.5,Rw=e=>e==="infinite"?1/0:typeof e=="number"?e:null,fV=e=>/front/.test(e)?e.replace("front","rear"):/rear/.test(e)?e.replace("rear","front"):null,hre=(()=>{let e=xw.rows,t=o=>{let a=fV(o),s=Rw(e[o]?.score),i=a&&e[a]?Rw(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>=pV&&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 V0={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 kw(e){let t=new Map;for(let a of Vd(e))t.set(a.key,a);let r=new Set,n=[];for(let a of dV){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=Vd(e).filter(a=>!r.has(a.key));return o.length&&n.push({title:"Other",rows:o}),n}var B0={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"},$0={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"},Mw=e=>!!(e.aeroModelId||e.aeroModel);function hV(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 bV=e=>!!(e.batteryModelId||e.batteryModel),Sw={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"},bre=Object.keys(Sw);function G0(e){if(!(e.motorModelId||e.motorModel))return{};let t=kt(e.motorModel),r={effi_pgb:"the motor model states its own efficiency",...t?Sw:{}};return(e.motorCount!=null||t)&&(r.driven_wheels="the motor layout in Powertrain sets which wheels are driven"),r}function gV(e,t){let r={};return t.geometry&&Object.assign(r,V0,hV(e)),Mw(e)&&Object.assign(r,B0),bV(e)&&Object.assign(r,Nd),Object.assign(r,G0(e)),Object.assign(r,Od(e)),Object.assign(r,Xm(e)),e.readouts&&Object.assign(r,e.readouts),r}function Aw(e,t){let r=gV(e,t);return Mw(e)||Object.assign(r,$0),r}function K0(e){let t=e.cop_long;return Xn(t)?1-t.value:.5}function yV(e,t){let r=e.front_aero_diss,n=e.cop_long;!Xn(r)||!Xn(n)||(t===r.label?n.value=1-r.value:t===n.label&&(r.value=1-n.value))}function xV(e,t){yV(e,t);let r=e.c_l,n=e.c_w,o=e.l_to_d_ratio;!Xn(r)||!Xn(n)||(t===r.label||t===n.label?Xn(o)&&n.value!==0&&(o.value=r.value/n.value):Xn(o)&&t===o.label&&o.value!==0&&(n.value=r.value/o.value))}function Zs(e,t,r){let n=!1;for(let o of Object.keys(e)){if(o==="motor"||o==="name")continue;let a=e[o];if(Xn(a)&&vw(a.label)===t){a.value=r,n=!0;break}}return n&&xV(e,t),n}function Bd(e,t,r=0,n,o){let a=()=>({cl:e.c_l.value,cw:e.c_w.value,frontShare:K0(e),A:e.A.value,platform:null});if(!e.aeroModel)return a();let s=Cn(n??jt(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:K0(e),A:s.area,platform:s}}var ww=e=>typeof e=="object"&&e!==null&&typeof e.value=="number"&&typeof e.label=="string";function Cw(e,t=e.aeroModel){if(!t)return e;let r=mo(t,{wheelbase:re(e,"wheelbase")}).at(re(e,"ride_height_front"),re(e,"ride_height_rear")),{cl:n,balanceFront:o}=Ih(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(ww(e.cop_long)?e.cop_long:void 0,cn.cop_long,1-o)};return ww(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 ml={dsTarget:.25,accelStep:.25,vTol:.002,scanSteps:24,seamIters:8,fitSpacing:1},RV=32;function Fw(e,t,r){let n=Math.round(e/t);return Math.max(1,Math.min(Number.isFinite(n)?n:1,Math.floor(r/RV)||1))}function Nt(e){let t=ml,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 Tw=Math.PI/180,$d=.02,Pw=new WeakMap;function dl(e){let t=Pw.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)*Tw,l=(e.bank?.[i]??0)*Tw,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 Pw.set(e,s),s}function Gd(e,t,r){return e.n0[t]+e.k[t]*r*r}function Lw(e,t){return e.k[t]<0?Math.sqrt(Math.max(0,e.n0[t])/-e.k[t]):1/0}function Dw(e,t){if(!e)return null;let r=1/0,n=-1/0;for(let o=0;o<e.n0.length;o++){let a=Gd(e,o,t[o]??0);a<r&&(r=a),a>n&&(n=a)}return r>=1-$d&&n<=1+$d?null:{lo:r,hi:n}}var Js=[.1,.25,.5,.75,1,1.25,1.5,2,2.5];function Ew(e){let t=e.lo>=1-$d?1:1-1.25*(1-e.lo)-.05,r=e.hi<=1+$d?1:1+1.25*(e.hi-1)+.05,n=[...Js].reverse().find(a=>a<=t)??Js[0],o=Js.find(a=>a>=r)??Js[Js.length-1];return Js.filter(a=>a>=n&&a<=o)}function H0(e,t,r){return r<1?Math.max(e,t):Math.min(e,t)}function Iw(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,d=s.kappaMax===void 0?t.kappaMax:t.kappaMax===void 0?s.kappaMax:Math.min(s.kappaMax,t.kappaMax),p=d!==void 0?{kappaMax:d}:{};return n?{vMax:s.vMax,...p,axAccel:(m,f,h=1,b=1)=>s.axAccel(m,f,h,b)+t.axAccel(u(m),m,f,h,b)-r.axAccel(m,f,h,b),axDecel:(m,f,h=1,b=1)=>{let g=y=>s.axDecel(m,f,h,y)+t.axDecel(u(m),m,f,h,y)-r.axDecel(m,f,h,y);return b===1?g(1):H0(g(b),g(1),b)},ay:(m,f,h=1)=>Math.max(0,s.ay(m,f,h)+t.ay(u(m),m,f,h)-r.ay(m,f,h)),scrub:(m,f,h=1)=>(s.scrub?.(m,f,h)??0)+t.scrub(u(m),m,f,h)-(r.scrub?.(m,f,h)??0)}:{vMax:s.vMax,...p,axAccel:(m,f,h=1,b=1)=>t.axAccel(u(m),m,f,h,b),axDecel:(m,f,h=1,b=1)=>t.axDecel(u(m),m,f,h,b),ay:(m,f,h=1)=>t.ay(u(m),m,f,h),scrub:(m,f,h=1)=>t.scrub(u(m),m,f,h)}}}function Kd(e,t,r,n,o){let a=e.length,s=r?a:a-1,i=S=>r?(S+1)%a:S+1,{brakeAhead:c,apexAhead:l}=vV(e,t,r),u=new Array(a),d=new Array(a),p=new Array(a),m=new Array(a).fill(0),f=0,h=0,b=0,g=Math.max(0,Math.min(1,n.kept)),y=g>=1?0:n.up,x=g>=1?0:n.down,v=4*y*(1-g),k=S=>{let{v:w,gear:F,tau:T,target:A}=S;f=0,h=0,b=0;for(let C=0;C<s;C++){let P=i(C),L=e[P];for(let D=0;T<=0&&D<n.count;D++){let I=F;if(w<L-1e-9?n.best(w)>F&&(n.rpm(w,F)>=n.limitRpm||c[C]>=w*v)?I=F+1:F>0&&w<n.vIdle(F)&&(I=F-1):L<w-1e-9&&F>0&&n.best(l[C])<F&&n.rpm(w,F-1)<=n.limitRpm&&(I=F-1),I===F)break;A=I,I>F?f++:h++,T=I>F?y:x,T<=0&&(F=A)}u[C]=w,d[C]=F+1,p[C]=n.rpm(w,F);let E=T>0;m[C]=E?1:0;let _=L;if(!E)w<L&&(_=Math.min(L,Math.sqrt(Math.max(0,w*w+2*o(C,w,n.share(w,F))*t[C]))));else if(w<L){let D=o(C,w,g>0?g*n.share(w,F):0),I=Math.min(L,Math.sqrt(Math.max(0,w*w+2*D*t[C]))),V=w+I>0?2*t[C]/(w+I):1/0;if(V<=T)_=I,b+=V,T-=V;else{let O=Math.min(L,Math.max(0,w+D*T)),B=Math.max(0,t[C]-(w+O)*.5*T);b+=T,T=0,F=A,_=Math.min(L,Math.sqrt(Math.max(0,O*O+2*o(C,O,n.share(O,F))*B)))}}else{let D=w+_>0?2*t[C]/(w+_):0;b+=Math.min(D,T),T-=D,T<=0&&(F=A)}w=_}return{v:w,gear:F,tau:T,target:A}},R=n.best(e[0]),M={v:e[0],gear:R,tau:0,target:R};if(r)for(let S=0;S<6;S++){let w=k(M),F=Math.abs(w.v-M.v)<=1e-9&&w.gear===M.gear&&w.target===M.target&&Math.abs(w.tau-M.tau)<=1e-12;if(M=w,F)break}else{let S=k(M);u[a-1]=S.v,d[a-1]=S.gear+1,p[a-1]=n.rpm(S.v,S.gear),m[a-1]=S.tau>0?1:0}return{v:u,gear:d,rpm:p,shifting:m,upshifts:f,downshifts:h,gapTime:b}}function vV(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,d=r?(u+1)%n:u+1,p=e[d]<e[u]-1e-9;s=p?0:s+t[u],i=p?Math.min(i,e[d]):e[u],l<n&&(o[u]=s,a[u]=i)}return{brakeAhead:o,apexAhead:a}}var z0=.001,Y0=9.81,pl=(e,t)=>Hd(e?.gradient?.[t]??0);function Hd(e){return e===0?0:-Y0*Math.sin(e*Math.PI/180)}function ei(e,t){let r=new Array(t);for(let n=0;n<t;n++)r[n]=Hd(e?.[n]??0);return r}function zd(e,t){let r=e?.[t];return r!=null&&r>0?r:1}var So=(e,t)=>zd(e?.mu,t),ga=(e,t)=>e?.bank?.[t]??0;function kV(e,t,r,n,o,a){let s=e.ay(t,r,So(o,a)),i=ga(o,a);if(!i)return s;let c=i*Math.PI/180,l=n===0?0:-Math.sign(n)*Y0*Math.sin(c);return Math.max(0,(s+l)/Math.cos(c))}function lt(e,t){if(!t)return e;let r=t*Math.PI/180;return e*Math.cos(r)+Y0*Math.sin(r)}function W0(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 qn=(e,t,r)=>t?t(r):e,MV=1e-4;function SV(e,t){let r=Math.abs(t);return e.kappaMax!==void 0&&r>e.kappaMax?e.kappaMax:r}function AV(e,t,r){if(e.kappaMax===void 0&&!t)return;let n=0,o=-1,a=0;for(let i=0;i<r.npts;i++){let c=qn(e,t,i).kappaMax,l=Math.abs(r.curvature[i]);c===void 0||!(l>c)||(n+=r.ds[i],l/c>a&&(a=l/c,o=i))}if(o<0)return;let s=qn(e,t,o).kappaMax;return{length:n,at:r.s[o],radius:1/Math.abs(r.curvature[o]),lockRadius:1/s}}function ti(e,t,r,n,o,a,s){let i=Nt(r),c=[];for(let l=0;l<t.length;l++){let u=t[l],d=qn(e,o,l),p=SV(d,u),m=a!==void 0&&a>0?Math.min(d.vMax,a):d.vMax,f=s?Math.min(m,s(l)):m,h=p<=0?f:W0(b=>b*b*p-kV(d,b,0,u,n,l),z0,f,i.scanSteps,Math.min(i.vTol,MV));c.push({v:h,ax:0,ay:h*h*u})}return c}function wV(e,t,r,n,o,a,s=1,i=0,c=0,l){if(r.v<=t.v)return 0;let u=m=>{let f=lt(m*m*n,c),h=(l?e.axDecel(m,Math.abs(f),s,l(m)):e.axDecel(m,Math.abs(f),s))+i;return Math.sqrt(Math.max(0,m*m+2*h*o))},d=r.v;r.v=W0(m=>u(m)-t.v,z0,r.v,a.scanSteps,a.vTol),r.ay=r.v*r.v*n;let p=Math.abs(lt(r.ay,c));return r.ax=(l?e.axDecel(r.v,p,s,l(r.v)):e.axDecel(r.v,p,s))+i,d-r.v}function CV(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(lt(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 _w(e,t,r,n,o,a){let s=Nt(n),i=r.npts,c=0;for(let l=0;l<s.seamIters;l++){let u=0;c++;for(let d=i-1;d>=0;d--){let p=(d+1)%i;u=Math.max(u,wV(qn(e,o,d),t[p],t[d],r.curvature[d],r.ds[d],s,So(r,d),pl(r,d),ga(r,d),a?m=>a(d,m):void 0))}if(u<=s.vTol)break}return c}function Nw(e,t,r,n,o,a){let s=Nt(n),i=r.npts,c=0;for(let l=0;l<s.seamIters;l++){let u=0;c++;for(let d=0;d<i;d++){let p=(d+1)%i;u=Math.max(u,CV(qn(e,o,d),t[p],t[d],r.curvature[d],r.ds[d],So(r,d),pl(r,d),ga(r,d),a?a[d]:1))}if(u<=s.vTol)break}return c}function FV(e,t,r){let n=r.load?dl(t):null;if(!n||!r.load)return{pick:r.envelope};let o=t.npts;return{pick:Iw(n,r.load,e,r.envelope),cap:a=>Lw(n,a%o),n:(a,s)=>Gd(n,a,s)}}function Ow(e,t,r,n,o,a,s){return Kd(n,r.ds,o,a,(i,c,l)=>{let u=c*c*r.curvature[i];return qn(e,t,i).axAccel(c,Math.abs(lt(u,ga(r,i))),So(r,i),s?l*s[i]:l)+pl(r,i)})}function Vw(e,t){return{gear:e.gear.slice(0,t),engineRpm:e.rpm.slice(0,t),shifting:e.shifting.slice(0,t)}}function Bw(e,t,r,n){if(!e.scrub)return{};let o=!1,a=n.map((s,i)=>{let c=qn(e,t,i),l=lt(s*s*r.curvature[i],ga(r,i)),u=c.scrub?c.scrub(s,Math.abs(l),So(r,i)):0;return u!==0&&(o=!0),u});return o?{axScrub:a}:{}}function er(e,t,r,n={}){let o=Nt(r),a=t.npts,s=t.closed&&!n.standingStart,{pick:i,cap:c,n:l}=FV(e,t,n),u=n.driveDerate,d=n.brakeFade;if(!s)return TV(e,t,o,n.standingStart===!0,i,u,n.vCeiling,d,c,l,n.shifts);let p=ti(e,t.curvature,o,t,i,n.vCeiling,c),m=_w(e,p,t,o,i,d),f=Nw(e,p,t,o,i,u),h=n.shifts?Ow(e,i,t,p.map(v=>v.v),!0,n.shifts,u):void 0;if(h)for(let v=0;v<a;v++)p[v].v=h.v[v];for(let v=0;v<a;v++){let k=p[v];k.ay=k.v*k.v*t.curvature[v];let R=p[(v+1)%a].v;k.ax=(R*R-k.v*k.v)/(2*t.ds[v])}let b=p.map(v=>v.v),g=p.map(v=>v.ax),y=p.map(v=>v.ay),x=0;for(let v=0;v<a;v++){let k=b[v]+b[(v+1)%a];k>0&&(x+=2*t.ds[v]/k)}return{states:p,v:b,ax:g,ay:y,laptime:x,sweeps:{backward:m,forward:f},...l?{loadFactor:b.map((v,k)=>l(k,v))}:{},...Bw(e,i,t,b),...h?Vw(h,a):{},...$w(e,i,t)}}function $w(e,t,r){let n=AV(e,t,r);return n?{pastLock:n}:{}}function TV(e,t,r,n,o,a,s,i,c,l,u){let d=t.npts,p=t.closed?d:d-1,m=p+1,f=new Array(m);for(let x=0;x<m;x++)f[x]=t.curvature[x%d];let h=ti(e,f,r,t,o,s,c);n&&(h[0].v=0);for(let x=p-1;x>=0;x--){let v=h[x],k=h[x+1];if(v.v<=k.v)continue;let R=qn(e,o,x),M=w=>{let F=lt(w*w*t.curvature[x],ga(t,x)),T=(i?R.axDecel(w,Math.abs(F),So(t,x),i(x,w)):R.axDecel(w,Math.abs(F),So(t,x)))+pl(t,x);return Math.sqrt(Math.max(0,w*w+2*T*t.ds[x]))},S=n&&x===0?v.v:z0;v.v=W0(w=>M(w)-k.v,S,v.v,r.scanSteps,r.vTol)}for(let x=0;x<p;x++){let v=h[x],k=h[x+1];v.ay=v.v*v.v*t.curvature[x];let R=lt(v.ay,ga(t,x));v.ax=qn(e,o,x).axAccel(v.v,Math.abs(R),So(t,x),a?a[x]:1)+pl(t,x),k.v=Math.min(k.v,Math.sqrt(Math.max(0,v.v*v.v+2*v.ax*t.ds[x])))}let b=u?Ow(e,o,t,h.map(x=>x.v),!1,u,a):void 0;if(b)for(let x=0;x<m;x++)h[x].v=b.v[x];let g=0;for(let x=0;x<p;x++){let v=h[x].v+h[x+1].v;v>0&&(g+=2*t.ds[x]/v)}let y=h.slice(0,d);for(let x=0;x<d;x++){let v=y[x];v.ay=v.v*v.v*t.curvature[x];let k=x<p?h[x+1].v:v.v;v.ax=t.ds[x]>0?(k*k-v.v*v.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,v)=>l(v,x.v))}:{},...Bw(e,o,t,y.map(x=>x.v)),...b?Vw(b,d):{},...$w(e,o,t)}}var Gw=(e,t)=>{let r=e[t]?.value;return Number.isFinite(r)&&r>0?r:0};function ya(e,t,r){let n=e.m.value,o=e.r_dyn?.value??0,a=Gw(e,"I_wheel"),s=e.motorModel?.kind==="ice"?0:Gw(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,d=(l*a+s*i*i)/c,p=u*a/c,m=n+d+p;return{mass:n,driven:d,undriven:p,effective:m,powerFactor:n/m,tractionFactor:n/(n+p)}}function xa(e){let t=e.fAxle;return{drivenFront:t?t.fFront.some(r=>r>0):!1,drivenRear:t?t.fRear.some(r=>r>0):!0}}var fl=36e5,Yw=Math.PI*2,j0=e=>Math.max(0,Math.min(1,e));function U0(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=_u(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/Yw),l=Math.max(0,i*o/(n*a)),u=r.efficiency(c,l);return u>.01?u:.5}}var Kw=new WeakMap;function ri(e){if(e.batteryModel)return e.batteryModel;let t=e.capacity.value,r=e.ocv.value,n=Kw.get(e);if(n&&n.capacityAh===t&&n.ocv===r)return n.model;let o=Mh(t,r);return Kw.set(e,{capacityAh:t,ocv:r,model:o}),o}function X0(e){let t=e.params,r=Ug(t,qm(e));if(kt(t.motorModel)||Yt(t).mode!=="hydraulic")return r;let n;return(o,a,s,i=0)=>{if(!(o>0))return 0;n??=PV(e);let c=nd(n.inp,n.ev,o,a,i);return c?Math.min(o,c.regenFront+c.regenRear):r(o,a,s)}}var Hw=new WeakMap;function PV(e){let t=e.params,r=Hw.get(t);if(!r){let n=Bn(t);r={inp:jt(n.regen?t:{...t,energy:{...n,regen:!0}}),ev:un(t)},Hw.set(t,r)}return r}var hl=e=>e.airTempC??lr;function Yd(e,t){return e.thermal?e.thermal.startC??t:ss}function zw(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 Ww=()=>({windingC:[],derate:[],lossW:[],torqueNm:[],ampsRms:[]});function LV(e){let t=e.motorModel;if(kt(t))return;let r=t?_u(t).maxTorque:s=>et(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/Yw),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 DV(e,t){let r=e.motorModel?.thermal;if(!r||!t)return;let n=r.torqueConstant;return{...t,th:Sh(r),amps:o=>n>0?Math.abs(o)/n:0}}function EV(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 d=e.currentFor(l,n,o),p=u?c/l:1,m=r*p;return{dq:d*m,lossJ:d*d*e.resistance(n,o)*m,energyJ:l*m,short:c>i,cutoff:u,seconds:m}}function IV(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 _V(e){let{drivenFront:t,drivenRear:r}=xa(e);return ya(e.params,t,r)}function ni(e,t,r,n,o=Vn,a,s,i,c,l,u){let d=e.params,p=d.rho.value,m=d.fr_0.value,f=d.m.value,h=e.FG,b=d.aeroModel?jt(d):void 0,g=U0(d),y=An(ri(d)),x=y.chargeC,v=d.motorModel?.kind==="ice",k=j0(a??(v?1:d.soc.value)),R=hl(d),M=s??Yd(y,R),S=M,w=0,F=0,T=0,A=0,C=-1,P=-1,L=-1,E=i||d.motorModel?.thermal?LV(d):void 0,_=DV(d,E),D=_?_.th.startC:0,I=D,V=0,O=1,B=-1,z=0,j=0,$=X0(e),N=u?.scrub,W=_V(e),Z=N?f/W.tractionFactor:0,q=W.effective-f,Y=Math.min(t.length,r.length);for(let K=0;K<Y;K++){let ne=r[K],U=ne*ne,Q=n[K]-(c?.[K]??0),{cl:se,cw:de,A:ue}=Bd(d,ne,Q/9.81,b),ie=.5*p*se*ue*U,ve=.5*p*de*ue*U,Ie=(h+ie)*-m,je=N?-Z*(N[K]??0):0,ee=Ie+ve+je+f*Q;q>0&&(ee+=q*n[K]);let ae=ee*t[K];l?.driveN?.push(ee>0?ee:0);let Ce=K+1<r.length?r[K+1]:ne,pe=.5*(ne+Ce),me=pe>0?t[K]/pe:0,xe=0,ge=k,ke=M,Re=0,ye=0,Me=me;if(v){ee>0&&(ye=ae/g(ne,ee),w+=ye/fl),l?.netKwh.push(w-F),l?.powerKw?.push(me>0?ye/me/1e3:0);continue}if(ee>0){let fe=ae/g(ne,ee),be=EV(y,fe,me,k,M);be.short&&C<0&&(C=K),be.cutoff&&P<0&&(P=K);let Te=k*x,Fe=Math.min(be.dq,Te),Gt=be.dq>0?Fe/be.dq:1;Fe>=Te&&L<0&&(L=K),w+=be.energyJ*Gt/fl,ye=be.energyJ*Gt,Me=be.seconds,T+=be.lossJ*Gt,A+=Fe,me>0&&(Re=Fe/be.seconds),k=j0(k-Fe/x),M=zw(y,M,be.dq>0&&me>0?Fe/me:0,be.lossJ*Gt,me,R),M>S&&(S=M),xe=ee}else if(o.regen){let fe=u?lt(u.ay[K],u.bank?.[K]??0)/9.81:0,be=$(-ee,ne,Q/9.81,fe),Te=o.regenEfficiency*be*t[K],Fe=IV(y,Te,me,k,M),Gt=(1-k)*x,mt=Math.min(Fe.dq,Gt),Kt=Fe.dq>0?mt/Fe.dq:1;F+=Fe.energyJ*Kt/fl,ye=-Fe.energyJ*Kt,T+=Fe.lossJ*Kt,A-=mt,me>0&&(Re=-mt/me),k=j0(k+mt/x),M=zw(y,M,mt>0&&me>0?-mt/me:0,Fe.lossJ*Kt,me,R),M>S&&(S=M),xe=-be*Kt}if(l?.netKwh.push(w-F),l?.powerKw?.push(me>0?ye/Me/1e3:0),l?.pack){let fe=l.pack;fe.soc.push(ge),fe.amps.push(Re),fe.volts.push(y.ocv(ge)-Re*y.resistance(ge,ke)),fe.cellC.push(ke)}if(_){let fe=_.rpm(ne),be=_.th.derate(fe,D,_.peak(fe));be<O&&(O=be),be<1&&B<0&&(B=K),j+=me,be<1&&(z+=me);let Te=_.torque(xe,fe,be),Fe=_.th.lossW(fe,Te,D);V+=Fe*me,i&&(i.windingC.push(D),i.derate.push(be),i.lossW.push(Fe),i.torqueNm.push(Te),i.ampsRms.push(_.amps(Te))),D=_.th.step(D,Fe,me),D>I&&(I=D)}else E&&i&&i.torqueNm.push(E.torque(xe,E.rpm(ne),1))}return{drive:w,regen:F,net:w-F,chargeAh:A/3600,loss:T/fl,socEnd:k,shortAt:C,cutoffAt:P,emptyAt:L,tempEndC:M,tempMaxC:S,..._?{motorTempEndC:D,motorTempMaxC:I,motorLossKwh:V/fl,motorDerateMin:O,motorDerateAt:B,motorDerateTimeFrac:j>0?z/j:0}:{}}}var NV=.5,OV=.02,VV=6;function jw(e,t,r,n,o,a,s,i){let c=n(),l=1,u=f=>{let h=Ww(),b=ni(e,t,f.v,f.ax,r,o,a,h,s,void 0,{ay:f.ay,bank:i,...f.axScrub?{scrub:f.axScrub}:{}});return{trace:h,peak:b.motorTempMaxC??0,frac:b.motorDerateTimeFrac??0}},d=u(c);if(!d.trace.derate.length||d.frac===0)return{lap:c,solves:l,converged:!0,peakWindingC:d.peak,derateTimeFrac:d.frac};let p=d.trace.derate.slice(),m=!1;for(let f=0;f<VV;f++){let h=n(p);l++;let b=Math.abs(h.laptime-c.laptime);if(c=h,d=u(c),b<OV){m=!0;break}let g=d.trace.derate,y=new Array(p.length);for(let x=0;x<p.length;x++)y[x]=p[x]+NV*((g[x]??1)-p[x]);p=y}return{lap:c,derate:p,solves:l,converged:m,peakWindingC:d.peak,derateTimeFrac:d.frac}}var BV=.1;function Uw(e){if(e.motorModel?.kind==="ice")return 0;let t=e.power_limit_kw?.value??0;return t>0?t*1e3:0}function q0(e,t,r){return e.motorModel?.kind==="ice"?1/0:An(ri(e)).maxPower(t??e.soc.value,r,Uw(e)).watts}function Wd(e,t,r,n){let o=q0(e,r,n);if(!Number.isFinite(o))return 1/0;if(o<=0)return 0;let a=Math.max(BV,t),s=U0(e),i=o*.9/a;return o*s(t,i)/a}var $V=180/Math.PI;function jd(e,t,r,n){let o=e*t,a=e*(1-t);return o/r-a/n}var Ud=e=>e*9.81*$V;var GV=.1*9.81;var ane=Math.PI/180;function Xd(e,t,r,n=0){let o=We(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?jd(e.massTotal,e.frontMassFrac,2*i,2*c):0,u=Ud(l),d=u>.15?"understeer":u<-.15?"oversteer":"neutral";return{gradient:u,balance:d,cAlphaFront:i,cAlphaRear:c}}var pne=Math.PI/180,fne=180/Math.PI;var Xw=2220446049250313e-31;function zV(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 d=1/l;for(let p=0;p<t;p++)e[a][p]*=d;for(let p=0;p<t;p++)e[p][a]*=l}}}}}function YV(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 WV(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])<=Xw*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],d=e[a][a-1]*e[a-1][a];if(c===a-1){let p=.5*(u-l),m=p*p+d,f=Math.sqrt(Math.abs(m));l+=s,m>=0?(f=p+(p>=0?Math.abs(f):-Math.abs(f)),r[a-1]=r[a]=l+f,f!==0&&(r[a]=l-d/f),n[a-1]=n[a]=0):(r[a-1]=r[a]=l+p,n[a]=f,n[a-1]=-f),a-=2}else{if(i===60)throw new Error("eigenvalues: QR iteration did not converge");if(i===10||i===20||i===30||i===40||i===50){s+=l;for(let g=0;g<=a;g++)e[g][g]-=l;let b=Math.abs(e[a][a-1])+Math.abs(e[a-1][a-2]);u=l=.75*b,d=-.4375*b*b}i++;let p=a-2,m=0,f=0,h=0;for(;p>=c;p--){let b=e[p][p],g=l-b,y=u-b;m=(g*y-d)/e[p+1][p]+e[p][p+1],f=e[p+1][p+1]-b-g-y,h=e[p+2][p+1];let x=Math.abs(m)+Math.abs(f)+Math.abs(h);if(m/=x,f/=x,h/=x,p===c)break;let v=Math.abs(e[p][p-1])*(Math.abs(f)+Math.abs(h)),k=Math.abs(m)*(Math.abs(e[p-1][p-1])+Math.abs(b)+Math.abs(e[p+1][p+1]));if(v<=Xw*k)break}for(let b=p+2;b<=a;b++)e[b][b-2]=0,b!==p+2&&(e[b][b-3]=0);for(let b=p;b<=a-1;b++){b!==p&&(m=e[b][b-1],f=e[b+1][b-1],h=b!==a-1?e[b+2][b-1]:0,l=Math.abs(m)+Math.abs(f)+Math.abs(h),l!==0&&(m/=l,f/=l,h/=l));let g=Math.sqrt(m*m+f*f+h*h),y=m>=0?g:-g;if(y!==0){b===p?c!==p&&(e[b][b-1]=-e[b][b-1]):e[b][b-1]=-y*l,m+=y,l=m/y,u=f/y;let x=h/y;f/=m,h/=m;for(let k=b;k<=a;k++){let R=e[b][k]+f*e[b+1][k];b!==a-1&&(R+=h*e[b+2][k],e[b+2][k]-=R*x),e[b+1][k]-=R*u,e[b][k]-=R*l}let v=a<b+3?a:b+3;for(let k=c;k<=v;k++){let R=l*e[k][b]+u*e[k][b+1];b!==a-1&&(R+=x*e[k][b+2],e[k][b+2]-=R*h),e[k][b+1]-=R*f,e[k][b]-=R}}}}}}while(c<a-1&&a>=0)}return r.map((i,c)=>({re:i,im:n[c]}))}function qw(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 zV(r),YV(r),WV(r)}function Qw(e){let t=[],r=new Array(e.length).fill(!1),n=qw(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 Q0(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,d=-1;for(let h=c;h<r;h++)for(let b=c;b<r;b++){let g=e[h][b]*e[h][b]+t[h][b]*t[h][b];g>d&&(d=g,l=h,u=b)}if(!(d>0))break;if([e[c],e[l]]=[e[l],e[c]],[t[c],t[l]]=[t[l],t[c]],u!==c){for(let h=0;h<r;h++)[e[h][c],e[h][u]]=[e[h][u],e[h][c]],[t[h][c],t[h][u]]=[t[h][u],t[h][c]];[n[c],n[u]]=[n[u],n[c]]}let p=e[c][c],m=t[c][c],f=p*p+m*m;for(let h=c+1;h<r;h++){let b=(e[h][c]*p+t[h][c]*m)/f,g=(t[h][c]*p-e[h][c]*m)/f;if(!(b===0&&g===0))for(let y=c;y<r;y++)e[h][y]-=b*e[c][y]-g*t[c][y],t[h][y]-=b*t[c][y]+g*e[c][y]}}let o=new Array(r).fill(0),a=new Array(r).fill(0);o[r-1]=1;for(let c=r-2;c>=0;c--){let l=e[c][c],u=t[c][c],d=l*l+u*u;if(!(d>0))continue;let p=0,m=0;for(let f=c+1;f<r;f++)p+=e[c][f]*o[f]-t[c][f]*a[f],m+=e[c][f]*a[f]+t[c][f]*o[f];o[c]=-(p*l+m*u)/d,a[c]=-(m*l-p*u)/d}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 jV(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 Q0(r,n)}function qd(e,t=r=>jV(e,r)){return Qw(e).map(r=>({...r,vector:t(r.eigenvalue)}))}function Ra(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 Zw(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),d=r*(l[2].re**2+l[2].im**2);return u+d>0?[u/(u+d),d/(u+d)]:[0,0]};return Ra(qd(i),c,0)}function Jw(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=Zw({sprungMass:o,unsprungMass:e.unsprungCornerMass??e.unsprungPerCorner,springRate:s,damperRate:n,tireRate:yt(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 Qd(e,t,r){let n=Ge(e);return{front:Jw(e,n,"front",t??n.rideDampingFront),rear:Jw(e,n,"rear",r??n.rideDampingRear)}}var Cne=180/Math.PI;var Z0=["FL","FR","RL","RR"];function UV(e,t){let r=e.chassisTorsion??0;if(!(r>0)||!Number.isFinite(r))return;let n=Math.max(0,Math.min(1,e.frontMassFrac));return{stiffness:r*(180/Math.PI),inertiaFront:e.twistInertiaFront??n*t,inertiaRear:e.twistInertiaRear??(1-n)*t,massFront:n}}function XV(e){let t=e.chassis;if(!t||!(t.stiffness>0)||!(t.inertiaFront>0)||!(t.inertiaRear>0))return;let r=t.inertiaFront+t.inertiaRear,n=t.inertiaRear/r,o=-t.inertiaFront/r;return{share:[n,n,o,o],inertia:t.inertiaFront*t.inertiaRear/r,stiffness:t.stiffness,moment:t.massFront*n+(1-t.massFront)*o}}var ce={zFL:0,vzFL:1,zFR:2,vzFR:3,zRL:4,vzRL:5,zRR:6,vzRR:7,zBody:8,vzBody:9,pitch:10,pitchRate:11,roll:12,rollRate:13,x:14,vx:15,y:16,vy:17,yaw:18,yawRate:19,twist:20,twistRate:21},Zd=20,eC=[ce.zFL,ce.zFR,ce.zRL,ce.zRR],tC=[ce.vzFL,ce.vzFR,ce.vzRL,ce.vzRR],mn={fzFL:0,fzFR:1,fzRL:2,fzRR:3,fzBody:4,myBody:5,mxBody:6,fx:7,fy:8,mz:9},J0=10;function Jd(e){let t=XV(e),r=t?Zd+2:Zd,n=Array.from({length:r},()=>new Array(r).fill(0)),o=Array.from({length:r},()=>new Array(J0).fill(0));n[ce.zFL][ce.vzFL]=1,n[ce.zFR][ce.vzFR]=1,n[ce.zRL][ce.vzRL]=1,n[ce.zRR][ce.vzRR]=1,n[ce.zBody][ce.vzBody]=1,n[ce.pitch][ce.pitchRate]=1,n[ce.roll][ce.rollRate]=1,n[ce.x][ce.vx]=1,n[ce.y][ce.vy]=1,n[ce.yaw][ce.yawRate]=1;let{inertia:a}=e,s=[1,0,3,2],i=(c,l,u,d)=>{c[eC[l]]-=u,c[tC[l]]-=d,c[ce.zBody]+=u,c[ce.vzBody]+=d,c[ce.pitch]-=u*e.leverX[l],c[ce.pitchRate]-=d*e.leverX[l],c[ce.roll]+=u*e.leverY[l],c[ce.rollRate]+=d*e.leverY[l],t&&(c[ce.twist]+=u*e.leverY[l]*t.share[l],c[ce.twistRate]+=d*e.leverY[l]*t.share[l])};for(let c=0;c<4;c++){let l=c<2,u=w=>w?l?w.front:w.rear:0,d=e.springRate[c]+u(e.heaveSpring),p=e.springRate[c]+u(e.arb),m=e.damperRate[c]+u(e.heaveDamper),f=e.damperRate[c]+u(e.rollDamper),h=(d+p)/2,b=(d-p)/2,g=(m+f)/2,y=(m-f)/2,x=new Array(r).fill(0);i(x,c,h,g),(b!==0||y!==0)&&i(x,s[c],b,y);let v=e.wheelMass[c],k=e.leverX[c],R=e.leverY[c],M=eC[c],S=tC[c];for(let w=0;w<r;w++){let F=x[w];F!==0&&(n[S][w]+=F/v,n[ce.vzBody][w]-=F/e.bodyMass,n[ce.pitchRate][w]+=k*F/a.yy,n[ce.rollRate][w]-=R*F/a.xx,t&&(n[ce.twistRate][w]-=R*t.share[c]*F/t.inertia))}n[S][M]-=e.tyreRate[c]/v,n[S][S]-=e.tyreDamping[c]/v,o[S][mn.fzFL+c]=1/v}return o[ce.vzBody][mn.fzBody]=1/e.bodyMass,o[ce.pitchRate][mn.myBody]=1/a.yy,o[ce.rollRate][mn.mxBody]=1/a.xx,o[ce.vx][mn.fx]=1/e.totalMass,o[ce.vy][mn.fy]=1/e.totalMass,o[ce.yawRate][mn.mz]=1/a.zz,t?(n[ce.twist][ce.twistRate]=1,n[ce.twistRate][ce.twist]-=t.stiffness/t.inertia,o[ce.twistRate][mn.mxBody]=t.moment/t.inertia,{A:n,B:o,params:e,n:r,twist:t}):{A:n,B:o,params:e,n:r}}function ey(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,d=(e.damperRear??2.5)*1e3,p=yt(e,"front")*1e3,m=yt(e,"rear")*1e3,f=(e.tireDamping??0)*1e3,h=e.rollInertia??i*.6*.6,b=UV(e,h);return{bodyMass:i,totalMass:e.massTotal,wheelMass:[s,s,s,s],inertia:{xx:h,yy:e.pitchInertia??i*1.2*1.2,zz:e.yawInertia??e.massTotal*1.2*1.2},...b?{chassis:b}:{},leverX:[r,r,-n,-n],leverY:[o,-o,a,-a],springRate:[c,c,l,l],damperRate:[u,u,d,d],tyreRate:[p,p,m,m],tyreDamping:[f,f,f,f],arb:{front:e.arbFront*1e3,rear:e.arbRear*1e3},heaveSpring:{front:(e.heaveSpringFront??0)*1e3,rear:(e.heaveSpringRear??0)*1e3},rollDamper:{front:(e.rollDamperFront??0)*1e3,rear:(e.rollDamperRear??0)*1e3},heaveDamper:{front:(e.heaveDamperFront??0)*1e3,rear:(e.heaveDamperRear??0)*1e3}}}function rC(e){let t=Array.from({length:ce.rollRate+1},(r,n)=>n);return e.twist?[...t,ce.twist,ce.twistRate]:t}function nC(e){let t=e.params,r=e.twist,n=[...t.wheelMass,t.bodyMass,t.inertia.yy,t.inertia.xx,...r?[r.inertia]:[]];if(!n.every(u=>u>0))return{};let o=rC(e),a=o.map(u=>o.map(d=>e.A[u][d]));if(!a.every(u=>u.every(Number.isFinite)))return{};let i=qd(a,u=>{let d=u.re*u.re-u.im*u.im,p=2*u.re*u.im,m=n.map((h,b)=>n.map((g,y)=>(b===y?d:0)-u.re*a[2*b+1][2*y+1]-a[2*b+1][2*y])),f=n.map((h,b)=>n.map((g,y)=>(b===y?p:0)-u.im*a[2*b+1][2*y+1]));return Q0(m,f)}),c=u=>{let d=n.map((m,f)=>m*(u[f].re**2+u[f].im**2)),p=d.reduce((m,f)=>m+f,0)||1;return[d[0]+d[1]+d[2]+d[3],d[4],d[5],d[6],...r?[d[7]]:[]].map(m=>m/p)},l={heave:Ra(i,c,1),pitch:Ra(i,c,2),roll:Ra(i,c,3)};return r?{...l,twist:Ra(i,c,4)}:l}var sC=Math.SQRT2;function oC(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 ep(e){let t=Ge(e),r=e.wheelbase/1e3,n=r*(1-e.frontMassFrac),o=r*e.frontMassFrac,a=t.rollRateTotal*(180/Math.PI),s=e.rollInertia??t.sprungMass*.6*.6,i=2*t.rideRateFront*1e3,c=2*t.rideRateRear*1e3,l=i*n*n+c*o*o,u=e.pitchInertia??t.sprungMass*1.2*1.2,d=Jd(ey(e)),p=nC(d),m={roll:oC(p.roll,a,s),pitch:oC(p.pitch,l,u)},f=qV(d,p.twist,e);return f?{...m,twist:f}:m}function aC(e,t,r){let n=e.params,o=n.tyreRate[t]+n.springRate[t]+r;return Math.sqrt(Math.max(0,o)/n.wheelMass[t])/(2*Math.PI)}function qV(e,t,r){let n=e.twist;if(!n||!t)return;let o=aC(e,0,e.params.arb?.front??0),a=aC(e,2,e.params.arb?.rear??0),s=Math.max(o,a),i=s>0?t.freq/s:NaN;return{freq:t.freq,dampingRatio:t.dampingRatio,freeFree:Math.sqrt(n.stiffness/n.inertia)/(2*Math.PI),hopFront:o,hopRear:a,hop:s,ratio:i,meets:i>=sC,lumped:r.twistInertiaFront===void 0||r.twistInertiaRear===void 0}}var tp=9.81,Qn=Math.PI/180;function iC(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 oi(e,t,r,n,o){let{wb:a,lf:s,lr:i,m:c}=iC(e),l=0;for(let x=0;x<16;x++){let v=l/r,k=o-n-s*v/r,R=-n+i*v/r,M=We(e,l/tp,0,r),S=Math.max(0,M.FL+M.FR),w=Math.max(0,M.RL+M.RR),F=t(k,S),T=t(R,w),A=(F*Math.cos(o)+T)/c;if(l=.5*(l+A),Math.abs(A-l)<1e-4)break}let u=l/r,d=o-n-s*u/r,p=-n+i*u/r,m=We(e,l/tp,0,r),f=Math.max(0,m.FL+m.FR),h=Math.max(0,m.RL+m.RR),b=t(d,f),g=t(p,h),y=s*b*Math.cos(o)-i*g;return{ay:l/tp,cn:y/(c*tp*a)}}function ty(e,t,r,n={}){let o=Math.max(8,r),a=(n.betaMaxDeg??10)*Qn,s=(n.deltaMaxDeg??10)*Qn,i=n.nLines??9,c=n.nPts??21,l=(g,y,x,v)=>x===1?g:g+(y-g)*v/(x-1),u=[],d={ay:[],cn:[]},p=0;for(let g=0;g<i;g++){let y=l(-s,s,i,g),x=[],v=[],k=[],R=[];for(let M=0;M<c;M++){let S=l(-a,a,c,M),w=oi(e,t,o,S,y);x.push(w.ay),v.push(w.cn),k.push(S/Qn),R.push(y/Qn),Math.abs(w.ay)>p&&(p=Math.abs(w.ay))}u.push({label:`\u03B4 ${(y/Qn).toFixed(0)}\xB0`,ay:x,cn:v,betaDeg:k,deltaDeg:R});for(let M=1;M<v.length;M++)if(v[M-1]===0||v[M-1]<0!=v[M]<0){let S=v[M-1]===v[M]?0:v[M-1]/(v[M-1]-v[M]);d.ay.push(x[M-1]+S*(x[M]-x[M-1])),d.cn.push(0);break}}let m=[];for(let g=0;g<i;g++){let y=l(-a,a,i,g),x=[],v=[],k=[],R=[];for(let M=0;M<c;M++){let S=l(-s,s,c,M),w=oi(e,t,o,y,S);x.push(w.ay),v.push(w.cn),k.push(y/Qn),R.push(S/Qn)}m.push({label:`\u03B2 ${(y/Qn).toFixed(0)}\xB0`,ay:x,cn:v,betaDeg:k,deltaDeg:R})}let f=.5*Qn,h=(oi(e,t,o,f,0).cn-oi(e,t,o,-f,0).cn)/(2*f),b=(oi(e,t,o,0,f).cn-oi(e,t,o,0,-f).cn)/(2*f);return{isoBeta:m,isoDelta:u,trim:d,maxAy:p,stability:h,control:b,speed:o}}function QV(e){return!e.corneringStiffnessFront||!e.corneringStiffnessRear?null:{Cf:2*e.corneringStiffnessFront,Cr:2*e.corneringStiffnessRear}}function bl(e,t){let r=QV(e);if(!r)return null;let{Cf:n,Cr:o}=r,{wb:a,lf:s,lr:i,m:c}=iC(e),l=e.yawInertia??c*1*1,u=Math.max(3,t),d=-(n+o)/(c*u),p=(-s*n+i*o)/(c*u)-u,m=(-s*n+i*o)/(l*u),f=-(s*s*n+i*i*o)/(l*u),h=d+f,b=d*f-p*m,g=h*h-4*b,y,x,v;if(g<0)y=h/2,x=Math.sqrt(Math.max(0,b)),v=x>0?-h/(2*x):1;else{let P=Math.sqrt(g);y=Math.max((h+P)/2,(h-P)/2),x=Math.sqrt(Math.abs(b)),v=x>0?-h/(2*x):1}let k=h<0&&b>0,R=jd(c,e.frontMassFrac,n,o),M=Ud(R),S=M>.15?"understeer":M<-.15?"oversteer":"neutral",w=s*n-i*o,F=P=>P*3.6,T=null,A=null;w>1e-6?A=F(Math.sqrt(n*o*a*a/(c*w))):w<-1e-6&&(T=F(Math.sqrt(n*o*a*a/(c*-w))));let C=u/(a+R*u*u);return{stable:k,yawFreq:x/(2*Math.PI),dampingRatio:v,eigReal:y,understeerGradient:M,balance:S,characteristicSpeed:T,criticalSpeed:A,yawRateGain:C}}var ZV={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"}},ry=Object.keys(ZV),gl=["envelopeTrim","envelopeLimits","qssLap","tyreReadouts","ymd"];var JV="the longitudinal condition is set directly; what a motor could deliver is the lap solver\u2019s question",e3="no tractive force is applied at a constant speed",ny="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)",oy="Drive runs no torque vectoring: its aids are ABS and traction control",cC="the readouts split the drive by room or through the diff, never by a controller",t3=[{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:gl,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:gl,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:gl,why:"inertia resists change; a steady corner has none"},{key:"I_pitch",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no pitch dynamics (reduced planner model)"},...["I_twist_front","I_twist_rear"].flatMap(e=>[{key:e,tools:gl,why:"inertia resists change; a steady corner has none"},{key:e,tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no twist dynamics (reduced planner model)"}]),...["capacity","ocv","soc"].flatMap(e=>[{key:e,tools:["ymd"],why:"energy does not enter a single steady-state point"},{key:e,tools:ry.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:gl,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:ny},{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:oy},{key:"tv_enabled",tools:["transientPlant","stepSteer"],why:ny},{key:"tv_enabled",tools:["drive"],why:oy},{key:"tv_enabled",tools:["tyreReadouts"],why:cC,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:ny},{key:e,tools:["drive"],why:oy},{key:e,tools:["tyreReadouts"],why:cC,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:e3,ymd:{moving:JV}})),...["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:ry.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:ry.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 lC(e=0){let t=[],r=new Set;for(let n of t3){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 uC=Math.PI/180;function pC(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 mC(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 fC(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[d,p]of[[s,1-c],[Math.min(o-1,s+1),c]])if(!(p<=0))for(let[m,f]of[[i,1-l],[Math.min(a-1,i+1),l]])f<=0||(u+=p*f*n(e.isoDelta[d],m,d));return u}function hC(e,t,r){let n=e.isoDelta[0],o=(n.betaDeg[1]-n.betaDeg[0])*uC||1,a=e.isoDelta.length>1?(e.isoDelta[1].deltaDeg[0]-e.isoDelta[0].deltaDeg[0])*uC:1,s=R=>fC(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]),d=s((R,M)=>mC(R.cn,M,o)),p=s((R,M,S)=>mC(e.isoDelta.map(w=>w.cn[M]),S,a||1)),m=Math.max(1e-6,e.maxAy),f=Math.abs(i)/m,h=Math.max(1e-6,...e.isoDelta.flatMap(R=>R.cn.filter(Number.isFinite).map(Math.abs))),b=Math.abs(c)/h,g=i===0?c:c*Math.sign(i),y=[];y.push(`${pC(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?d/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 v=Math.abs(e.control),k=v>1e-9?Math.abs(p)/v:1;return k<.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."):k<.5&&y.push(`Steering response is down to about ${(100*k).toFixed(0)} % of its straight-ahead value \u2014 the front is well into the non-linear part of its curve.`),f>.97?y.push(`At the edge of the diagram: ${Math.abs(i).toFixed(2)} g is essentially all this car has at this speed.`):f<.25&&y.push("Well inside the limit \u2014 this is the linear region the handling balance is measured in."),{ay:i,cn:c,betaDeg:l,deltaDeg:u,stability:d,control:p,gripUsed:f,notes:y}}var dC=1e-4;function ay(e){let t=null,r=p=>{if(!t)return!0;let m=Math.abs(p),f=Math.abs(t.ay);return m>f*(1+dC)?!0:m<f*(1-dC)?!1:p>0&&t.ay<0};for(let p=0;p<e.isoDelta.length;p++){let m=e.isoDelta[p];for(let f=1;f<m.cn.length;f++){if(!(m.cn[f-1]===0||m.cn[f-1]<0!=m.cn[f]<0))continue;let b=m.cn[f-1]===m.cn[f]?0:m.cn[f-1]/(m.cn[f-1]-m.cn[f]),g=m.ay[f-1]+b*(m.ay[f]-m.ay[f-1]);r(g)&&(t={ay:g,d:p,b:b<.5?f-1:f})}}if(!t)return null;let n=hC(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,d=t.ay<0?-1:1;return{ay:Math.abs(t.ay),turn:d,betaDeg:e.isoDelta[t.d].betaDeg[t.b]*d,deltaDeg:e.isoDelta[t.d].deltaDeg[t.b]*d,d:t.d,b:t.b,limitedBy:c,controlFrac:o,stiffnessFrac:a,onGridEdge:u}}function bC(e=0){return lC(e)}var r3=bC(0);function gC(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 n3=gC(0);var o3=9.81;function a3(e){let t=e.wheelbase/1e3;return{lf:t*(1-e.frontMassFrac),lr:t*e.frontMassFrac}}function yl(e,t,r,n){let o=t.tire;if(!o)return null;let s=(r==="limit"?R0(e,o,t.speed):ko(e,o,t.speed,t.ayG)).wheels;return Dn(n??sa(o,e.massTotal*o3*1.2),{FL:s.FL,FR:s.FR,RL:s.RL,RR:s.RR},a3(e))}function s3(e){if(!e.tire)return e.cornerStiffness;let t=we(e.tire,"front"),r=we(e.tire,"rear");return{front:n=>t.corneringStiffness(n),rear:n=>r.corneringStiffness(n)}}var yC=[{key:"understeer",label:"Understeer gradient",unit:"\xB0/g",compute:(e,t)=>Xd(e,t.ayG,s3(t),t.speed).gradient},{key:"rollGradient",label:"Roll gradient",unit:"\xB0/g",compute:e=>Ge(e).rollGradient},{key:"pitchGradient",label:"Pitch gradient",unit:"\xB0/g",compute:e=>Ge(e).pitchGradient},{key:"tlltdFront",label:"TLLTD front",unit:"%",compute:e=>100*cc(e)},{key:"rollStiffFront",label:"Front roll-stiffness",unit:"%",compute:e=>100*Ge(e).frontRollStiffFrac},{key:"rideFreqFront",label:"Ride freq front",unit:"Hz",compute:e=>Ge(e).rideFreqFront},{key:"rideFreqRear",label:"Ride freq rear",unit:"Hz",compute:e=>Ge(e).rideFreqRear},{key:"rollFreq",label:"Roll-mode freq",unit:"Hz",compute:e=>ep(e).roll.freq},{key:"pitchFreq",label:"Pitch-mode freq",unit:"Hz",compute:e=>ep(e).pitch.freq},{key:"zetaFront",label:"Damping \u03B6 front",unit:"-",compute:e=>Qd(e).front.dampingRatio},{key:"zetaRear",label:"Damping \u03B6 rear",unit:"-",compute:e=>Qd(e).rear.dampingRatio},{key:"yawFreq",label:"Yaw natural freq",unit:"Hz",compute:(e,t)=>bl(e,t.speed)?.yawFreq??NaN},{key:"yawZeta",label:"Yaw damping \u03B6",unit:"-",compute:(e,t)=>bl(e,t.speed)?.dampingRatio??NaN},{key:"stabilitySpeed",label:"Char./critical speed",unit:"km/h",compute:(e,t)=>{let r=bl(e,t.speed);return r?r.criticalSpeed??r.characteristicSpeed??NaN:NaN}},{key:"maxAy",label:"Max lateral accel",unit:"g",compute:(e,t)=>t.fyAxle?ty(e,t.fyAxle,t.speed,{betaMaxDeg:12,deltaMaxDeg:12}).maxAy:NaN},{key:"yawReserveRear",label:"Yaw stability reserve",unit:"N\xB7m",compute:(e,t)=>yl(e,t,"operating")?.stabil??NaN},{key:"yawReserveFront",label:"Yaw agility reserve",unit:"N\xB7m",compute:(e,t)=>yl(e,t,"operating")?.agil??NaN},{key:"limitBalance",label:"Limit balance (+US / \u2212OS)",unit:"-",compute:(e,t)=>yl(e,t,"limit")?.rel??NaN},{key:"yawStiffness",label:"Yaw stiffness N_\u03B2",unit:"N\xB7m/rad",compute:(e,t)=>t.tire?x0(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorque",label:"Steering holding torque",unit:"N\xB7m",compute:(e,t)=>t.tire?g0(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorqueGradient",label:"Steering feedback gradient",unit:"N\xB7m/g",compute:(e,t)=>t.tire?y0(e,t.tire,t.speed,t.ayG):NaN}],sy=Object.fromEntries(yC.map(e=>[e.key,e]));var dn=9.81;function i3(e,t,r){let n=Math.abs(e);return n>0?t>0&&(n<=t||t>=r)?n/t:r>0?1+(n-t)/r:2:0}var c3={front:!1,rear:!0};function ai(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*Vb(n,t,s):o*Math.sqrt(1-s*s)}function xC(e,t,r,n,o,a,s,i){let c=e[t]+e[r];if(!(c>0))return;let l=ai(n,o[t],a[t],i),u=ai(n,o[r],a[r],i),d=!(l+u>0);if(d&&(l=n.muX(o[t])*o[t],u=n.muX(o[r])*o[r]),!(l+u>0))return;let p=s?.[t],m=s?.[r];if(p===void 0&&m===void 0){e[t]=c*(l/(l+u)),e[r]=c-e[t];return}let f=[Math.min(l,p??1/0),Math.min(u,m??1/0)],h=d?void 0:RC(n,o,a,t,r,l,u,s,i);if(h&&c>f[0]+f[1]){let b=Math.min(c-h.capC,h.xMax),g=Math.min(a[h.o],h.fyO(b));a[h.c]+=a[h.o]-g,a[h.o]=g,e[h.o]=b,e[h.c]=c-b;return}e[t]=vC(c,f,[l,u])[0],e[r]=c-e[t]}function RC(e,t,r,n,o,a,s,i,c){let l=i[n]??1/0,u=i[o]??1/0,d,p,m;if(l<a&&!(u<s))[d,p,m]=[n,o,s];else if(u<s&&!(l<a))[d,p,m]=[o,n,a];else return;let f=i[d],h=i[p]??1/0,b=e.muX(t[p])*t[p],g=e.muY(t[p])*t[p],y=e.muX(t[d])*t[d],x=e.muY(t[d])*t[d];if(!(b>0&&g>0&&y>0&&x>0))return;let v=(T,A)=>c?aM(c,T,A):Math.sqrt(Math.max(0,1-A*A)),k=(T,A)=>c?Vb(c,T,A):Math.sqrt(Math.max(0,1-A*A)),R=T=>g*v(t[p],T/b),M=x*v(t[d],f/y),S=r[d]+r[p]-M,w=Math.min(h,b*k(t[p],0)),F=S<=0?w:Math.max(m,Math.min(w,S<g?b*k(t[p],S/g):0));return{c:d,o:p,capC:f,xMax:F,fyO:R}}function vC(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 kC(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?$c(b,g,y):s==="own"?b+g:2*Math.min(b,g),u={FL:ai(n,t.FL,r.FL,c?.front),FR:ai(n,t.FR,r.FR,c?.front),RL:ai(o,t.RL,r.RL,c?.rear),RR:ai(o,t.RR,r.RR,c?.rear)},d=(b,g)=>u[g],p=l(u.FL,u.FR,a.front),m=l(u.RL,u.RR,a.rear);if(i&&i.total>0&&p+m>0){let b=(R,M)=>Math.min(d(R,M),i.caps[M]??1/0),g=(R,M,S,w,F)=>{let T=M==="FL"?c?.front:c?.rear,A=w||s!=="own"?void 0:RC(R,t,r,M,S,d(R,M),d(R,S),i.caps,T),C=A?A.capC+A.xMax:l(b(R,M),b(R,S),w);return[C,Math.max(F,C)]},[y,x]=g(n,"FL","FR",a.front,p),[v,k]=g(o,"RL","RR",a.rear,m);return vC(i.total,[y,v],[x,k])[0]/i.total}if(p+m>0)return p/(p+m);let f=n.muX(t.FL)*t.FL+n.muX(t.FR)*t.FR,h=o.muX(t.RL)*t.RL+o.muX(t.RR)*t.RR;return f+h>0?f/(f+h):.5}function iy(e,t,r,n){return{car:t?AC(t,r.loadFactor[n]):e,ayTyre:lt(r.ay[n],r.bank?.[n]??0),axCar:r.ax[n]-(r.axGrade?.[n]??0)}}function MC(e,t){if(!e.aero?.model)return 0;let r=Math.min(t.v.length,t.ax.length,t.ay.length),n=t.loadFactor?np(e):void 0,o=0,a=0;for(let s=0;s<r;s++){let i=t.ds?.[s]??1,c=iy(e,n,t,s);o+=i,Ib(c.car,t.v[s],c.axCar/dn,c.ayTyre/dn)&&(a+=i)}return o>0?a/o:0}function SC(e,t,r){let n=Or(we(t,"front")),o=Or(we(t,"rear")),a=Math.min(r.v.length,r.ax.length,r.ay.length),s=r.loadFactor?np(e):void 0,i=0,c=0;for(let l=0;l<a;l++){let u=r.ds?.[l]??1,d=iy(e,s,r,l);i+=u;let p=We(d.car,d.ayTyre/dn,d.axCar/dn,r.v[l]);(p.FL>n||p.FR>n||p.RL>o||p.RR>o)&&(c+=u)}return i>0?c/i:0}function rp(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=Hs(t,e.massTotal*dn*1.2),l=Ls(c,"front"),u=Ls(c,"rear"),d={mu:1},p=$=>({muX:N=>d.mu*$.muX(N),muY:N=>d.mu*$.muY(N)}),m=r.mu?p(l):l,f=r.mu?u===l?m:p(u):u,h=r.mu?{front:m,rear:f}:c,b=zt(we(t,"front")),g=zt(we(t,"rear")),y=Bb(b,l),x=g===b?y:Bb(g,u),v={front:y,rear:x},k=n.driven??c3,R={front:mr(e,"front",1),rear:mr(e,"rear",1)},M={front:0,rear:0},S=new Array(o),w=new Array(o),F=new Array(o),T=1/0,A=0,C=0,P=Or(b),L=Or(g),E=0,_=0,D=0,I=0,V=0,O=0,B=["FL","FR","RL","RR"],z=n.perWheel?Object.fromEntries(B.map($=>[$,{Fz:new Array(o),alpha:new Array(o),Fy:new Array(o),Fx:new Array(o),Mz:new Array(o),used:new Array(o),FxCap:new Array(o),FyCap:new Array(o)}])):void 0,j=r.loadFactor?np(e):void 0;for(let $=0;$<o;$++){let N=iy(e,j,r,$),{ayTyre:W,axCar:Z}=N,q=W/dn,Y=We(N.car,q,Z/dn,r.v[$]),K=r.mu?zd(r.mu,$):1;d.mu=K;let ne=e.massTotal*W,U=ne*i/a,Q=ne*s/a,se=xc(b,U/K,Y.FL,Y.FR,V),de=xc(g,Q/K,Y.RL,Y.RR,O);V=se,O=de;let ue={FL:K*Math.abs(b.Fy(se,Y.FL,0)),FR:K*Math.abs(b.Fy(se,Y.FR,0)),RL:K*Math.abs(g.Fy(de,Y.RL,0)),RR:K*Math.abs(g.Fy(de,Y.RR,0))},ie=(Z-(r.axDrag?.[$]??0)-(r.axScrub?.[$]??0))/dn,ve=r.wheelMotor,Ie=ve?Object.fromEntries(B.flatMap(Re=>ve[Re]?[[Re,ve[Re][$]*e.massTotal]]:[])):void 0,je=Ie?{total:ie*dn*e.massTotal,caps:Ie}:void 0,ee=ie>0&&k.front?kC(k,Y,ue,m,f,R,"own",je,v):0,ae=r.v[$]*r.v[$],Ce=e.driveline?{Fz:Y,alpha:{front:se,rear:de},curvature:ae>1?r.ay[$]/ae:0,seed:M,...K!==1?{grip:K}:{}}:void 0,pe={...h0(e,ie,r.v[$],t,q,ee,Ce,K)};ie>0&&(R.front||xC(pe,"FL","FR",m,Y,ue,Ie,y),R.rear||xC(pe,"RL","RR",f,Y,ue,Ie,x));let me=!1,xe=!1;for(let Re of["FL","FR","RL","RR"]){let ye=(Re==="FL"||Re==="FR"?m:f).muX(Y[Re])*Y[Re];Math.abs(pe[Re])>ye&&(me=!0),Y[Re]>(Re==="FL"||Re==="FR"?P:L)&&(xe=!0)}xe&&(C+=r.ds?.[$]??1);let ge=Dn(h,{FL:{Fz:Y.FL,Fy:ue.FL,Fx:pe.FL},FR:{Fz:Y.FR,Fy:ue.FR,Fx:pe.FR},RL:{Fz:Y.RL,Fy:ue.RL,Fx:pe.RL},RR:{Fz:Y.RR,Fy:ue.RR,Fx:pe.RR}},{lf:s,lr:i});if(S[$]=ge.stabil,w[$]=ge.agil,F[$]=ge.rel,z){let Re=.5*(Y.FL+Y.FR),ye=.5*(Y.RL+Y.RR),Me=m.muX(Re)*Re,fe=f.muX(ye)*ye;for(let be of B){let Te=Y[be],Fe=be==="FL"||be==="FR",Gt=Fe?m:f,mt=Gt.muY(Te)*Te,Kt=Gt.muX(Te)*Te,De=z[be],Be=Fe?se:de;De.Fz[$]=Te,De.alpha[$]=Be,De.Fy[$]=ue[be],De.Fx[$]=pe[be],De.Mz[$]=Te>0?K*(Fe?b:g).Mz(Be,Te,0):0,De.FxCap[$]=Kt,De.FyCap[$]=mt;let gt=mt>0?Math.min(1,Math.abs(ue[be])/mt):0,_e=i3(pe[be],Kt,Fe?Me:fe),Ze=Fe?y:x,Tr=Ze&&Te>0?Ze.reach(Te,Math.sign(pe[be])*_e,gt):1;De.used[$]=Math.hypot(gt,_e)/Tr}}ge.stabil<T&&(T=ge.stabil,A=$);let ke=r.ds?.[$]??1;I+=ke,ge.diff>0&&(E+=ke),me&&(_+=ke),Ib(N.car,r.v[$],Z/dn,q)&&(D+=ke)}return{stabil:S,agil:w,rel:F,minStabil:Number.isFinite(T)?T:0,minStabilAt:A,pastTurnoverFrac:I>0?C/I:0,understeerFrac:I>0?E/I:0,beyondFrac:I>0?_/I:0,aeroOutsideFrac:I>0?D/I:0,wheels:z}}function np(e){return Object.create(e,{loadFactor:{value:1,writable:!0,enumerable:!0}})}function AC(e,t){return e.loadFactor=t,e}var cy=9.81;function ly(e,t,r,n={}){let o=r.v.length,a=e.massTotal,s=Gn(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],d=r.ax[l]-(r.axGrade?.[l]??0),p=d-(r.axDrag?.[l]??0)-(r.axScrub?.[l]??0),m=-a*p;if(!(m>0))continue;let f=lt(r.ay[l],r.bank?.[l]??0)/cy,h=Math.min(.99,Math.max(.01,Bs(e,p/cy,u,t,f)));c.front[l]=m*h,c.rear[l]=m*(1-h);let b=i?nd(e,t,m,u,f):void 0;if(c.regen&&n.regen&&(c.regen[l]=b?Math.min(m,b.regenFront+b.regenRear):n.regen(m,u,d/cy)),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(m,u),u);c.pFront[l]=g.pFront,c.pRear[l]=g.pRear,c.pedalN[l]=g.pedalN}}return c}var Boe=Math.PI/180;var $oe=Z0.map(Xc);var Goe=[ce.zFL,ce.zFR,ce.zRL,ce.zRR];var k3=9.81,M3=.001,S3=.6,A3=2,TC=4;function PC(e,t,r,n=TC){let o=Math.min(e.v.length,t.npts),{ds:a,closed:s}=t,i=r.massTotal*k3*r.wheelbase,c=w3(e.ay.slice(0,o).map((d,p)=>d/Math.max(M3,e.v[p])),a,s,n),l=new Array(o).fill(0),u=new Array(o).fill(0);if(!(i>0))return{demand:l,rdot:u};for(let d=0;d<o;d++){let p=d===0?s?o-1:-1:d-1,m=d===o-1?s?0:-1:d+1;if(p<0||m<0)continue;let f=a[p]+a[d];if(!(f>0))continue;u[d]=e.v[d]*(c[m]-c[p])/f;let h=Math.sign(c[d]);l[d]=h===0?0:h*r.yawInertia*u[d]/i}return{demand:l,rdot:u}}function w3(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],d=1,p=0;for(let m=1;m<=s&&!(!r&&c+m>=o||(p+=t[(c+m-1)%o],!(p<l)));m++){let f=1-p/l;u+=f*e[(c+m)%o],d+=f}p=0;for(let m=1;m<=s&&!(!r&&c-m<0);m++){let f=(c-m+o)%o;if(p+=t[f],!(p<l))break;let h=1-p/l;u+=h*e[f],d+=h}i[c]=u/d}return i}function LC(e,t,r,n,o={}){let a=o.maxIter??20,s=o.tol??.001,i=Math.min(1,Math.max(.001,o.relax??S3)),c=o.smoothM??TC,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=er(e.steady,t,n,l),d=[u.laptime],p=new Array(t.npts).fill(0),m=p.slice(),f=u,h=0,b=!1,g=0;for(let v=0;v<a;v++){h=v+1;let k=PC(f,t,r,c);p=k.demand.map((S,w)=>p[w]+i*(S-p[w])),m=k.rdot;let R=er(e.steady,t,n,{...l,envelope:S=>e.at(p[S]??0)});d.push(R.laptime);let M=Math.abs(R.laptime-f.laptime);if(f=R,g=M<=s?g+1:0,g>=A3){b=!0;break}}let y=0,x=0;for(let v=0;v<t.npts;v++)x+=t.ds[v],e.clamps(p[v]??0)&&(y+=t.ds[v]);return{...f,steady:u,demand:p,rdot:m,history:d,iterations:h,converged:b,clampedFrac:x>0?y/x:0}}var qoe=Math.PI/180;var Nae=180/Math.PI;function EC(e,t,r){let n=e.length-1;if(!(r<e[n]))return t[n];let o=0,a=n;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function H3(e,t,r,n,o){let a=e.grip(o),s=t.atLock?n*n/t.ayMax:e.lockRadius,i=a*r.ayMax,c=s>0&&Number.isFinite(s)?o*o/s:1/0,l=c<i,u=l?c:i,d=l&&i>0?c/i:1,{norm:p}=e,m=h=>p.map(b=>a*EC(p,h,b*d)),f=h=>d===1?h:p.map(b=>EC(p,h,b*d));return{ayMax:u,axAccelN:m(r.axAccelN),axDecelN:m(r.axDecelN),axScrubN:m(r.axScrubN),...r.motorTyreN?{motorTyreN:r.motorTyreN.map(f)}:{},...r.motorLoss?{motorLoss:f(r.motorLoss)}:{},...r.motorGain?{motorGain:r.motorGain.map(f)}:{},atLock:l}}var z3=5,uy=1;function Zn(e,t,r){let n=e.length;if(n===1||r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0;for(;o<n-2&&e[o+1]<=r;)o++;let a=e[o],s=e[o+1],i=t[o],c=t[o+1];if(n===2)return i+(r-a)/(s-a)*(c-i);let l=p=>{let m=e[p];return i*(r-s)*(r-m)/((a-s)*(a-m))+c*(r-a)*(r-m)/((s-a)*(s-m))+t[p]*(r-a)*(r-s)/((m-a)*(m-s))},u=(r-a)/(s-a),d=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),d))}function IC(e,t,r){let n=Y3(e,t);if(!r||!(t>0))return n;let o=n(t);return a=>a<t?H3(r,e[0],o,t,a):n(a)}function Y3(e,t){let r=e.filter(m=>m.atLock),n=e.filter(m=>!m.atLock),o=r.length>0&&n.length>0&&r[r.length-1].v<n[0].v,a=m=>({vs:m.map(h=>h.v),ayMax:m.map(h=>h.ayMax),radius:m.map(h=>Math.max(h.v,t)**2/h.ayMax),accel:m[0].axAccelN.map((h,b)=>m.map(g=>g.axAccelN[b])),decel:m[0].axDecelN.map((h,b)=>m.map(g=>g.axDecelN[b])),scrub:m[0].axScrubN.map((h,b)=>m.map(g=>g.axScrubN[b])),motors:m.every(h=>h.motorTyreN&&h.motorLoss)?{tyreN:m[0].motorTyreN.map((h,b)=>h.map((g,y)=>m.map(x=>x.motorTyreN[b][y]))),loss:m[0].motorLoss.map((h,b)=>m.map(g=>g.motorLoss[b])),gain:m.every(h=>h.motorGain)?m[0].motorGain.map((h,b)=>h.map((g,y)=>m.map(x=>x.motorGain[b][y]))):void 0}:void 0}),s=(m,f)=>({axAccelN:m.accel.map(h=>Zn(m.vs,h,f)),axDecelN:m.decel.map(h=>Zn(m.vs,h,f)),axScrubN:m.scrub.map(h=>Zn(m.vs,h,f)),...m.motors?{motorTyreN:m.motors.tyreN.map(h=>h.map(b=>Zn(m.vs,b,f))),motorLoss:m.motors.loss.map(h=>Zn(m.vs,h,f)),...m.motors.gain?{motorGain:m.motors.gain.map(h=>h.map(b=>Zn(m.vs,b,f)))}:{}}:{}});if(!o){let m=a(e);return f=>({ayMax:Zn(m.vs,m.ayMax,f),...s(m,f),atLock:!1})}let i=a(r),c=a(n),l=i.vs[i.vs.length-1],u=c.vs[0],d=m=>Math.max(m,t)**2/Zn(i.vs,i.radius,m),p=m=>m>=u||c.vs.length<2?Zn(c.vs,c.ayMax,m):c.ayMax[0]+(c.ayMax[1]-c.ayMax[0])/(c.vs[1]-c.vs[0])*(m-u);return m=>{if(m<=l)return{ayMax:d(m),...s(i,m),atLock:!0};if(m>=u)return{ayMax:p(m),...s(c,m),atLock:!1};let f=d(m),h=p(m);return f<h?{ayMax:f,...s(i,m),atLock:!0}:{ayMax:h,...s(c,m),atLock:!1}}}function W3(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 _C(e,t,r,n,o,a){let s=r>t?Math.max(2,Math.min(z3,Math.floor(n))):1,i=[];for(let m=0;m<s;m++)i.push(e(s===1?t:t+(r-t)*m/(s-1)));let c=IC(i,t,a),l=[],u=s,d=(m,f)=>{let h=.5*(m+f),b=e(h);u++;let g=W3(c(h),b);i.splice(i.findIndex(y=>y.v>h),0,b),c=IC(i,t,a),g>o&&l.push({lo:m,hi:h,misfit:g},{lo:h,hi:f,misfit:g})},p=i.map(m=>m.v);for(let m=0;m+1<p.length&&u<n;m++)p[m+1]-p[m]>=uy&&d(p[m],p[m+1]);if(p.length>1){let m=.5*(p[0]+p[1]);if(i.some(f=>f.v===m))for(let[f,h]of[[p[0],m],[m,p[1]]]){if(u>=n||h-f<uy)break;let b=l.findIndex(g=>g.lo===f&&g.hi===h);b>=0&&l.splice(b,1),d(f,h)}}for(;u<n&&l.length>0;){let m=0;for(let g=1;g<l.length;g++)l[g].misfit>l[m].misfit&&(m=g);let{lo:f,hi:h,misfit:b}=l.splice(m,1)[0];if(b<=o)break;h-f<uy||d(f,h)}return{anchors:i,at:c}}function NC(e,t){let r=Math.abs(t);return!(r>0)||!(e>0)?1/0:e/Math.tan(Math.min(r,1.5))}function OC(e){if(!e?.meanDeg?.length)return 0;let t=0;for(let r of e.meanDeg)t=Math.max(t,Math.abs(r));return t*Math.PI/180}var j3=2,U3=.5,xl=Math.PI/180,VC=21,X3={nCoarse:11,nSteer:13,nNorm:41,nAngle:45},q3={nCoarse:11,nSteer:13,nNorm:41,nAngle:61},Q3=.005,Z3=.05,J3=.5,my=e=>e<0?0:e>1?1:e;function BC(e,t,r,n){let o=e.massTotal,a=n.nSteer??7,s=(n.drivenFront?2:0)+(n.drivenRear?2:0),i=We(e,0,0,r),c=Math.max(1,(i.FL+i.FR+i.RL+i.RR)/4),l=8*xl,u=0,d=(b,g,y)=>{for(let x=b;x<=g;x+=y){let v=Math.abs(t.Fy(x*xl,c,0));v>u&&(u=v,l=x*xl)}};d(1,45,1),d(Math.max(.1,l/xl-1),l/xl+1,.1);let p=[],m=[],f=[],h=[];for(let b=0;b<a;b++){let g=b/(a-1),y=l*(g+Math.sin(Math.PI/2*g))/2,x=Math.abs(t.Fy(y,c,0));p.push(4*x/o),m.push(s*cr(t,c,x,!1)/o),f.push(4*cr(t,c,x,!0)/o),h.push(-4*x*Math.sin(y)/o)}return p[0]=0,{ayMax:4*u/o,ay:p,axAccel:m,axDecel:f,axScrub:h,rollover:!1}}function eB(e,t,r){if(e.engine)return;let n=ha(e.params),o=Br(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 tB=.001;function $C(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 rB=.01,nB=.05;function GC(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 Rl(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}=GC(e,t,r,a);if(!(i>0))return s;let l=e.motorLoss?.[t]??1;if(r===1&&n>=1||!o.every(f=>f.gain)){let f=r>=1?l:l/(r+l*(1-r));return Math.max(c,s-f*i)}let u=Math.min(s,KC(e,t,r,a)),d=GC(e,t,1,e.axDrive);if(!(d.short>0))return Math.max(c,u);let m=Math.max(d.theirs,e.axAccelN[t]-l*d.short)-Math.min(e.axAccelN[t],KC(e,t,1,e.axDrive));return Math.max(c,Math.min(s,u+m*(i/d.short)))}function KC(e,t,r,n){let o=e.motors,a=r*e.axAccelN[t],s=a;for(let i=0;i<=o.length+1;i++){let c=0,l=0,u=0;for(let p of o){let m=r*p.gain[t],f=r*p.tyreN[t]*e.axAccelN[t],h=p.share>0?p.share*n:0,b=f+m*(s-a);u+=Math.min(h,b),(m>0?b<=h:b<h)?(l+=m,c+=f-m*a):c+=h}if(!(u<s))return s;if(!(l<1))return 0;let d=c/(1-l);if(!(d<s))return s;s=d}return s}function dy(e,t,r,n,o){if(!e.motors)return 1/0;let a=t.length-1;if(!(r<t[a]))return Rl(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=Rl(e,s,n,o);return c===0?l:l+c*(Rl(e,i,n,o)-l)}function pn(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?q3:X3),{nCoarse:c,nSteer:l,nAngle:u}=i,d=$n(0,1,i.nNorm).map(K=>Math.sin(Math.PI/2*K)),p=e.params,m=p.m.value,f=p.rho.value,h=p.fr_0.value,b=p.driven_wheels.value,g=p.power_scale.value,y=e.FG,x=jt(p);s!==1&&(x.loadFactor=s);let v=un(p),k=LS(0,n?.vRes??(e.engine?U3:j3),e.vMax);k[k.length-1]<e.vMax&&k.push(e.vMax);let R=e.fRad.map(K=>K*b),M=e.fAxle,{drivenFront:S,drivenRear:w}=xa(e),F=ya(p,S,w),T=(K,ne,U)=>{let Q=Ct(K,ne,Math.max(U,K[0]));return Number.isFinite(Q)?Q:1/0},A=(K,ne)=>M?T(M.vVehicle,K,ne):1/0,C=r==="fast"?void 0:eB(e,S,w),P=Br(p),L=(K,ne)=>{if(M){let Q=A(M.fFront,ne),se=A(M.fRear,ne),de=K.map(ie=>(ie.axle==="front"?Q:se)*(ie.motors/P[ie.axle])),ue=de.reduce((ie,ve)=>ie+ve,0);if(Number.isFinite(ue)&&ue>0)return de.map(ie=>ie/ue)}let U=K.reduce((Q,se)=>Q+se.motors,0);return K.map(Q=>Q.motors/U)},E=K=>{let ne=K*K,{cl:U,cw:Q,A:se}=Bd(p,K,0,x),de=.5*f*-Q*se*ne,ue=.5*f*-U*se*ne,ie=h*(-ue+y);return de+ie},_=K=>{let ne=E(K)/m*F.powerFactor,U=E(K)/m*F.tractionFactor,Q;if(e.engine){let de=E(K);Q=Os(e.engine,K,F.effective,de,g).accel-ne}else if(M){let de=0;S&&(de+=A(M.fFront,K)),w&&(de+=A(M.fRear,K)),Q=g*de/m*F.powerFactor}else{let de=T(e.vVehicle,R,K),ue=g*de/m*F.powerFactor;Q=Number.isFinite(ue)?ue:1/0}let se=Wd(p,K,o)/m*F.powerFactor;return{axDrag:ne,axDragTyre:U,axDrive:Q,axPackCap:se,axPower:Math.min(Q,se)}},D=k.map(_),I=e.vMax;for(let K=1;K<k.length;K++){let ne=D[K].axDrive+D[K].axDrag;if(ne>0)continue;let U=D[K-1].axDrive+D[K-1].axDrag;I=U>0?k[K-1]+(k[K]-k[K-1])*U/(U-ne):k[K-1];break}let V=Math.min(e.vMax,(1+Z3)*I),O=r==="fast"?BC:k0,B=K=>{let ne=C?_(K).axDrive:1/0,U=C&&Number.isFinite(ne)?L(C,K).map((pe,me)=>({wheels:C[me].wheels,cap:pe*ne*m/F.tractionFactor})):void 0,Q=O(x,v,K,{drivenFront:S,drivenRear:w,nSteer:l,yawDemandCn:a,axDrag:E(K)/m,...p.diffYaw?{diffYaw:!0}:{},...U?{motorCaps:U}:{}}),se=Q.ay[0],de=Q.ay[Q.ay.length-1],ue=pe=>Math.min(Math.max(pe*Q.ayMax,se),de),ie=d.map(pe=>jm(Q.ay,Q.axAccel,ue(pe))*F.tractionFactor),ve=d.map(pe=>jm(Q.ay,Q.axDecel,ue(pe))),Ie=d.map(pe=>jm(Q.ay,Q.axScrub,ue(pe))*F.tractionFactor),je=Q.axAccelWheels,ee=Q.axAccelHeld,ae=Q.axAccelWheelsHeld,Ce=C&&U&&je&&ee?(()=>{let pe=C.map(Re=>Q.ay.map((ye,Me)=>Re.wheels.reduce((fe,be)=>fe+je[Me][be],0))),me=pe.map(Re=>{let ye=Re.map((Me,fe)=>Me/Math.max(Q.axAccel[fe],tB));return d.map(Me=>Ct(Q.ay,ye,ue(Me)))}),xe=Q.ay.map((Re,ye)=>{let Me=pe.reduce((fe,be,Te)=>fe+Math.max(0,be[ye]-U[Te].cap/m),0);return Me>rB?Math.max(0,Q.axAccel[ye]-ee[ye])/Me:void 0}),ge=d.map(Re=>Ct(Q.ay,$C(xe,1),ue(Re))),ke=ae?C.map((Re,ye)=>{let Me=Q.ay.map((fe,be)=>{let Te=ae[be],Fe=Q.axAccel[be]-ee[be];if(!(!Te||!(Fe>nB)))return(pe[ye][be]-Re.wheels.reduce((Gt,mt)=>Gt+Te[mt],0))/Fe});return d.map(fe=>Ct(Q.ay,$C(Me,0),ue(fe)))}):void 0;return{motorTyreN:me,motorLoss:ge,...ke?{motorGain:ke}:{}}})():void 0;return{v:K,ayMax:Q.ayMax,axAccelN:ie,axDecelN:ve,axScrubN:Ie,...Ce??{},atLock:Q.atLock===!0}},z=new Map,j=K=>{let ne=z.get(K);return ne||z.set(K,ne=B(K)),ne},$=r==="fast"?0:Math.min(pd,V),N=$;if(r!=="fast"){for(let K=$;K<V;K=Math.min(V,K+J3))if(j(K).ayMax>0){N=K;break}}let W=(()=>{if(r==="fast"||!(N>0))return;let K=U=>BC(x,v,U,{drivenFront:S,drivenRear:w,nSteer:2}).ayMax,ne=K(N);return{norm:d,grip:U=>ne>0?K(U)/ne:1,lockRadius:NC(x.wheelbase/1e3,OC(x.steerFront))}})(),Z=_C(j,N,V,c,i.anchorTol??Q3,W),q=[],Y=[];for(let K=0;K<k.length;K++){let ne=k[K],{axDrag:U,axDragTyre:Q,axDrive:se,axPackCap:de,axPower:ue}=D[K],{ayMax:ie,axAccelN:ve,axDecelN:Ie,axScrubN:je,motorTyreN:ee,motorLoss:ae,motorGain:Ce,atLock:pe}=Z.at(ne),me=C&&ee&&ae?L(C,ne):void 0,xe=C&&ee&&me?C.map((Me,fe)=>({wheels:Me.wheels,share:me[fe],tyreN:ee[fe],...Ce?{gain:Ce[fe]}:{}})):void 0,ge={v:ne,ayMax:ie,...pe?{atLock:pe}:{},axTyreAcc:ve[0],axTyreDec:Ie[0],axDrive:se,axPackCap:de,axPower:ue,axDrag:U,axDragTyre:Q,axAccelN:ve,axDecelN:Ie,axScrubN:je,...xe&&ae?{motors:xe,motorLoss:ae}:{}};q.push(ge);let ke=[],Re=[];for(let Me=0;Me<u;Me++){let fe=Math.PI*Me/(u-1),be=ie*Math.cos(fe),Te=my(Math.abs(Math.cos(fe))),Fe=Math.min(Ct(d,ve,Te)+Q,ue+U,dy(ge,d,Te,1,1)+U);ke.push({ax:Fe+Ct(d,je,Te),ay:be,v:ne})}for(let Me=u-1;Me>=0;Me--){let fe=Math.PI*Me/(u-1),be=ie*Math.cos(fe),Te=my(Math.abs(Math.cos(fe)));Re.push({ax:Ct(d,Ie,Te)+U+Ct(d,je,Te),ay:be,v:ne})}let ye=(Me,fe,be)=>Array.from({length:VC},(Te,Fe)=>({ax:fe+(be-fe)*(Fe+1)/(VC+1),ay:Me,v:ne}));Y.push([...ke,...ye(-ie,ke[ke.length-1].ax,Re[0].ax),...Re,...ye(ie,Re[Re.length-1].ax,ke[0].ax)])}return{...WC(q,d),rows:q,norm:d,surf:Y}}function si(e,t){return e?.length?t.map(r=>ap(e,r)):t.map(()=>0)}function zC(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=>YC(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 ap(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 YC(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 WC(e,t){let r=e[e.length-1].v,n=0;for(let b of e)b.atLock&&b.v>0&&b.ayMax>0&&(n=Math.max(n,b.ayMax/(b.v*b.v)));let o=b=>{if(b<=e[0].v)return{i0:0,i1:0,t:0};if(b>=r)return{i0:e.length-1,i1:e.length-1,t:0};let g=0,y=e.length-1;for(;y-g>1;){let x=g+y>>1;e[x].v<=b?g=x:y=x}return{i0:g,i1:y,t:(b-e[g].v)/(e[y].v-e[g].v)}},a=b=>{let{i0:g,i1:y,t:x}=o(b);return{a:e[g],b:e[y],t:g===y?0:x}},s=(b,g,y)=>b===0||g===y?g:g+b*(y-g),i=(b,g,y,x)=>b===0?Ct(t,g,x):s(b,Ct(t,g,x),Ct(t,y,x)),c=(b,g)=>g>=1?b.axPower:Math.min(g*b.axDrive,b.axPackCap),l=({a:b,b:g,t:y},x,v)=>b.axScrubN?v*i(y,b.axScrubN,g.axScrubN,x):0,u=b=>b.axDragTyre??b.axDrag,d=({a:b,b:g,t:y},x,v)=>{let k=v*s(y,b.ayMax,g.ayMax);return k>0?my(x/k):1},p=({a:b,b:g,t:y},x,v,k)=>s(y,dy(b,t,x,v,k),y===0?0:dy(g,t,x,v,k))+s(y,b.axDrag,g.axDrag),m=(b,g,y=1,x=1)=>{let{a:v,b:k,t:R}=b,M=d(b,g,y),S=y*i(R,v.axAccelN,k.axAccelN,M)+s(R,u(v),u(k)),w=s(R,c(v,x),R===0?0:c(k,x))+s(R,v.axDrag,k.axDrag);return v.motors?Math.min(S,w,p(b,M,y,x))+l(b,M,y):Math.min(S,w)+l(b,M,y)},f=(b,g,y=1,x=1)=>{let{a:v,b:k,t:R}=b,M=d(b,g,y),S=i(R,v.axDecelN,k.axDecelN,M);return(x===1||S>0?y*S:x*y*S)+s(R,v.axDrag,k.axDrag)+l(b,M,y)},h=({a:b,b:g,t:y},x,v=1)=>{let k=t.length-1,R=b.axAccelN,M=g.axAccelN,S=b.axDecelN,w=g.axDecelN,F=b.axScrubN,T=g.axScrubN,A=V=>R[V]+y*(M[V]-R[V]),C=V=>S[V]+y*(w[V]-S[V]),P=V=>F?v*(F[V]+y*(T[V]-F[V])):0,L=s(y,b.ayMax,g.ayMax),E=s(y,b.axDrag,g.axDrag),_=s(y,u(b),u(g)),D=s(y,b.axPower,g.axPower),I=b.motors?V=>s(y,Rl(b,V,v,1),y===0?0:Rl(g,V,v,1)):null;for(let V=k;V>=0;V--){let O=I?Math.min(v*A(V)+_,D+E,I(V)+E)+P(V):Math.min(v*A(V)+_,D+E)+P(V),B=v*C(V)+E+P(V);if(!(x<=O+1e-6&&x>=B-1e-6))continue;if(V===k)return t[V]*v*L;let z=(W,Z,q)=>{if(q(Z))return 1;let Y=(W-x)/(W-Z);return Y>0?Math.min(Y,1):0},j=W=>x<=W+1e-6,$=W=>x>=W-1e-6,N=Math.min(z(v*A(V)+_+P(V),v*A(V+1)+_+P(V+1),j),z(D+E+P(V),D+E+P(V+1),j),z(v*C(V)+E+P(V),v*C(V+1)+E+P(V+1),$),I?z(I(V)+E+P(V),I(V+1)+E+P(V+1),j):1);return(t[V]+N*(t[V+1]-t[V]))*v*L}return 0};return{vMax:r,...n>0?{kappaMax:n}:{},axAccel:(b,g,y=1,x=1)=>m(a(b),g,y,x),axDecel:(b,g,y=1,x=1)=>f(a(b),g,y,x),ay:(b,g,y=1)=>h(a(b),g,y),scrub:(b,g,y=1)=>{let x=a(b);return l(x,d(x,g,y),y)},power:(b,g,y=1)=>{let x=a(b),{a:v,b:k,t:R}=x,S=(Number.isFinite(v.axPower)&&Number.isFinite(k.axPower)?s(R,v.axPower,k.axPower):Math.max(v.axPower,k.axPower))+s(R,v.axDrag,k.axDrag);return v.motors?Math.min(S,p(x,d(x,g,y),y,1)):S}}}function oB(e,t,r){let n=e.params,o=n.m.value,{drivenFront:a,drivenRear:s}=xa(e),i=ya(n,a,s);return c=>Wd(n,c,t,r)/o*i.powerFactor}function vl(e,t,r,n){let o=oB(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{...WC(a,e.norm),rows:a,norm:e.norm}}var aB=[-.2,-.08,0,.06,.12,.2,.3];function jC(e,t=!1,r="twoTrack",n,o,a=aB){let s=[...new Set([...a,0])].sort((f,h)=>f-h),i=s.map(f=>pn(e,t,r,n,o,f)),c=i[s.indexOf(0)],l=s[0],u=s[s.length-1],d=f=>{if(f<=l)return{i:0,t:0};if(f>=u)return{i:s.length-1,t:0};let h=0;for(;h<s.length-2&&s[h+1]<=f;)h++;return{i:h,t:(f-s[h])/(s[h+1]-s[h])}},p=f=>{let h=b=>{let{i:g,t:y}=d(b);return{a:f[g],b:f[Math.min(f.length-1,g+1)],t:y}};return b=>{let{a:g,b:y,t:x}=h(b);if(x===0)return g;let v=(R,M)=>R+x*(M-R),k=UC(g.kappaMax,y.kappaMax);return{vMax:g.vMax,...k!==void 0?{kappaMax:k}:{},axAccel:(R,M,S=1,w=1)=>v(g.axAccel(R,M,S,w),y.axAccel(R,M,S,w)),axDecel:(R,M,S=1,w=1)=>v(g.axDecel(R,M,S,w),y.axDecel(R,M,S,w)),ay:(R,M,S=1)=>v(g.ay(R,M,S),y.ay(R,M,S)),scrub:(R,M,S=1)=>v(g.scrub?.(R,M,S)??0,y.scrub?.(R,M,S)??0)}}},m=f=>f<l||f>u;return{anchors:s,steady:c,clamps:m,at:p(i),atSoc(f,h,b){let g=i.map(y=>vl(y,f,h,b));return{anchors:s,steady:g[s.indexOf(0)],clamps:m,at:p(g)}}}}function UC(e,t){return e===void 0?t:t===void 0?e:Math.min(e,t)}function XC(e,t,r,n="twoTrack",o){let a=[...new Set([...t,1])].sort((i,c)=>i-c),s=a.map(i=>i===1?r:pn(e,!1,n,o,void 0,0,i));return{...HC(a,s),atSoc:(i,c,l)=>HC(a,s.map(u=>vl(u,i,c,l)))}}function HC(e,t){let r=e.length-1,n=1,o=0,a=0,s=0,i=1,c=0,l=0,u=f=>{if(n=1,!(f>e[0]))return void(o=0);if(f>=e[r])return void(o=r);let h=0;for(;h<r-1&&e[h+1]<=f;)h++;if(o=h,f===e[h])return;a=h+1;let b=e[h],g=e[h+1];if(r<2){n=2,c=(f-b)/(g-b),i=1-c;return}s=h===0?2:h+1===r||f-e[h-1]<e[h+2]-f?h-1:h+2;let y=e[s];n=3,i=(f-g)*(f-y)/((b-g)*(b-y)),c=(f-b)*(f-y)/((g-b)*(g-y)),l=(f-b)*(f-g)/((y-b)*(y-g))},d=f=>{let h=f(t[o]);if(n===1)return h;let b=f(t[a]);if(n===2)return i*h+c*b;let g=i*h+c*b+l*f(t[s]);return Math.min(Math.max(h,b),Math.max(Math.min(h,b),g))},p=(f,h,b,g,y)=>{if(u(f),n===1||b===0)return d(k=>y(k,b));let x=d(k=>k.ay(h,0,g));if(!(x>0))return d(k=>y(k,b));let v=b/x;return d(k=>y(k,v*k.ay(h,0,g)))},m=t.reduce((f,h)=>UC(f,h.kappaMax),void 0);return{anchors:e,...m!==void 0?{kappaMax:m}:{},axAccel:(f,h,b,g=1,y=1)=>p(f,h,b,g,(x,v)=>x.axAccel(h,v,g,y)),axDecel:(f,h,b,g=1,y=1)=>{let x=v=>p(f,h,b,g,(k,R)=>k.axDecel(h,R,g,v));return y===1?x(1):H0(x(y),x(1),y)},scrub:(f,h,b,g=1)=>p(f,h,b,g,(y,x)=>y.scrub?.(h,x,g)??0),ay:(f,h,b,g=1)=>{if(u(f),n===1||b===0)return d(k=>k.ay(h,b,g));let y=k=>b>0?k.axAccel(h,0,g):-k.axDecel(h,0,g),x=d(y);if(!(x>0))return d(k=>k.ay(h,b,g));let v=b/x;return d(k=>k.ay(h,v*y(k),g))}}}var qC=new WeakMap;function py(e,t){let r=qC.get(e);if(!r){let n=Bn(e).regen?X0(t??ur(e)):void 0;r={inp:jt(e),ev:un(e),...n?{regen:n}:{}},qC.set(e,r)}return r}function fy(e,t,r){let n=py(e,r);return ly(n.inp,n.ev,t,n.regen?{regen:n.regen}:{})}function hy(e){let t=Yt(e);if(t.mode!=="hydraulic")return null;let r=a=>a.heat?{heat:Mg(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 sB(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 by(e,t,r,n,o,a=lr){if(!e)return null;let s=sB(t);return{...e.front?{front:Gm(e.front.heat,e.front.discs,s.front,r,n,o.front,a)}:{},...e.rear?{rear:Gm(e.rear.heat,e.rear.discs,s.rear,r,n,o.rear,a)}:{}}}var iB=.5,cB=.02,lB=6,sp=9,QC=1e-9,uB={FL:0,FR:0,RL:0,RR:0};function gy(e){return e?[...new Set([...e.padCurve.factor,1])].sort((t,r)=>t-r):[1]}function mB(e,t,r){let n=sn(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 ZC(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 JC(e,t,r,n,o=()=>0){let a=Array.from({length:sp},(d,p)=>r*p/(sp-1)),s=Yc(),{front:i,rear:c}=n,l=a.map(d=>{let p=o(d),m=h=>Kn(h,t,d,s).limitAt(0,0,uB,p).ax,f=m(e);return i.map(h=>c.map(b=>{if(h===1&&b===1)return 1;let g=f<0?m(mB(e,h,b))/f:1;return Math.abs(g-1)<QC?1:g}))}),u=a[1]-a[0];return{share(d,p,m){if(p===1&&m===1)return 1;let f=u>0?Math.min(sp-2,Math.max(0,Math.floor(d/u))):0,h=u>0?Math.min(1,Math.max(0,(d-a[f])/u)):0,b=ZC(i,p),g=ZC(c,m),y=v=>{let k=l[v],R=Math.min(i.length-1,b.i+1),M=Math.min(c.length-1,g.i+1),S=k[b.i][g.i]+g.t*(k[b.i][M]-k[b.i][g.i]),w=k[R][g.i]+g.t*(k[R][M]-k[R][g.i]);return S+b.t*(w-S)},x=y(f)+h*(y(Math.min(sp-1,f+1))-y(f));return Math.abs(x-1)<QC?1:x}}}function dB(e,t){let{front:r,rear:n}=t;return(o,a)=>e.share(a,r?.[o]??1,n?.[o]??1)}var pB=e=>(e.front??[]).every(t=>t===1)&&(e.rear??[]).every(t=>t===1);function eF(e,t,r){let n=e(),o=1,a=t(n);if(pB(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<lB;c++){let l=e(dB(r,s));o++;let u=Math.abs(l.laptime-n.laptime);if(n=l,u<cB){i=!0;break}a=t(n);let d=(f,h)=>f&&h?f.map((b,g)=>b+iB*((h[g]??1)-b)):f,p=d(s.front,a.front),m=d(s.rear,a.rear);s={...p?{front:p}:{},...m?{rear:m}:{}}}return{lap:n,pads:s,solves:o,converged:i}}function Ao(e,t){let r=e.engine;if(!r||r.gears.length===0||t.length===0)return;let n=e.params,{drivenFront:o,drivenRear:a}=xa(e),s=ya(n,o,a).effective,i=n.power_scale.value,{up:c,down:l}=Bg(r.engine.gearbox),u=r.engine.idleRpm,d=(p,m,f)=>(i*r.force(p,m)+f)/(s+r.inertiaMass(p,m));return{count:r.gears.length,up:c,down:l,kept:$g(r.engine.gearbox),limitRpm:r.engine.limitRpm,best:p=>Os(r,p,s,ap(t,p)*s,i).gear,share:(p,m)=>{let f=ap(t,p),h=f*s,b=Os(r,p,s,h,i);if(m===b.gear)return 1;let g=b.accel-f;return g>0?Math.min(1,Math.max(0,(d(p,m,h)-f)/g)):0},rpm:(p,m)=>r.slipping(p,m)?u:r.rpm(p,m),vIdle:p=>r.gears[p]?.vIdle??0}}var tF=new WeakMap;function xy(e){let t=tF.get(e.ggv);return t===void 0&&(t=Ao(e.vehicle,e.ggv.rows)??null,tF.set(e.ggv,t)),t??void 0}function fB(e){return e.gear&&e.engineRpm&&e.shifting?{gear:e.gear,rpm:e.engineRpm,shifting:e.shifting}:{}}function hB(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}:{},...fB(t)}}var cp=class extends Error{constructor(t){super(t),this.name="EventError"}};function bB(e,t){let{ggv:r}=t,n=Nt(t.numerics),o=n.accelStep,a=Math.max(1,Math.round(e.distance/o)),s=ti(r,new Array(a+1).fill(0),n);s[0].v=e.vStart??0;for(let f=0;f<s.length-1;f++){let h=s[f],b=s[f+1];h.v>=b.v||(h.ax=r.axAccel(h.v,0),b.v=Math.min(r.vMax,Math.sqrt(Math.max(0,h.v*h.v+2*h.ax*o))))}let i=xy(t),c=i?Kd(s.map(f=>f.v),new Array(a).fill(o),!1,i,(f,h,b)=>r.axAccel(h,0,1,b)):void 0;if(c){for(let f=0;f<=a;f++)s[f].v=c.v[f];for(let f=0;f<a;f++)s[f].ax=(s[f+1].v*s[f+1].v-s[f].v*s[f].v)/(2*o)}let l=0;for(let f=0;f<a;f++){let h=s[f].v+s[f+1].v;h>0&&(l+=2*o/h)}let u=s.slice(0,a).map(f=>f.v),d=s.slice(0,a).map(f=>f.ax),p=new Array(a).fill(o),m=p.map((f,h)=>h*o);return{id:e.id,label:e.label,kind:e.kind,time:l,distance:a*o,laps:1,lapTime:l,trace:{v:u,ax:d,ay:new Array(a).fill(0),s:m,x:m,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:uF(t,p,[...u,s[a].v],d,1)}}function gB(e,t){let r=Math.max(1,Math.round(e.laps??1)),[n]=ti(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=uF(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 lp(e,t){return e.laps!=null?Math.max(1,Math.round(e.laps)):e.distance!=null?Math.max(1,Math.ceil(e.distance/t.length)):1}function yB(e,t){let r=e.distance!=null?t.v_limit_endurance?.value??0:0;return r>0?r/3.6:void 0}function xB(e,t){if(e.distance==null||kt(t.motorModel))return 0;let r=t.endurance_reserve?.value??0;return r>0?Math.min(r,95)/100:0}var rF=1;function iF(e,t,r,n){return{v:r.v,ax:r.ax,ay:r.ay,ds:t.ds,axDrag:si(e.ggv.rows,r.v),...r.axScrub?{axScrub:r.axScrub}:{},axGrade:n,...t.bank?{bank:t.bank}:{}}}var nF=new WeakMap;function cF(e){let t=e.vehicle.params;if(!t.brakeFade)return null;let r=nF.get(t);if(r===void 0){let n=hy(t),o=n?Yt(t):null;if(!n||!o||o.mode!=="hydraulic")r=null;else{let a=py(t,e.vehicle),s=e.ggv.rows,i=JC(a.inp,a.ev,e.vehicle.vMax,{front:gy(o.hydraulic.front.heat),rear:gy(o.hydraulic.rear.heat)},c=>si(s,[c])[0]);r={discs:n,table:i}}nF.set(t,r)}return r}function RB(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=xy(e),u=(g,y)=>e.yaw?LC(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}:{}}):er(vl(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}:{}}),d=ei(t.gradient,t.npts),p=g=>n.motorThermal?jw(e.vehicle,t.ds,e.energyOpts??Vn,y=>u(y,g),o,a,d,t.bank).lap:u(void 0,g),m=cF(e);if(!m)return p();let f=hl(n),h=r.discC??{front:f,rear:f};return eF(p,g=>{let y=by(m.discs,fy(n,iF(e,t,g,d),e.vehicle),g.v,t.ds,h,f);return{...y?.front?{front:y.front.padFactor}:{},...y?.rear?{rear:y.rear.padFactor}:{}}},m.table).lap}function vB(e,t){let r=yB(e,t.vehicle.params),n=xB(e,t.vehicle.params);return n>0?SB(e,t,n,r):kl(e,t,r)}function ip(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 oF=5,kB=.1,MB=.005,aF=12;function SB(e,t,r,n){let o=kl(e,t,n),a=1,s=(f,h,b)=>({...f,energyTarget:{reserve:r,capKmh:h===void 0?null:h*3.6,met:b,solves:a}}),i=ip(o,r);if(i>=0)return s(o,n,!0);let c=Math.min(n??1/0,t.ggv.vMax),l=c/2,u=kl(e,t,l);a++;let d=ip(u,r);for(;d<0&&l>oF&&a<aF;)c=l,i=d,l=Math.max(oF,l/2),u=kl(e,t,l),a++,d=ip(u,r);if(d<0)return s(u,l,!1);let m=AB(f=>{let h=kl(e,t,f);return{run:h,margin:ip(h,r)}},{lo:l,hi:c,atLo:{run:u,margin:d},fHi:i},aF-a);return a+=m.solves,s(m.run,m.cap,!0)}function AB(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>kB&&a.margin>MB;){let u=o-n,d=Math.min(o-.05*u,Math.max(n+.05*u,n+s*u/(s-i))),p=e(d);l++,p.margin>=0?(n=d,a=p,s=p.margin,c===1&&(i/=2),c=1):(o=d,i=p.margin,c===-1&&(s/=2),c=-1)}return{cap:n,run:a.run,solves:l}}function lF(e,t,r){return r===0?e:e&&!t}function kl(e,t,r){let n=t.track;if(!n)throw new cp(`Event "${e.id}" needs a track.`);let o=lp(e,n),a=e.standingStart??t.standingStart??!1,s=N=>lF(a,n.closed,N),i=t.vehicle.params,c=An(ri(i)),l=c.capacityAh,u=kt(i.motorModel)?1:i.soc.value,d=hl(i),p=Yd(c,d),m=0,f=0,h=0,b=0,g=[],y=!1,x=-1/0,v=0,k=0,R=!1,M=-1/0,S=0,w=0,F=-1/0,T=(N,W,Z=1)=>{N.tempMaxC>F&&(F=N.tempMaxC),N.motorTempMaxC!==void 0&&(y=!0,R=!0,N.motorTempMaxC>x&&(x=N.motorTempMaxC),N.motorTempMaxC>M&&(M=N.motorTempMaxC),v+=(N.motorDerateTimeFrac??0)*W,S+=(N.motorDerateTimeFrac??0)*W,k+=(N.motorLossKwh??0)/Z,w+=(N.motorLossKwh??0)/Z)},A=null,C,P=hy(i),L={front:d,rear:d},E=null,_=cF(t)!==null,D=(N,W)=>_&&(Math.abs(N.front-W.front)>rF||Math.abs(N.rear-W.rear)>rF),I=(N,W,Z)=>{let q=q0(i,N,W);if(E&&E.launch===Z&&!FB(q,E.pw)&&!D(L,E.discC))return E.lap;let Y=RB(t,n,{soc:N,packTempC:W,launched:Z,...r?{vCeiling:r}:{},..._?{discC:L}:{}});return E={pw:q,launch:Z,discC:L,lap:Y},Y},V=ei(n.gradient,n.npts),O=(N,W,Z)=>ni(t.vehicle,n.ds,N.v,N.ax,t.energyOpts,W,Z,void 0,V,void 0,{ay:N.ay,bank:n.bank,...N.axScrub?{scrub:N.axScrub}:{}}),B=new WeakMap,z=(N,W)=>{let Z=B.get(N);return Z||(Z=fy(i,iF(t,n,N,V),t.vehicle),B.set(N,Z)),by(P,Z,N.v,n.ds,W,d)},j=(N,W,Z)=>{let q=`${(100*Z/n.npts).toFixed(0)} % of the way through lap ${N+1}`,Y=W.cutoffAt>=0&&W.cutoffAt<=W.emptyAt;return{lapsCompleted:N,lapsAsked:o,why:Y?`the pack reached its ${c.voltageFloor.toFixed(0)} V cut-off ${q}`:`the pack ran out ${q}`}};for(let N=0;N<o;N++){if(u<=0){C={lapsCompleted:N,lapsAsked:o,why:"the pack was empty"};break}let W=s(N),Z=u,q=p;R=!1,M=-1/0,S=0,w=0,F=-1/0;let Y=I(u,p,W),K=O(Y,u,p);if(K.emptyAt>=0){C=j(N,K,K.emptyAt);break}let U=I(K.socEnd,K.tempEndC,W).laptime-Y.laptime,Q,se,de,ue,ie=p,ve=-1,Ie=null,je=1;if(U<=yy)Q=Y.laptime,se=K.net,de=K.loss,ue=K.chargeAh,ie=K.tempEndC,T(K,Q),je=1;else{let ae=Math.min(wB,Math.max(2,Math.ceil(U/(2*yy))));je=ae;let Ce=u,pe=p;Q=0,se=0,de=0,ue=0;for(let me=0;me<ae;me++){let xe=I(Ce,pe,W),ge=O(xe,Ce,pe),ke=ge.emptyAt>=0?ge.emptyAt/n.npts:1;if(ke*ae<1){ve=Math.round(n.npts*(me/ae+ke)),Ie=ge;break}if(Q+=xe.laptime/ae,T(ge,xe.laptime/ae,ae),se+=ge.net/ae/ke,de+=ge.loss/ae/ke,ue+=ge.chargeAh/ae/ke,Ce-=ge.chargeAh/ae/ke/l,pe+=(ge.tempEndC-pe)/ae,Ce<=0){ve=Math.round(n.npts*(me+1)/ae),Ie=ge;break}}if(ie=pe,ve>=0&&Ie){C=j(N,Ie,ve);break}u=Ce}m+=Q,f+=se,h+=de,b+=ue,U<=yy&&(u=K.socEnd),p=ie;let ee=P?z(Y,L):null;ee&&(L={front:ee.front?.endC??L.front,rear:ee.rear?.endC??L.rear}),g.push({lap:N+1,time:Q,elapsed:m,entryTime:Y.laptime,socStart:Z,socEnd:u,packTempStartC:q,packTempEndC:p,packTempMaxC:Number.isFinite(F)?F:q,energyKwh:se,lossKwh:de,chargeAh:ue,launched:W,substeps:je,...r?{vCeiling:r}:{},...R?{motor:{peakWindingC:M,derateTimeFrac:Q>0?S/Q:0,lossKwh:w}}:{},...ee?{brakes:{...ee.front?{front:sF(ee.front)}:{},...ee.rear?{rear:sF(ee.rear)}:{}}}:{}}),A=Y}if(!A){let N=xy(t);A=er(vl(t.ggv,t.vehicle,u),n,t.numerics,{standingStart:a,...t.load?{load:t.load.atSoc(t.vehicle,u)}:{},...N?{shifts:N}:{}}),C=C??{lapsCompleted:0,lapsAsked:o,why:"the pack was empty"}}let $=g.length;return{id:e.id,label:e.label,kind:e.kind,time:m,distance:n.length*$,laps:$,lapTime:A.laptime,trace:hB(n,A),energy:{consumed:f,loss:h,...kt(i.motorModel)?{}:{native:{value:b,unit:"Ah"}},remainingFraction:kt(i.motorModel)?1:u,...y?{motor:{peakWindingC:x,derateTimeFrac:m>0?v/m:0,lossKwh:k}}:{}},lapLog:g,...C?{incomplete:C}:{}}}var yy=.05;function sF(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 wB=4,CB=.001;function FB(e,t){return e===t?!1:!Number.isFinite(e)||!Number.isFinite(t)?!0:Math.abs(e-t)>CB*Math.max(1,Math.abs(t))}function uF(e,t,r,n,o,a){return TB(e,t,o,()=>({v:r,ax:n,...a?{lateral:a}:{}}))}function TB(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),d=ni(e.vehicle,t,u.v,u.ax,o,a,void 0,void 0,void 0,void 0,u.lateral);s+=d.net,i+=d.loss,c+=d.chargeAh,a=d.socEnd}return kt(e.vehicle.params.motorModel)?{consumed:s,loss:i,remainingFraction:1}:{consumed:s,loss:i,native:{value:c,unit:"Ah"},remainingFraction:a}}function mF(e,t){switch(e.kind){case"straightLineAccel":return bB(e,t);case"constantRadius":return gB(e,t);case"trackLap":return vB(e,t)}}function Ry(e,t){let r={};for(let n of e)r[n.id]=mF(n,t);return r}function dF(e,t){if(e.kind!=="trackLap")return e;let{distance:r,...n}=e;return{...n,laps:Math.max(1,Math.round(t))}}function va(e,t,r,n,o="twoTrack",a){let s=1/0,i=-1/0;for(let p of r){let m=dl(p);if(!m)continue;let f=Dw(m,er(t,p,n).v);f&&(s=Math.min(s,f.lo),i=Math.max(i,f.hi))}if(!(i>=s))return;let c=Ew({lo:s,hi:i}),l=c.join(","),u=a?.get(l);if(u)return u;let d=XC(e,c,t,o);return a?.set(l,d),d}var Ml=e=>e.distance/Math.max(1,e.laps);function Sl(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 PB=e=>e.v.map(t=>t*3.6),LB=e=>e.ax.map(t=>t/9.81),DB=e=>e.ay.map(t=>t/9.81),EB=e=>e.ay.map((t,r)=>e.v[r]>1e-6?t/(e.v[r]*e.v[r]):0),up=(e,t,r)=>e?.slice()??new Array(t.s.length).fill(r),IB=e=>up(e.z,e,0),_B=e=>e.gradient?e.gradient.map(t=>100*Math.tan(t*Math.PI/180)):up(void 0,e,0),NB=e=>up(e.bank,e,0),OB=e=>up(e.mu,e,1);function VB(e){let t=e.s.length,r=Sl(e),n=new Array(t);n[0]=0;for(let o=1;o<t;o++)n[o]=n[o-1]+2*r[o-1]/(e.v[o-1]+e.v[o]);return n}var vy=[{name:"s",unit:"m",what:"distance along the lap"},{name:"ds",unit:"m",what:"length of the segment starting at this sample"},{name:"t",unit:"s",what:"elapsed time"},{name:"v",unit:"m/s",what:"speed"},{name:"speed",unit:"km/h",what:"speed"},{name:"ax",unit:"m/s\xB2",what:"longitudinal acceleration"},{name:"ay",unit:"m/s\xB2",what:"lateral acceleration"},{name:"axg",unit:"g",what:"longitudinal acceleration"},{name:"ayg",unit:"g",what:"lateral acceleration"},{name:"curv",unit:"1/m",what:"signed curvature, ay/v\xB2"},{name:"z",unit:"m",what:"elevation of the road"},{name:"grade",unit:"%",what:"grade of the road, uphill +"},{name:"bank",unit:"\xB0",what:"bank of the road, left side up +"},{name:"grip",unit:"-",what:"grip scale of the road, 1 = the tyre\u2019s own"}];function pF(e){let t=Sl(e);return{ds:t,vars:{s:e.s,ds:t,t:VB(e),v:e.v,speed:PB(e),ax:e.ax,ay:e.ay,axg:LB(e),ayg:DB(e),curv:EB(e),z:IB(e),grade:_B(e),bank:NB(e),grip:OB(e)}}}function mp(e){let t=e.rows?zC(e.rows,e.v):void 0;return{v:e.v,ax:e.ax,ay:e.ay,ds:e.ds,...e.rows?{axDrag:si(e.rows,e.v)}:{},...e.axScrub?{axScrub:e.axScrub}:{},axGrade:ei(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 fF(e,t){return mp({v:e.v,ax:e.ax,ay:e.ay,ds:Sl({s:e.s,length:t}),gradient:e.gradient,bank:e.bank,loadFactor:e.loadFactor})}function hF(e,t){let r=jt(e);return{pastTurnover:SC(r,un(e),t),...e.aeroModel?{aeroOutside:MC(r,t)}:{}}}var dp="Flying lap";function ky(e,t){return e.kind!=="trackLap"||e.label!==dp?e.label:e.standingStart??t?"Run":e.label}function BB(e){let t=jt(e);return{yawInertia:t.yawInertia??0,massTotal:t.massTotal,wheelbase:t.wheelbase/1e3}}function $B(e,t,r){let n=e.params,o=n.ggvMode??"twoTrack",a=n.quasiTransient?jC(e,!1,o):null,s=a?a.steady:pn(e,!1,o),i=t?va(e,s,[t],r,o):void 0;return{ggv:s,...a?{yaw:{family:a,car:BB(n)}}:{},...i?{load:i}:{}}}function GB(e,t){let r=t.lapCounts,n=t.standingStart??!1,o=!1,a=e.events.map(s=>{let i=r?.[s.id]!=null?dF(s,r[s.id]):s,c=ky(i,n),l=c===i.label?i:{...i,label:c};return l!==s&&(o=!0),l});return o?a:e.events}function KB(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=lp(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 HB(e,t){for(let[r,n]of Object.entries(e))n.trace&&(e[r]={...n,...hF(t,fF(n.trace,Ml(n)))})}function Al(e,t,r={}){let n=ur(e),o=$B(n,r.track,r.numerics),{ggv:a}=o,s=Ry(GB(t,r),{vehicle:n,...o,track:r.track,energyOpts:Bn(e,r.energyOpts),numerics:r.numerics,standingStart:r.standingStart});return KB(s,t,r),HB(s,n.params),{name:e.name,rulesetId:t.id,events:s,ggv:a}}function My(e){return{...e,ggv:{rows:e.ggv.rows,vMax:e.ggv.vMax,surf:e.ggv.surf}}}var Sy=["<","<=",">",">=","==","!="],ot=class extends Error{at;constructor(t,r){super(t),this.name="ExprError",this.at=r}},wl=e=>e>="0"&&e<="9",bF=e=>/[A-Za-z_]/.test(e),zB=e=>/[A-Za-z0-9_]/.test(e);function YB(e){let t=[],r=0;for(;r<e.length;){let n=e[r];if(n===" "||n===" "||n===`
|
|
224
|
-
`||n==="\r"){r++;continue}if(wl(n)||n==="."&&wl(e[r+1]??"")){let o=r;for(;r<e.length&&(wl(e[r])||e[r]===".");)r++;if(e[r]==="e"||e[r]==="E"){let i=r;if(r++,(e[r]==="+"||e[r]==="-")&&r++,wl(e[r]??""))for(;r<e.length&&wl(e[r]);)r++;else r=i}let a=e.slice(o,r),s=Number(a);if(!Number.isFinite(s))throw new ot(`"${a}" is not a number`,o);t.push({t:"num",value:s,at:o});continue}if(bF(n)){let o=r;for(;;){for(;r<e.length&&zB(e[r]);)r++;if(e[r]==="."&&bF(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(Sy.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 ot(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 ot(`"${n}" is not something this expression can contain`,r)}return t.push({t:"end",at:e.length}),t}function Ay(e){let t=YB(e),r=0,n=()=>t[r],o=h=>{let b=n();return b.t==="op"&&b.value===h},a=h=>o(h)?(r++,!0):!1,s=(h,b)=>{if(!a(h))throw new ot(`Expected ${b} here`,n().at)};function i(){let h=c(),b=n();if(b.t!=="op"||!Sy.includes(b.value))return h;r++;let g={kind:"binary",op:b.value,left:h,right:c(),at:b.at},y=n();if(y.t==="op"&&Sy.includes(y.value))throw new ot("Comparisons do not chain \u2014 write and(a < b, b < c)",y.at);return g}function c(){let h=l();for(;;){let b=n().at;if(a("+"))h={kind:"binary",op:"+",left:h,right:l(),at:b};else if(a("-"))h={kind:"binary",op:"-",left:h,right:l(),at:b};else return h}}function l(){let h=u();for(;;){let b=n().at;if(a("*"))h={kind:"binary",op:"*",left:h,right:u(),at:b};else if(a("/"))h={kind:"binary",op:"/",left:h,right:u(),at:b};else return h}}function u(){return a("-")?{kind:"unary",op:"-",arg:u()}:a("+")?u():d()}function d(){let h=p(),b=n().at;return a("^")?{kind:"binary",op:"^",left:h,right:u(),at:b}:h}function p(){let h=n();if(h.t==="num")return r++,{kind:"num",value:h.value};if(h.t==="name"){if(r++,a("(")){let b=[];if(!o(")"))do b.push(i());while(a(","));return s(")","a closing bracket"),{kind:"call",name:h.value,args:b,at:h.at}}return{kind:"var",name:h.value,at:h.at}}if(a("(")){let b=i();return s(")","a closing bracket"),b}throw h.t==="end"?new ot("The expression ends before it is finished",h.at):new ot(`"${h.value}" cannot start a value`,h.at)}let m=i(),f=n();if(f.t!=="end")throw new ot(`"${f.value}" is left over \u2014 check for a missing operator`,f.at);return m}function wy(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 Cl=(e,t)=>typeof e=="number"?new Array(t).fill(e):e;function WB(e){let t=1;for(let r of e)Array.isArray(r)&&(t=Math.max(t,r.length));return t}function fr(e,t){if(e.every(a=>typeof a=="number"))return t(...e);let r=WB(e),n=e.map(a=>Cl(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 at=(e,t)=>({arity:e,call:r=>fr(r,t)}),ka=e=>e!==0&&!Number.isNaN(e),fn=e=>e?1:0;function gF(e,t,r){let n=yF(t,r,"integrate"),o=n.length,a=Cl(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 yF(e,t,r){if(!e.ds||e.ds.length===0)throw new ot(`${r}() needs to know the sample spacing, and this context has none`,t);return e.ds}var pp={abs:at(1,Math.abs),sqrt:at(1,Math.sqrt),sign:at(1,Math.sign),floor:at(1,Math.floor),ceil:at(1,Math.ceil),round:at(1,Math.round),exp:at(1,Math.exp),log:at(1,Math.log),sin:at(1,Math.sin),cos:at(1,Math.cos),tan:at(1,Math.tan),atan:at(1,Math.atan),atan2:at(2,Math.atan2),hypot:at(2,Math.hypot),min:at(2,Math.min),max:at(2,Math.max),clamp:at(3,(e,t,r)=>Math.min(r,Math.max(t,e))),if:at(3,(e,t,r)=>ka(e)?t:r),and:at(2,(e,t)=>fn(ka(e)&&ka(t))),or:at(2,(e,t)=>fn(ka(e)||ka(t))),not:at(1,e=>fn(!ka(e))),finite:at(1,e=>fn(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=gF(e,t,0),n=t.ds,o=Cl(e,n.length),a=n.length-1;return r[a]+(o[a]+o[0])/2*n[a]}},integrate:{arity:1,call:([e],t)=>gF(e,t,0)},cum:{arity:1,call:([e],t)=>{let r=t.ds?.length??(Array.isArray(e)?e.length:1),n=Cl(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=yF(t,0,"deriv"),n=r.length,o=Cl(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}}},ii={g:9.81,pi:Math.PI,e:Math.E,nan:NaN,inf:1/0},Fl={fleetmin:"min",fleetmax:"max"};function Ma(e){switch(e.kind){case"call":return Object.hasOwn(Fl,e.name)||e.args.some(Ma);case"unary":return Ma(e.arg);case"binary":return Ma(e.left)||Ma(e.right);default:return!1}}var jB=e=>typeof e=="number"?`${e}`:`between ${e[0]} and ${e[1]}`;function UB(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 XB(e,t){let r=t.map(c=>({k:c,d:UB(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 hn(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(ii,e.name))return ii[e.name];let r=[...Object.keys(t.vars),...Object.keys(ii)].sort();throw new ot(XB(e.name,r),e.at)}case"unary":return fr([hn(e.arg,t)],r=>-r);case"binary":{let r=hn(e.left,t),n=hn(e.right,t);switch(e.op){case"+":return fr([r,n],(o,a)=>o+a);case"-":return fr([r,n],(o,a)=>o-a);case"*":return fr([r,n],(o,a)=>o*a);case"/":return fr([r,n],(o,a)=>a===0?0:o/a);case"^":return fr([r,n],(o,a)=>o**a);case"<":return fr([r,n],(o,a)=>fn(o<a));case"<=":return fr([r,n],(o,a)=>fn(o<=a));case">":return fr([r,n],(o,a)=>fn(o>a));case">=":return fr([r,n],(o,a)=>fn(o>=a));case"==":return fr([r,n],(o,a)=>fn(o===a));case"!=":return fr([r,n],(o,a)=>fn(o!==a))}break}case"call":{let r=Object.hasOwn(Fl,e.name)?Fl[e.name]:void 0;if(r){if(!t.fleet)throw new ot(`${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 ot(`${e.name}() takes 1 argument, not ${e.args.length}`,e.at);return t.fleet(e.args[0],r,e.at)}let n=Object.hasOwn(pp,e.name)?pp[e.name]:void 0;if(!n){let s=[...Object.keys(pp),...t.fleet?Object.keys(Fl):[]];throw new ot(`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 ot(`${e.name}() takes ${jB(n.arity)} argument${o===1&&a===1?"":"s"}, not ${e.args.length}`,e.at);return n.call(e.args.map(s=>hn(s,t)),t)}}throw new ot("Unreachable node",0)}var ci=e=>Number.isFinite(e)?e:NaN,Cy=[{name:"time",unit:"s",what:"the whole event, every lap",read:e=>ci(e?.time)},{name:"lapTime",unit:"s",what:"one lap \u2014 the last one completed",read:e=>ci(e?.lapTime)},{name:"distance",unit:"m",what:"distance covered",read:e=>ci(e?.distance)},{name:"laps",unit:"-",what:"laps completed",read:e=>ci(e?.laps)},{name:"energy",unit:"kWh",what:"energy drawn over the event",read:e=>ci(e?.energy?.consumed)},{name:"remaining",unit:"-",what:"share of the pack or tank left afterwards",read:e=>ci(e?.energy?.remainingFraction)},{name:"finished",unit:"-",what:"1 when the car ran the whole event, else 0",read:e=>e&&!e.incomplete?1:0}],xF=/^[A-Za-z_][A-Za-z0-9_]*$/,qB=new Set([...Object.keys(ii),...vy.map(e=>e.name)]);function fp(e,t,r=[]){let n=[],o=new Set(r),a=t.map(b=>b.id),s=new Set;for(let b of a)xF.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(!xF.test(b.key)){n.push({key:b.key,message:`"${b.key}" must be one word \u2014 letters, digits and _`});continue}if(qB.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,Ay(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,[...wy(g)].filter(y=>i.has(y)));let u=new Set,d=[];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),d.push(b)}for(let b of c.keys()){if(u.has(b))continue;let g=QB(b,l);n.push({key:b,message:g?`"${b}" depends on itself, through ${g.join(" \u2192 ")}`:`"${b}" reads a KPI that depends on itself`})}let p=(b,g,y)=>{throw new ot("fleetmin() and fleetmax() cannot sit inside one another",y)},m=new Set,f={};for(let b of a)for(let g of Cy)f[`${b}.${g.name}`]=1;for(let b of o)f[b]=1;for(let b of i.keys())f[b]=1;let h={};for(let b of vy)h[b.name]=[1,1];for(let b of d){let g=i.get(b),y=c.get(b);(Ma(y)||l.get(b).some(R=>m.has(R)))&&m.add(b);let x=g.over!=null?{...f,...h}:f,v=g.over!=null?[1,1]:void 0,k=(R,M,S)=>{let w=hn(R,{vars:x,ds:v,fleet:p});if(Array.isArray(w))throw new ot("fleetmin() and fleetmax() compare one number per car \u2014 reduce the channel first, e.g. peak(v)",S);return w};try{let R=hn(y,{vars:x,ds:v,fleet:k});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:d.map(b=>({def:i.get(b),node:c.get(b)})),field:m,eventIds:a},problems:n}}function QB(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 ZB(e,t,r={}){let n={...r};for(let o of e.eventIds){let a=t.events[o];for(let s of Cy)n[`${o}.${s.name}`]=s.read(a)}return{vars:n,laps:new Map,events:t.events}}function RF(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?pF({...n.trace,length:Ml(n)}):null,e.laps.set(t.over,r)}return r?{vars:{...e.vars,...r.vars},ds:r.ds}:null}var vF=e=>Array.isArray(e)?NaN:e;function kF(e,t,r,n={}){let o=Object.keys(t),a=o.map(i=>ZB(e,t[i],n[i]));for(let{def:i,node:c}of e.order){let l=e.field.has(i.key);if(l&&!r){for(let p of a)p.vars[i.key]=NaN;continue}let u=new Map,d=(p,m)=>{let f=u.get(p);if(f!==void 0)return f;let h=NaN;for(let b of a){let g=RF(b,i);if(!g)continue;let y=vF(hn(p,g));Number.isFinite(y)&&(Number.isNaN(h)||(m==="min"?y<h:y>h))&&(h=y)}return u.set(p,h),h};for(let p of a){let m=RF(p,i);p.vars[i.key]=m?vF(hn(c,l?{...m,fleet:d}:m)):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 Tl(e,t,r){return kF(e,t,!0,r)}function Fy(e,t,r){return kF(e,{car:t},!1,r?{car:r}:void 0).car}var hp=class extends Error{problems;constructor(t,r){super(`Ruleset "${t}" does not compile:
|
|
223
|
+
`}function En(e){let t=Ac(JM(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 eS={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},tS={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},rS={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},nS={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},oS={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},aS={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},sS={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},iS={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},ng=()=>En(eS),og=()=>En(tS),ag=()=>En(rS),sg=()=>En(nS),ig=()=>En(oS),cg=()=>En(aS),lg=()=>En(sS),ug=()=>En(iS);var cS=e=>Number.isFinite(e)&&e>0;function _m(e,t){let r=cS(t.grip)?t.grip:1,n=cS(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 Cc={ok:!0,violation:0},Jo=1e7;function In(e,t){let r;try{r=e.build(t)}catch(s){return{total:Jo*2,feasible:!1,terms:[],reason:`build failed: ${String(s)}`}}let n=e.feasible(r);if(!n.ok)return{total:Jo+Math.max(0,n.violation),feasible:!1,terms:[],reason:n.reason};let o;try{o=e.terms(r)}catch(s){return{total:Jo*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:Jo*2,feasible:!1,terms:o,reason:"objective was not finite"}}var Fc=(e,t)=>!t||(e.feasible!==t.feasible?e.feasible:e.total<t.total);function mg(e,t){return t.map((r,n)=>Math.min(e[n].hi,Math.max(e[n].lo,r)))}var Vr=e=>e.map(t=>t.start);function Nm(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 N_(e){let t=0;for(;t===0;)t=e();return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e())}function dg(e,t){let{budget:r}=t,n=Math.max(1,Math.floor(t.progressEvery??1)),o=e.variables,a=m=>mg(o,m.map((f,h)=>o[h].lo+f*(o[h].hi-o[h].lo))),s=m=>m.map((f,h)=>(f-o[h].lo)/(o[h].hi-o[h].lo)),i=0,c=0,l=null,u=null,d=[];return{vars:o,denorm:a,norm:s,evaluate:m=>{if(i>=r)return l?.total??Number.POSITIVE_INFINITY;i++;let f=m.map(g=>Math.min(1,Math.max(0,g))),h=In(e,a(f));h.feasible||c++;let b=Fc(h,l)?h:l;return b===h&&(l=h,u=f),d.push(b.total),t.onProgress&&(i%n===0||i===r)&&t.onProgress({evaluations:i,budget:r,x:a(u),score:b,infeasible:c}),h.total},left:()=>r-i,result:m=>({method:m,x:u?a(u):Vr(o),score:l??In(e,Vr(o)),evaluations:i,history:d,infeasible:c})}}var pg=(e,t,r,n=0,o)=>{let a=t?r.norm(Vr(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 lS(e,t){let r=dg(e,t),n=Nm(t.seed??1),o=e.variables.length;for(r.evaluate(pg(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 Ds(e,t){let r=dg(e,t),n=e.variables.length,o=Nm(t.seed??1),a=1,s=2,i=.5,c=.5,l=pg(e,t.warmStart!==!1,r,t.startJitter,o),u=.25;for(;r.left()>0;){let d=[{u:l,f:r.evaluate(l)}];for(let p=0;p<n&&r.left()>0;p++){let m=l.slice();m[p]+=m[p]+u>1?-u:u,d.push({u:m,f:r.evaluate(m)})}for(;r.left()>0;){d.sort((g,y)=>g.f-y.f);let p=d[n],m=new Array(n).fill(0);for(let g=0;g<n;g++)for(let y=0;y<n;y++)m[y]+=d[g].u[y]/n;let f=g=>m.map((y,x)=>y+g*(y-p.u[x])),h=f(a),b=r.evaluate(h);if(b<d[0].f){let g=f(s),y=r.evaluate(g);d[n]=y<b?{u:g,f:y}:{u:h,f:b}}else if(b<d[n-1].f)d[n]={u:h,f:b};else{let g=f(-i),y=r.evaluate(g);if(y<p.f)d[n]={u:g,f:y};else{let x=d[0],v=0;for(let k=1;k<=n;k++)for(let R=0;R<n;R++)v=Math.max(v,Math.abs(d[k].u[R]-x.u[R]));if(v<1e-4)break;for(let k=1;k<=n&&r.left()>0;k++){let R=d[k].u.map((M,S)=>x.u[S]+c*(M-x.u[S]));d[k]={u:R,f:r.evaluate(R)}}}}}d.sort((p,m)=>p.f-m.f),l=d[0].u.map(p=>Math.min(1,Math.max(0,p+.05*(o()-.5)))),u=Math.max(.02,u*.5)}return r.result("nelder-mead")}function uS(e,t){let r=dg(e,t),n=e.variables.length,o=Nm(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,S)=>M+S,0);for(let M=0;M<s;M++)i[M]/=c;let l=1/i.reduce((M,S)=>M+S*S,0),u=(l+2)/(n+l+5),d=1+2*Math.max(0,Math.sqrt((l-1)/(n+1))-1)+u,p=(4+l/n)/(n+4+2*l/n),m=(n+2)/3,f=Math.min(1,m*2/((n+1.3)**2+l)),h=Math.min(1-f,m*2*(l-2+1/l)/((n+2)**2+l)),b=Math.sqrt(n)*(1-1/(4*n)+1/(21*n*n)),g=pg(e,t.warmStart!==!1,r,t.startJitter,o),y=.25,x=new Array(n).fill(1),v=new Array(n).fill(0),k=new Array(n).fill(0),R=0;for(;r.left()>0;){R++;let M=[];for(let A=0;A<a&&r.left()>0;A++){let C=[];for(let L=0;L<n;L++)C.push(N_(o));let P=g.map((L,E)=>L+y*x[E]*C[E]);M.push({z:C,u:P,f:r.evaluate(P)})}if(M.length<s)break;M.sort((A,C)=>A.f-C.f);let S=g.slice(),w=new Array(n).fill(0);g=new Array(n).fill(0);for(let A=0;A<s;A++)for(let C=0;C<n;C++)g[C]+=i[A]*M[A].u[C],w[C]+=i[A]*M[A].z[C];g=g.map(A=>Math.min(1,Math.max(0,A)));for(let A=0;A<n;A++)v[A]=(1-u)*v[A]+Math.sqrt(u*(2-u)*l)*w[A];let F=Math.sqrt(v.reduce((A,C)=>A+C*C,0)),T=F/Math.sqrt(1-(1-u)**(2*R))/b<1.4+2/(n+1)?1:0;for(let A=0;A<n;A++){let C=(g[A]-S[A])/(y*x[A]);k[A]=(1-p)*k[A]+T*Math.sqrt(p*(2-p)*l)*C}for(let A=0;A<n;A++){let C=0;for(let E=0;E<s;E++)C+=i[E]*M[E].z[A]*M[E].z[A];let P=x[A]*x[A],L=(1-f-h)*P+f*(k[A]*k[A]+(1-T)*p*(2-p)*P)+h*C*P;x[A]=Math.sqrt(Math.max(1e-12,L))}if(y*=Math.exp(u/d*(F/b-1)),y<1e-6||y>10)break}return r.result("sep-cma-es")}var Es=[{name:"random",run:lS},{name:"nelder-mead",run:Ds},{name:"sep-cma-es",run:uS}];var p9=Math.PI/180;var Om=Math.PI/180;var g9={Fz:100,alpha:.25*Om,kappa:.005,gamma:.5*Om,p:6900},mS={Fz:100,alpha:1*Om,kappa:.02,gamma:.5*Om,p:6900};var dS=Math.PI/180,M9={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:dS},gamma:{rad:1,deg:dS},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 F9=Math.PI/180;var U_=Math.PI/180;var _9=3*U_;var $9=Math.PI/180;var Z9=Math.PI/180;var rN={RCX1:1,RCY1:1,REX1:0,REY1:0,RBY3:0,RHX1:0,RHY1:0},hS={RBX1:15,RBX2:15,RBY1:18,RBY2:19,...rN};var lX=Math.PI/180;var iN=Math.PI/180,Vm=[{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"}],SX=new Map(Vm.map(e=>[e.id,e]));var AX=.01*iN;var pt=Math.PI/180;var yS=new Set(Vm.filter(e=>e.group!=="inputs"&&(e.unit==="N"||e.unit==="N\xB7m"||e.unit==="N/rad")).map(e=>e.id)),xS={alpha:{from:-15*pt,to:15*pt,n:61},kappa:{from:-.25,to:.25,n:61},gamma:{from:-6*pt,to:6*pt,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}},yg={alpha:{from:0,to:12*pt,n:7},kappa:{from:-.2,to:.2,n:9},gamma:{from:-4*pt,to:4*pt,n:5},Fz:{from:400,to:1600,n:5},p:{from:6e4,to:12e4,n:4},V:{from:5,to:35,n:4}};var xg={alpha:{from:0,to:12*pt,n:25},kappa:{from:-.2,to:.2,n:25},gamma:{from:-4*pt,to:4*pt,n:17},Fz:{from:300,to:1800,n:16},p:{from:6e4,to:12e4,n:13},V:{from:5,to:35,n:13}};var Ee=(e,t,r,n={},o={})=>({id:e,form:"curves",sweep:[{input:t,...xS[t],...o}],x:t,y:r,...n}),Bm=(e,[t,r],n,o,a={})=>({id:e,form:"carpet",sweep:[{input:t,...yg[t]},{input:r,...yg[r]}],x:n,y:[o],...a}),_n=(e,t)=>({id:e,fixed:t}),kr={input:"Fz",values:"car"},gg={alpha:0,kappa:0},Zt={kappa:0},bS={alpha:0},lN={input:"Fz",values:[500,1e3,1500]},uN=[{id:"overview",name:"Overview",cards:[_n("tyre","tyre"),Ee("fy","alpha",["Fy"],{title:"Lateral force",hold:Zt}),Ee("mz","alpha",["Mz"],{title:"Aligning moment",hold:Zt}),Ee("fx","kappa",["Fx"],{title:"Longitudinal force",hold:bS}),Bm("combined-carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),_n("ellipse","ellipse")]},{id:"lateral",name:"Lateral",cards:[Ee("fy-load","alpha",["Fy"],{title:"Lateral force per wheel load",series:kr,hold:Zt}),Ee("muy-load","alpha",["muY"],{title:"Lateral force per unit load",series:kr,hold:Zt}),Ee("fy-peak","alpha",["Fy"],{title:"Lateral force over its peak",series:kr,hold:Zt,scale:{per:"peak"}},{from:0,to:15*pt,n:61}),Ee("muy-peak","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load"}),Ee("calpha","Fz",["Calpha"],{title:"Cornering stiffness over load"}),Ee("alpha-peak","Fz",["alphaPeak"],{title:"Slip angle at the peak over load"})]},{id:"aligning",name:"Aligning",cards:[Ee("mz-load","alpha",["Mz"],{title:"Aligning moment per wheel load",series:kr,hold:Zt}),Ee("trail","alpha",["t"],{title:"Pneumatic trail",series:kr,hold:Zt},{from:0,to:12*pt,n:49}),Ee("mzr","alpha",["Mzr"],{title:"Residual aligning moment",series:kr,hold:Zt},{from:0,to:12*pt,n:49}),Bm("gough",["alpha","Fz"],"Fy","Mz",{title:"Gough plot",hold:Zt}),Ee("steering-feel","alpha",["t"],{title:"Steering feel",x:"FyRel",series:kr,hold:Zt},{from:0,to:12*pt,n:49})]},{id:"longitudinal",name:"Longitudinal",cards:[Ee("fx-load","kappa",["Fx"],{title:"Longitudinal force per wheel load",series:kr,hold:bS}),Ee("mux-peak","Fz",["muXPeak"],{title:"Peak longitudinal \u03BC over load"}),Ee("kx","Fz",["dFxdk"],{title:"Slip stiffness at zero slip over load",hold:gg}),Ee("kappa-peak","Fz",["kappaPeak"],{title:"Slip ratio at the peak over load"})]},{id:"combined",name:"Combined",cards:[Bm("carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),Bm("envelope-load",["kappa","alpha"],"Fy","Fx",{title:"Friction envelope per load",scale:{per:"Fz"},facet:lN}),Ee("fy-kappa","kappa",["Fy"],{title:"Side force while driving or braking",series:{input:"alpha",values:[2*pt,4*pt,8*pt]}}),Ee("fx-kappa","kappa",["Fx"],{title:"Driving force while cornering",series:{input:"alpha",values:[0,4*pt,8*pt]}}),_n("ellipse","ellipse")]},{id:"camber",name:"Camber",cards:[Ee("fy-gamma","alpha",["Fy"],{title:"Lateral force per inclination",series:{input:"gamma",values:[-4,-2,0,2,4].map(e=>e*pt)},hold:Zt}),Ee("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",...xg.gamma},{input:"Fz",...xg.Fz,follow:!0}],x:"gamma",y:["Fz"],z:"muYPeak"},Ee("camber-stiffness","alpha",["dFydg"],{title:"Camber stiffness at the point",series:kr,hold:Zt}),Ee("mx","alpha",["Mx"],{title:"Overturning moment",series:kr,hold:Zt})]},{id:"rolling",name:"Rolling and radius",cards:[Ee("my","V",["My"],{title:"Rolling-resistance moment",series:kr,hold:gg}),Ee("radius","Fz",["R0","Rl","Re"],{title:"Radius over load"},{from:0}),Ee("p-roll","V",["Proll"],{title:"Rolling power",series:kr,hold:gg})]},{id:"transient",name:"Transient",cards:[Ee("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},Ee("delta-fy","alpha",["Fy"],{title:"Lateral force, minus the reference",hold:Zt,scale:{delta:!0}}),Ee("delta-mu","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load, minus the reference",scale:{delta:!0}}),Ee("delta-calpha","Fz",["Calpha"],{title:"Cornering stiffness over load, minus the reference",scale:{delta:!0}})]},{id:"car",name:"Car",cards:[_n("operating","operating"),_n("wheels","wheels")]},{id:"fit",name:"Fit check",cards:[_n("fitLateral","fitLateral"),_n("fitLongitudinal","fitLongitudinal"),_n("fitCoupling","fitCoupling"),_n("fitEnvelope","fitEnvelope")]}];var yN=5670374e-14,Rg=273.15,kS=.95,MS=60,$m=10,xN=.55,lr=25,vg=-20,kg=50,Pc={tempC:[20,100,200,550,650,750],factor:[.8,.92,1,1,.85,.65]},Lc={discMassKg:.5,discOuterMm:220,specificHeatJPerKgK:460,emissivity:.6,coolingWPerM2K:200,padCurve:{tempC:[...Pc.tempC],factor:[...Pc.factor]}},Gm={...Lc,discMassKg:.4,discOuterMm:200,padCurve:{tempC:[...Pc.tempC],factor:[...Pc.factor]}};function Mg(e,t){let r=t==="front"?Lc:Gm,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 RN=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},Tc=(e,t,r,n)=>Math.min(r,Math.max(t,RN(e,n)));function vN(e,t){let r=e,n=Array.isArray(r?.tempC)?r.tempC:[],o=Array.isArray(r?.factor)?r.factor:[],a=[];for(let i=0;i<Math.min(n.length,o.length);i++){let c=Number(n[i]),l=Number(o[i]);Number.isFinite(c)&&Number.isFinite(l)&&a.push([Math.min(1500,Math.max(-50,c)),Math.min(2,Math.max(.05,l))])}a.sort((i,c)=>i[0]-c[0]);let s=a.filter((i,c)=>c===0||i[0]>a[c-1][0]);return s.length?{tempC:s.map(i=>i[0]),factor:s.map(i=>i[1])}:{tempC:[...t.tempC],factor:[...t.factor]}}function Sg(e,t){return{discMassKg:Tc(e?.discMassKg,.05,20,t.discMassKg),discOuterMm:Tc(e?.discOuterMm,50,600,t.discOuterMm),specificHeatJPerKgK:Tc(e?.specificHeatJPerKgK,100,3e3,t.specificHeatJPerKgK),emissivity:Tc(e?.emissivity,.02,1,t.emissivity),coolingWPerM2K:Tc(e?.coolingWPerM2K,$m,5e3,t.coolingWPerM2K),padCurve:vN(e?.padCurve,t.padCurve)}}function Km(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 Ag(e,t=1){let r=e.discMassKg*e.specificHeatJPerKgK,n=e.discOuterMm*.001/2,o=2*Math.PI*n*n,a=MS/3.6,s=e.emissivity*yN*o,i=d=>$m+(e.coolingWPerM2K-$m)*Math.pow(Math.max(0,d)*t/a,xN),c=(d,p,m)=>{let f=d+Rg,h=m+Rg;return i(p)*o*(d-m)+s*(f**4-h**4)},l=(d,p)=>i(p)*o+4*s*Math.max(0,d+Rg)**3,u=(d,p)=>r/l(p,d);return{heatCapacityJPerK:r,areaM2:o,convectionAt:i,coolingW:c,timeConstantS:u,step(d,p,m,f,h){if(!(f>0))return d+p/r;let b=u(m,d+Math.max(0,p)/r),g=Math.max(1,Math.ceil(f/(.25*b))),y=f/g,x=p/g;for(let v=0;v<g;v++)d+=(x-c(d,m,h)*y)/r;return d},padFactor:d=>Km(e.padCurve,d),window:SS(e.padCurve)}}function Hm(e,t,r,n,o,a,s=lr){let i=n.length,c=new Array(i),l=new Array(i),u=new Array(i),d=kS/Math.max(1,t),p=a,m=p,f=0,h=0,b=0;for(let g=0;g<i;g++){let y=Math.max(0,r[g]??0);c[g]=p,l[g]=y*n[g],u[g]=e.padFactor(p);let x=y*(o[g]??0);f+=x,p<e.window.fromC?h+=x:p>e.window.toC&&(b+=x);let v=g+1<i?n[g+1]:n[g],k=.5*(n[g]+v),R=k>0?(o[g]??0)/k:0;p=e.step(p,d*x,k,R,s),p>m&&(m=p)}return{tempC:c,heatW:l,padFactor:u,startC:a,endC:p,maxC:m,workJ:f,coldWorkJ:h,hotWorkJ:b}}function SS(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])&&Km(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 wg=e=>typeof e=="number"&&Number.isFinite(e);function zm(e){if(e==null)return null;if(typeof e!="object"||Array.isArray(e))return"disc and caliper are not readable.";let t=e;for(let[r,n]of[["discDiameter","disc diameter"],["caliperHeight","caliper height"],["caliperLength","caliper length"],["caliperWidth","caliper width"]]){let o=t[r];if(!wg(o)||!(o>0))return`${n} must be a length above zero.`}return wg(t.discOffset)?!wg(t.caliperAngle)||Math.abs(t.caliperAngle)>180?"caliper angle must be between \u2212180\xB0 and 180\xB0.":null:"disc offset must be a length."}var Cg=1e5,FS=.001,ea={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},Tg={fullAtBar:10,maxPowerKw:0,fadeBelowKmh:0,distribution:"equal"};var Pg=PS(Wm(ea,"Formula Student brakes")),Lg=40,TS={ideal:!1,barFront:ea.barFront,pedalForceMaxN:0,testSpeedKmh:Lg,regen:Tg};function AS(e){let{heat:t,packaging:r,...n}=e;return{...n,...t?{heat:{...t,padCurve:{tempC:[...t.padCurve.tempC],factor:[...t.padCurve.factor]}}}:{},...r?{packaging:{...r}}:{}}}function PS(e){let t=(r,n)=>r.heat?r:{...r,heat:Mg(r,n)};return{...e,front:t(e.front,"front"),rear:t(e.rear,"rear")}}function Wm(e,t){return{name:t,pedalRatio:e.pedalRatio,masterFrontMm:e.masterFrontMm,masterRearMm:e.masterRearMm,valve:e.valve,valveKneeBar:e.valveKneeBar,valveSlope:e.valveSlope,front:AS(e.front),rear:AS(e.rear),adjusterPitchMm:e.adjusterPitchMm,barLengthMm:e.barLengthMm}}function Dg(e,t){return LS({...e,barFront:t.barFront,pedalForceMaxN:t.pedalForceMaxN})}function Eg(e,t){let r=On(t),n=e?an(e):void 0;return{mode:r.ideal?"tyre":n?"hydraulic":"balance",hydraulic:n?Dg(n,r):ea,regen:r.regen}}var kN=["none","proportioning","limiter"],Ym=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},St=(e,t,r,n)=>Math.min(r,Math.max(t,Ym(e,n))),MN=(e,t)=>{let r=Ym(e,t);return r>0?r:t};function wS(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(Ym(e?.discs,n==="inboard"?1:t.discs)))),pistonsPerSide:Math.max(1,Math.min(6,Math.round(Ym(e?.pistonsPerSide,t.pistonsPerSide)))),pistonDiaMm:St(e?.pistonDiaMm,5,80,t.pistonDiaMm),padMu:St(e?.padMu,.05,1.5,t.padMu),effRadiusMm:St(e?.effRadiusMm,20,300,t.effRadiusMm),ratio:n==="inboard"?St(e?.ratio,1,20,t.ratio):1,...e?.heat&&typeof e.heat=="object"?{heat:Sg(e.heat,t.heat??r)}:{},...zm(e?.packaging)===null&&e?.packaging?{packaging:{...e.packaging}}:{}}}function LS(e){let t=ea;return{pedalRatio:St(e?.pedalRatio,.5,15,t.pedalRatio),pedalForceMaxN:St(e?.pedalForceMaxN,0,5e3,t.pedalForceMaxN),barFront:St(e?.barFront,.05,.95,t.barFront),masterFrontMm:St(e?.masterFrontMm,8,40,t.masterFrontMm),masterRearMm:St(e?.masterRearMm,8,40,t.masterRearMm),valve:kN.includes(e?.valve)?e?.valve:t.valve,valveKneeBar:St(e?.valveKneeBar,0,200,t.valveKneeBar),valveSlope:St(e?.valveSlope,0,1,t.valveSlope),front:wS(e?.front,t.front,Lc),rear:wS(e?.rear,t.rear,Gm),adjusterPitchMm:MN(e?.adjusterPitchMm,t.adjusterPitchMm),barLengthMm:St(e?.barLengthMm,0,500,t.barLengthMm)}}function SN(e){let t=Tg;return{fullAtBar:St(e?.fullAtBar,0,200,t.fullAtBar),maxPowerKw:St(e?.maxPowerKw,0,1e3,t.maxPowerKw),fadeBelowKmh:St(e?.fadeBelowKmh,0,100,t.fadeBelowKmh),distribution:e?.distribution==="wheel"?"wheel":"equal"}}function an(e){let t=LS(e??void 0),r=typeof e?.name=="string"&&e.name.trim()?e.name:AN;return Wm(t,r)}function On(e){return{ideal:e?.ideal===!0,barFront:St(e?.barFront,.05,.95,ea.barFront),pedalForceMaxN:St(e?.pedalForceMaxN,0,5e3,0),testSpeedKmh:St(e?.testSpeedKmh,5,150,Lg),regen:SN(e?.regen)}}var AN="Formula Student brakes";var Fg=e=>Math.PI/4*(e*FS)**2;function xo(e,t){let r=e.pistonsPerSide*Fg(e.pistonDiaMm)*Cg;return e.discs*2*e.padMu*r*e.effRadiusMm*FS*e.ratio/Math.max(.05,t)}function DS(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 Dc(e,t){let r=Math.max(0,t)*e.pedalRatio,n=e.barFront*r/Fg(e.masterFrontMm)/Cg,o=(1-e.barFront)*r/Fg(e.masterRearMm)/Cg;return{front:n,rearIn:o,rear:DS(e,o)}}function wN(e,t){let r=Dc(e,1);return{front:xo(e.front,t)*r.front,rear:xo(e.rear,t)*r.rearIn}}function Ec(e,t){let r=wN(e,t);return r.front/Math.max(1e-12,r.front+r.rear)}function Ic(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=ES(t,l),d=t.maxPowerKw>0&&l>0?t.maxPowerKw*1e3/l:1/0,p=Math.max(0,e.fFront[c]),m=Math.max(0,e.fRear[c]),f=p+m>0?Math.min(1,d/(p+m)):1;r.push(l),n.push(p*f*u),o.push(m*f*u)}}function ES(e,t){let r=e.fadeBelowKmh/3.6;return r>0?Math.max(0,Math.min(1,t/r)):1}function Nn(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 CS=new WeakMap;function ta(e){let t=CS.get(e);return t||(t=e.mode==="hydraulic"&&e.hydraulic?FN(e,e.hydraulic):CN(e),CS.set(e,t)),t}function CN(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 FN(e,t){let r=xo(t.front,e.tyreRadiusM),n=xo(t.rear,e.tyreRadiusM),o=e.regen,a=(c,l)=>{let u=Dc(t,c),d=0,p=0;if(o&&u.front>0){let m=o.fullAtBar>0?Math.min(1,u.front/o.fullAtBar):1;d=m*Nn(o.v,o.front,l),p=m*Nn(o.v,o.rear,l)}return{front:r*u.front+d,rear:n*u.rear+p,regenFront:d,regenRear:p,pFront:u.front,pRear:u.rear,pedalN:c}},s=t.pedalForceMaxN>0?t.pedalForceMaxN:1/0,i=(c,l)=>{let u=a(c,l);return u.front+u.rear};return{mode:"hydraulic",equalLeftRight:!0,uMax:s,demand:a,controlFor:(c,l)=>{if(!(c>0))return 0;let u=100;for(;i(u,l)<c&&u<1e6;)u*=2;if(u=Math.min(u,s),i(u,l)<=c)return u;let d=0;for(let p=0;p<60;p++){let m=.5*(d+u);i(m,l)<c?d=m:u=m}return u}}}function Ig(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 jm=mc,TN=.1,ra=(e,t)=>e.a*Math.sqrt(Math.max(0,1-(t/Math.max(1e-9,e.b))**2));function Um(e,t,r){if(!(r>t))return t;let n=(Math.sqrt(5)-1)/2,o=t,a=r,s=a-n*(a-o),i=o+n*(a-o),c=e(s),l=e(i);for(let p=0;p<48;p++)c<l?(o=s,s=i,c=l,i=o+n*(a-o),l=e(i)):(a=i,i=s,l=c,s=a-n*(a-o),c=e(s));let u=.5*(o+a),d=e(u);for(let p of[t,r]){let m=e(p);m>d&&(u=p,d=m)}return u}function Og(e,t,r){let n=Math.max(0,r-jm*t.b),o=Math.min(r,jm*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 d=.5*(c+l);s(d)>0?c=d:l=d}i=.5*(c+l)}return{lo:n,hi:o,y1:i,c1:e.cap(i),c2:t.cap(r-i)}}function Vg(e,t,r,n,o=0){let a=Math.max(0,r),s=Og(e,t,a),i=s?s.c1:0,c=s?s.c2:0,l=s?Math.min(i,c):0,[u,d]=e.a<=t.a?[e,t]:[t,e],p=u.Fz/Math.max(1e-9,u.Fz+d.Fz),m=Math.max(0,Math.min(1,1-p/TN)),f=m>0&&a<jm*d.b?d.cap(a):0,h=f>l?l+m*(f-l):0,b=Math.max(0,Math.min(u.slide,u.a)),g={xNoLock:l,xLock:h,slide:b,ceiling:Math.max(0,n)},y=Math.max(0,o);if(!(y>0)||!s)return{...g,regenWheel:s?y:0,mixedMax:2*l,regenRoom:T=>2*Math.max(0,l-T)};let{lo:x,hi:v}=s,k=Um(T=>{let A=ra(e,T),C=ra(t,a-T);return Math.min(A+C,2*Math.min(A,C)+y)},x,v),R=e.cap(k),M=t.cap(a-k),S=Math.max(2*l,Math.min(R+M,2*Math.min(R,M)+y)),w=(T,A,C)=>Math.min(y,Math.max(0,T-C))+Math.min(y,Math.max(0,A-C));return{...g,regenWheel:y,mixedMax:S,regenRoom:T=>{let A=w(i,c,T);if(!(a>0))return A;let C=_=>jm*_.b*Math.sqrt(Math.max(0,1-(T/Math.max(1e-9,_.a))**2)),P=Math.max(x,a-C(t)),L=Math.min(v,C(e));if(!(P<=L))return A;let E=Um(_=>Math.min(y,ra(e,_)-T)+Math.min(y,ra(t,a-_)-T),P,L);return Math.max(A,w(e.cap(E),t.cap(a-E),T))}}}var _g=e=>Math.max(e.xNoLock,e.xLock),Ng=e=>Math.max(e.mixedMax,2*e.xLock);function Is(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 _s(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 _c(e,t,r,n){return e.shares?PN(e,e.shares,t,r,n):LN(e,t,r,n)}function IS(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 PN(e,t,r,n,o){let a=Ng(r),s=Ng(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=_s(r,t.front*b),y=_s(n,t.rear*b);return Number.isFinite(g)&&Number.isFinite(y)?g+y:-1/0},u=a>0?t.front*i/a:1/0,d=s>0?t.rear*i/s:1/0,p=[{u:i,by:c?"pedal":u>=d?"front":"rear"}];if(r.xLock>r.xNoLock){let b=t.front>0?r.mixedMax/t.front:1/0;b<i&&p.push({u:b,by:"front"})}if(n.xLock>n.xNoLock){let b=t.rear>0?n.mixedMax/t.rear:1/0;b<i&&p.push({u:b,by:"rear"})}let{cand:m,force:f}=IS(p,l),h=e.demand(m.u,o);return{force:Math.max(0,Number.isFinite(f)?f:0),control:m.u,demand:h,limitedBy:m.by,lockFront:h.front/2>r.mixedMax/2*(1+1e-9),lockRear:h.rear/2>n.mixedMax/2*(1+1e-9)}}function LN(e,t,r,n){let o=_g(t),a=_g(r),s=k=>(k.front-k.regenFront)/2,i=k=>(k.rear-k.regenRear)/2,c=k=>{let R=e.demand(k,n);return s(R)<=o*(1+1e-12)&&i(R)<=a*(1+1e-12)},l=(k,R)=>{if(k(e.demand(R,n)))return R;let M=0,S=R;for(let w=0;w<60;w++){let F=.5*(M+S);k(e.demand(F,n))?M=F:S=F}return M},u=Number.isFinite(e.uMax)?e.uMax:100;if(!Number.isFinite(e.uMax))for(;c(u)&&u<1e7;)u*=2;let d=c(u)?u:l(k=>s(k)<=o&&i(k)<=a,u),p=Number.isFinite(e.uMax)&&d>=e.uMax,m=k=>{let R=e.demand(k,n),M=Is(t,s(R),R.regenFront),S=Is(r,i(R),R.regenRear);return Number.isFinite(M)&&Number.isFinite(S)?M+S:-1/0},f=e.demand(d,n),h=o>0?s(f)/o:1/0,b=a>0?i(f)/a:1/0,g=[{u:d,by:p?"pedal":h>=b?"front":"rear"}];if(t.xLock>t.xNoLock){let k=l(R=>s(R)<=t.xNoLock,d);k<d&&g.push({u:k,by:"front"})}if(r.xLock>r.xNoLock){let k=l(R=>i(R)<=r.xNoLock,d);k<d&&g.push({u:k,by:"rear"})}let{cand:y,force:x}=IS(g,m),v=e.demand(y.u,n);return{force:Math.max(0,Number.isFinite(x)?x:0),control:y.u,demand:v,limitedBy:y.by,lockFront:s(v)>t.xNoLock*(1+1e-9),lockRear:i(v)>r.xNoLock*(1+1e-9)}}var Vn={regen:!0,regenEfficiency:.6};function Bn(e,t){let r=e.energy??t??Vn;return{regen:r.regen===!0,regenEfficiency:Math.min(1,Math.max(0,Number.isFinite(r.regenEfficiency)?r.regenEfficiency:0))}}function $n(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 _S(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 Ct(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 Xm(e,t,r){let n=e.length;if(!(r>=e[0]&&r<=e[n-1]))return NaN;if(n<3)return n===1?t[0]:t[0]+(r-e[0])/(e[1]-e[0])*(t[1]-t[0]);let o=0,a=n-1;for(;a-o>1;){let f=o+a>>1;e[f]<=r?o=f:a=f}if(o===n-1)return t[n-1];let s=f=>e[f+1]-e[f],i=f=>(t[f+1]-t[f])/s(f),c=f=>{if(f===0||f===n-1){let[y,x]=f===0?[0,1]:[n-2,n-3],v=i(y)*(1+s(y)/(s(y)+s(x)))-i(x)*(s(y)/(s(y)+s(x)));return v*i(y)<=0?0:Math.abs(v)>2*Math.abs(i(y))?2*i(y):v}let h=i(f-1),b=i(f),g=(h*s(f)+b*s(f-1))/(s(f-1)+s(f));return(Math.sign(h)+Math.sign(b))*Math.min(Math.abs(h),Math.abs(b),.5*Math.abs(g))},l=s(o),u=i(o),d=c(o),p=c(o+1),m=r-e[o];return t[o]+m*(d+m*((3*u-2*d-p)/l+m*(d+p-2*u)/(l*l)))}function Nc(e,t,r){return r.map(n=>Ct(e,t,n))}var Oc=e=>e.reduce((t,r)=>r>t?r:t,-1/0),Ns=e=>e.reduce((t,r)=>r<t?r:t,1/0);var DN=[-.906179845938664,-.538469310105683,0,.538469310105683,.906179845938664],EN=[.236926885056189,.478628670499366,.568888888888889,.478628670499366,.236926885056189];function Bg(e,t,r){let n=.5*(r-t),o=.5*(t+r),a=0;for(let s=0;s<5;s++)a+=EN[s]*e(n*DN[s]+o);return n*a}var IN=Math.PI*2,_N=.5/3.6;function Vc(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 $g(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*IN;c[g]=y*o/n,l[g]=s[g]*n/o}let u=Oc(c),d=$n(Ns(c),u,u/_N),p=Nc(c,l,d),{front:m,rear:f}=Vc(t,r),h=p.map(g=>g*m),b=p.map(g=>g*f);return{vVehicle:d,fFront:h,fRear:b,vMax:u}}var NS=60/(2*Math.PI),OS=.1,VS=.08,BS=0;function Gg(e){let t=(r,n)=>r===void 0||!Number.isFinite(r)?n:Math.max(0,r);return{up:t(e.upshiftTime,OS),down:t(e.downshiftTime,VS)}}function Kg(e){let t=e.driveKept;return t===void 0||!Number.isFinite(t)?BS:Math.max(0,Math.min(1,t))}function Hg(e,t,r){let{primary:n,ratios:o,efficiency:a}=e.gearbox,s=t>0&&r>0&&n>0,i=(b,g)=>b/NS*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),d=b=>b>e.limitRpm?0:Math.max(0,et(e.rpm,e.torque,b)),p=(b,g)=>{let y=c[g];return y?b*y.ratio/r*NS:0},m=(b,g)=>g===0&&c.length>0&&b<c[0].vIdle,f=(b,g)=>{let y=c[g];return y?m(b,g)?d(e.idleRpm)*y.ratio*l/r:b<y.vIdle||b>y.vLimit?0:d(p(b,g))*y.ratio*l/r:0},h=(b,g)=>{let y=c[g];return!y||m(b,g)?0:u*y.ratio*y.ratio/(r*r)};return{engine:e,gears:c,efficiency:l,rDyn:r,vMax:c.length?c[c.length-1].vLimit:0,rpm:p,torque:d,force:f,inertiaMass:h,slipping:m}}function Os(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 zg(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 $S=9.81,GS=Math.PI*2;function ur(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 k=0;k<n;k++)o[k]=r[k]*t[k]*(GS/60),a[k]=t[k]/60*GS,s[k]=a[k]*u/l,i[k]=r[k]*l,c[k]=i[k]/u;let d=Oc(s),p=d,m=.5/3.6,f=$n(Ns(s),d,d/m),h=Nc(s,c,f),b=$n(Ns(t),Oc(t),250),g=Nc(t,o,b).map(k=>k*e.power_scale.value),y,x=p,v;if(e.motorModel?.kind==="ice"){v=Hg(e.motorModel,l,u);let k=$n(0,v.vMax,Math.max(2,Math.ceil(v.vMax/m)+1)),R=k.map(w=>zg(v,w)),M=k.map(()=>0),S=e.motorPlacement==="front";y={vVehicle:k,fFront:S?R:M,fRear:S?M:R,vMax:v.vMax},x=v.vMax}else e.motorModel&&(y=$g(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:$S,FG:e.m.value*$S,vMax:x,vVehicle:f,fRad:h,uMotor:b,pMotor:g,vRad:s,fAxle:y,...v?{engine:v}:{}}}var Br=e=>e.motorModel?.kind==="ice"?Vc(1,e.motorPlacement==="front"?"front":"rear"):Vc(Math.max(1,Math.round(e.motorCount??e.driven_wheels?.value??2)),e.motorPlacement??"rear");function KS(e){let t=Br(e);return t.front>=2||t.rear>=2}function HS(e){return KS(e)?e.motorMount??"hub":"chassis"}function Yg(e){if(!e.motorModel)return{front:!1,rear:!0};let t=Br(e);return{front:t.front>0,rear:t.rear>0}}function qm(e){let t=Br(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=HS(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 Yt(e){return Eg(e.brakeModel,e.brakeSetup)}function Bc(e){return On(e.brakeSetup).ideal?"tyre":e.brakeModel||e.brakeModelId?"hydraulic":"balance"}function Qm(e){let t=Bc(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 zS(e,t){if(!(kt(e.motorModel)||!Bn(e).regen))return Ic(Zm(ur(e)),t??Yt(e).regen)}function Zm(e){return e.fAxle??{vVehicle:e.vVehicle,fFront:e.vVehicle.map(()=>0),fRear:e.fRad.map(t=>t*e.params.driven_wheels.value)}}function Wg(e,t=Yt(e)){if(t.mode==="hydraulic")return Ec(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+ee(e,"cg_height")/Math.max(1,ee(e,"wheelbase"))))}return ee(e,"brake_balance")}function jg(e,t=Yt(e)){return{front:t.hydraulic.front.location==="inboard",rear:t.hydraulic.rear.location==="inboard"}}function Ug(e){let t=Yt(e);return{brakeBalanceFront:Wg(e,t),brakeInboard:jg(e,t)}}function YS(e,t=Yt(e)){if(t.mode==="tyre"||t.regen.distribution!=="wheel"||kt(e.motorModel))return;let r=Br(e),n={front:r.front>=2,rear:r.rear>=2};return n.front||n.rear?n:void 0}function $c(e){let t=Yt(e),r=e.r_dyn.value,n=jg(e,t),o=Wg(e,t),a=YS(e,t),s=t.mode==="hydraulic"||a?zS(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 ON=9.81;function qg(e,t){let r=WS(e,t);return(n,o,a)=>r(n,o,a).total}var Xg={front:0,rear:0,total:0};function WS(e,t){if(kt(e.motorModel))return()=>Xg;let r=Yt(e),n=Ic(t,r.regen);if(r.mode==="hydraulic"){let a=ta({mode:"hydraulic",balanceFront:Ec(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 Xg;let c=a.demand(a.controlFor(s,i),i),l=c.regenFront+c.regenRear,u=Math.min(s,l),d=l>0?u/l:0;return{front:c.regenFront*d,rear:c.regenRear*d,total:u}}}let o=r.mode==="tyre"?VN(e):()=>Math.min(.99,Math.max(.01,ee(e,"brake_balance")));return(a,s,i)=>{if(!(a>0))return Xg;let c=o(s,i),l=Math.min(c*a,Nn(n.v,n.front,s)),u=Math.min((1-c)*a,Nn(n.v,n.rear,s));return{front:l,rear:u,total:l+u}}}function VN(e){let t=e.m.value*ON,r=e.front_mass_diss.value>1?e.front_mass_diss.value/100:e.front_mass_diss.value,n=ee(e,"cg_height")/Math.max(1,ee(e,"wheelbase")),o=1-Math.max(0,Math.min(1,ee(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 jS(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 Qg={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"},...jS("front"),...jS("rear")},Zg={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 Jg(e){let t=Qg[e];return`${t.label}, ${t.section}`.toLowerCase()}function e0(e){let t=Zg[e];return t.section?`${t.section} ${t.label.charAt(0).toLowerCase()}${t.label.slice(1)}`:t.label}var US=new WeakMap;function sn(e){if(e.brakes)return e.brakes;let t=US.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},US.set(e,t)}return t}var Gn=e=>ta(sn(e));var KN=Math.PI/180,Vs=Object.freeze({tbr:1,preloadN:0}),Jm=Object.freeze({tbr:1/0,preloadN:0}),r0=e=>e.faces*e.muClutch*e.rFrictionMm/e.rRampMm;function n0(e,t){if(!(e>0)||Number.isNaN(t))return 0;let r=Math.tan(Math.min(90,t)*KN);return r>0?Math.min(1,e/r):1}function qS(e){if(e>=1)return 1/0;let t=e>0?e:0;return(1+t)/(1-t)}function ed(e){return e===1/0?1:e>1?(e-1)/(e+1):0}function na(e,t){return e.tbr===1/0?1/0:(e.preloadN>0?e.preloadN:0)+ed(e.tbr)*Math.abs(t)}function Kc(e,t,r){let n=o=>o!==void 0&&o>0&&r>0?o/r:0;switch(e.kind){case"open":return Vs;case"spool":return Jm;case"independent":return t==="hubs"?Vs:Jm;case"clutch":{let o=n(e.preloadNm);return t==="hubs"?{tbr:1,preloadN:o}:{tbr:qS(n0(r0(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 Gc(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 XS=4;function t0(e,t){let r=0;for(let a of e)r=Math.max(r,Gc(a.m1,a.m2,t));let n=t.tbr>1?t.tbr:1,o=(t.preloadN>0?t.preloadN:0)*(1+n)/2;if(n===1/0||o===1/0)return r;for(let a=0;a+1<e.length;a++){let s=e[a],i=e[a+1].m1-s.m1,c=e[a+1].m2-s.m2,l=p=>{p>0&&p<1&&(r=Math.max(r,Gc(s.m1+p*i,s.m2+p*c,t)))};i!==c&&l((s.m2-s.m1)/(i-c));let u=i+c-(1+n)*i,d=i+c-(1+n)*c;u!==0&&l(((1+n)*s.m1+o-s.m1-s.m2)/u),d!==0&&l(((1+n)*s.m2+o-s.m1-s.m2)/d)}return r}function Hc(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=Og(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 d=Um(b=>ra(e,b)+ra(t,c-b),l.lo,l.hi),p=[{m1:l.c1,m2:l.c2}];for(let b=1;b<=XS&&d!==l.y1;b++){let g=l.y1+(d-l.y1)*b/XS;p.push({m1:e.cap(g),m2:t.cap(c-g)})}let m=t0(p,Vs),f=t0(p,Jm);if(!(f>m))return u;let h=(t0(p,{tbr:s,preloadN:i})-m)/(f-m);return Math.min(a,u+(a-u)*Math.min(1,Math.max(0,h)))}function QS(e,t,r,n,o,a){return o0(e,o,Hc(t,r,n,o,a))}function o0(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 a0(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 d=s<0!=l<0,p=l-s,m=p!==0?i-l*(i-o)/p:NaN;d?m>Math.min(o,i)&&m<Math.max(o,i)||(m=.5*(o+i)):Number.isFinite(m)?Math.abs(m-i)>10*Math.abs(l)&&(m=i+Math.sign(m-i)*10*Math.abs(l)):m=c;let f=e(m),h=f-m;if(u++,d&&h<0==l<0?s*=.5:(o=i,s=l),i=m,c=f,l=h,s<0!=l<0&&Math.abs(i-o)<=r)break}return{x:i,fx:c,evals:u}}function ZS(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),d=Math.abs(r-t),p=0;for(let m=o;l<a;m*=2){if(p=Math.min(p+m,d),p>d-n)return null;let f=t+u*p,h=e(f),b=h-f;if(l++,!(Math.abs(b)>n))return{x:f,fx:h,evals:l};if(c<0!=b<0)return eA(e,s,c,f,h,b,n,l,a);s=f,c=b}return null}function JS(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),d=u-c;if(!(Math.abs(d)>r))return{x:c,fx:u,evals:l};if(s<0!=d<0)return eA(e,o,s,c,u,d,r,l,n);if(l>=n)return{x:c,fx:u,evals:l};let p=Math.abs(c-o),m=s!==d?d*(c-o)/(s-d):NaN,f=m*i>0?Math.min(Math.abs(m),10*Math.abs(d),2*p):2*p;o=c,s=d,c+=i*f}}function eA(e,t,r,n,o,a,s,i,c){let l=t,u=r,d=n,p=a,m=n,f=o,h=0;for(;i<c&&Math.abs(d-l)>s;){m=(l*p-d*u)/(p-u),f=e(m);let b=f-m;if(i++,!(Math.abs(b)>s))break;b<0==u<0?(l=m,u=b,h===-1&&(p*=.5),h=-1):(d=m,p=b,h===1&&(u*=.5),h=1)}return{x:m,fx:f,evals:i}}function td(e,t){return Math.abs(e.fx-e.x)>t?e.x:e.fx}var HN=(e,t)=>{let r=e.brakes?.hydraulic?.[t];return!!r&&r.location==="inboard"&&r.discs===1};function mr(e,t,r){let n=e.driveline?.[t];if(n)return r>=0?n.drive:HN(e,t)?n.coast:n.hubs}var tA=e=>e.tbr>1||e.preloadN>0;var zN=9.81,rA=["FL","FR","RL","RR"],s0=e=>e==="FL"||e==="FR",rd=e=>s0(e)?"front":"rear",nA={front:["FL","FR"],rear:["RL","RR"]},Wc=()=>({peak:new Map,freeBrake:new Map}),Yc=25;function zc(e,t){let r=Math.max(0,e)/Yc,n=Math.floor(r),o=r-n,a=t(n);return o>0?a+o*(t(n+1)-a):a}var Ro=1e-4,YN=.05;function Kn(e,t,r,n=Wc(),o=!1){let a=r,s=e.massTotal,i=n.peak,c=(A,C)=>{let P=`${A}:${C}`,L=i.get(P);return L||(L=mm(we(t,A),Math.max(1,C*Yc)),i.set(P,L)),L},l=(A,C)=>({aPeak:zc(C,P=>c(A,P).aPeak),fyPeak:zc(C,P=>c(A,P).fyPeak)}),u=n.freeBrake,d=(A,C)=>{let P=`${A}:${C}`,L=u.get(P);if(L===void 0){let E=Math.max(1,C*Yc);L=cr(we(t,A),E,0,!0,c(A,C)),u.set(P,L)}return L},p=(A,C)=>C>0?zc(C,P=>d(A,P)):0,m=Gn(e),f=sn(e),h=A=>f.regen&&f.regenPerWheel?.[A]?Nn(f.regen.v,f.regen[A],a)/2:0,b=h("front"),g=h("rear"),y=(A,C,P)=>{let L=Math.max(0,C[A]),E=l(rd(A),L);return cr(we(t,rd(A)),L,P[A]*E.fyPeak,!0,E)},x=(A,C,P,L,E=!0,_=1)=>{let D=ne=>{let U=Math.max(0,C[ne]),Q=we(t,A),se=l(A,U),de={Fz:U,a:Math.abs(p(A,U)),b:se.fyPeak,slide:U>0?Math.abs(Q.forces({Fz:U,kappa:-1,alpha:0}).Fx):0,cap:ue=>Math.abs(cr(Q,U,ue,!0,se))};return _===1?de:{Fz:U,a:_*de.a,b:_*de.b,slide:_*de.slide,cap:ue=>_*de.cap(ue/_)}},I=ne=>_*Math.abs(P[ne])*l(rd(ne),Math.max(0,C[ne])).fyPeak,[V,O]=nA[A],B=D(V),z=D(O),j=I(V)+I(O),$=Vg(B,z,j,L,A==="front"?b:g),N=E?$:{...$,xLock:0},W=mr(e,A,-1),Z=W&&tA(W)?W:void 0;if(!Z)return{axle:A,eq:N,cap:N};let q=Number.isFinite(L)?L:B.cap(I(V))+z.cap(I(O)),Y=QS(N,B,z,j,Z,q);return{axle:A,eq:N,cap:Y,law:Z,strong:()=>B.cap(I(V))>=z.cap(I(O))?V:O}},v=(A,C,P,L,E=1)=>x(A,C,P,L,!0,E).cap,k=(A,C,P)=>{let L=A.demand,E=m.shares?_s(C,L.front):Is(C,(L.front-L.regenFront)/2,L.regenFront),_=m.shares?_s(P,L.rear):Is(P,(L.rear-L.regenRear)/2,L.regenRear);return{front:Number.isFinite(E)?E:0,rear:Number.isFinite(_)?_:0}},R=A=>({muX:C=>C>0?Math.abs(p(A,C))/C:0,muY:C=>C>0?l(A,C).fyPeak/C:0}),M={front:R("front"),rear:R("rear")},S={lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},w={front:e.trackFront/2e3,rear:e.trackRear/2e3},F=(A,C,P,L,E)=>{let _=L.cap,D=E.cap,I=_c(m,_,D,a),V={arms:S,halfTrack:w,ayDir:Math.sign(A)};for(let O=0;O<2;O++){let B=k(I,_,D),z={};for(let $ of rA){let N=Math.max(0,C[$]);z[$]={Fz:N,Fy:Math.abs(P[$])*l(rd($),N).fyPeak,Fx:-(s0($)?B.front:B.rear)/2}}let j=$=>{if(!$.law||!$.strong)return $.cap;let N={axle:$.axle,strong:$.strong(),full:2*$.cap.xNoLock,open:2*$.eq.xNoLock,sense:-1};return o0($.eq,$.law,Em(N,z,M,V))};_=j(L),D=j(E),I=_c(m,_,D,a)}return{limit:I,front:_,rear:D}};return{peakAt:l,axle:v,ceiling:(A,C,P)=>{let[L,E]=nA[A];return Math.abs(y(L,C,P)+y(E,C,P))},limitAt:(A,C,P,L=0)=>{let E={FL:0,FR:0,RL:0,RR:0},_=We(e,A,0,a,0,C),D,I=ne=>(D?.ax!==ne&&(D={ax:ne,loads:We(e,A,(ne+L)/zN,a,0,C)}),D.loads),V=dm(ne=>ws(P,I(ne),_,l).short,-L,-1),O=P,B={front:0,rear:0},z,j,$=(ne,U=!0)=>{let Q=V.at(ne);E=I(Q),O=ws(P,E,_,l).util;let se=0,de=0,ue=0;for(let ie of rA){let ve=y(ie,E,O);se+=ve,s0(ie)?de+=ve:ue+=ve}if(B={front:Math.abs(de),rear:Math.abs(ue)},m.mode!=="tyre"){let ie=x("front",E,O,Math.abs(de),U),ve=x("rear",E,O,Math.abs(ue),U);if(o&&(ie.law||ve.law)){let Ie=F(A,E,O,ie,ve);z=Ie.limit,j={front:Ie.front,rear:Ie.rear}}else z=_c(m,ie.cap,ve.cap,a),j={front:ie.cap,rear:ve.cap};se=-z.force}return se/s},N=a0($,0,Ro),W=td(N,Ro),Z=W;if(z?.lockFront||z?.lockRear){let ne=a0(Q=>$(Q,!1),0,Ro);Z=td(ne,Ro);let U=ZS($,ne.x,N.x,Ro,YN);U||$(N.x),W=td(U??N,Ro)}let q=V.edge(),Y=q!==void 0&&W<q;Y&&(W=Math.min(0,q),$(W),Z=Math.max(Z,W));let K={loads:E,ceiling:B,limit:z,axles:j};return{ax:W,axUnlocked:Z,...Y?{edge:q}:{},...K,split:()=>K.limit&&K.axles?k(K.limit,K.axles.front,K.axles.rear):{...K.ceiling}}}}}var od=9.81;function WN(e,t,r){let n=We(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 sA=(e,t)=>t.mode==="hydraulic"&&!!sn(e).regen;function Bs(e,t,r=0,n,o=0,a=1){if(!e.brakes&&e.brakeBalanceFront==null)return e.frontMassFrac;let s=Gn(e);if(s.shares&&s.mode!=="tyre")return s.shares.front;let i=n&&sA(e,s)?lA(e,n):void 0,c=i?iA(a):oa,l=i?cA(i,c).shares:oA.get(e);l||oA.set(e,l=new Map);let u=Math.round(Math.abs(t)/.005),d=Math.round(Math.max(0,r)/.25),p=i?Math.round(o/.01):0,m=uA(u,d,p),f=l.get(m);if(f===void 0){let h=-u*.005,b=d*.25,g=e.massTotal*Math.abs(h)*od;if(i){let y=dA(s,mA(e,i,u,d,p,c),g,b);f=y.front+y.rear>0?y.front/(y.front+y.rear):.5}else f=s.mode==="tyre"?WN(e,h,b):Ig(s,g,b);l.size>5e4&&l.clear(),l.set(m,f)}return f}var oA=new WeakMap;function ad(e,t,r,n,o=0,a=1){let s=Gn(e);if(!sA(e,s))return;let i=Math.round(Math.max(0,r)/(e.massTotal*od)/.005),c=Math.round(Math.max(0,n)/.25);return dA(s,mA(e,lA(e,t),i,c,Math.round(o/.01),iA(a)),Math.max(0,r),n)}var oa=100,iA=e=>e>0&&Number.isFinite(e)?Math.max(1,Math.round(e*oa)):oa;function cA(e,t){if(t===oa)return e;let r=e.roads.get(t);return r||e.roads.set(t,r={shares:new Map,rooms:new Map}),r}var aA=new WeakMap;function lA(e,t){let r=aA.get(e);r||aA.set(e,r=new WeakMap);let n=r.get(t);return n||r.set(t,n={ev:t,tyres:Wc(),shares:new Map,rooms:new Map,speeds:new Map,roads:new Map}),n}var uA=(e,t,r)=>(r*1001+e)*100003+t;function mA(e,t,r,n,o,a=oa){let s=uA(r,n,o),i=cA(t,a),c=a===oa?1:a/oa,l=i.rooms.get(s);if(!l){let u=n*.25,d=o*.01,p=t.speeds.get(n);p||(p={cap:Kn(e,t.ev,u,t.tyres),dragG:-Math.max(0,Wi(e,u).drag)/(e.massTotal*od)},t.speeds.set(n,p));let{cap:m}=p,f=We(e,d,-r*.005+p.dragG,u),h=Math.abs(d)*e.massTotal*od,b=x=>{let[v,k]=x==="front"?["FL","FR"]:["RL","RR"],R=h*(x==="front"?e.frontMassFrac:1-e.frontMassFrac),M=c*(m.peakAt(x,Math.max(0,f[v])).fyPeak+m.peakAt(x,Math.max(0,f[k])).fyPeak),S=R>0&&M>0?Math.min(1,R/M):0;return m.axle(x,f,{FL:S,FR:S,RL:S,RR:S},1/0,c)},g,y;l=(x,v)=>(x==="front"?g??=b("front"):y??=b("rear")).regenRoom(v),i.rooms.size>5e4&&i.rooms.clear(),i.rooms.set(s,l)}return l}function nd(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 dA(e,t,r,n){if(!(r>0))return nd(e,t,1,n);let o=c=>c.front+c.rear,a=e.controlFor(r,n),s=nd(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=nd(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=nd(e,t,l,n);o(u)<r?a=l:(i=l,s=u)}return s}var $s={rel:.003,abs:2,kappa:1e-5,iters:12},Gs={rel:1e-6,abs:.001,kappa:1e-12,iters:40},id={...Gs,settle:1e-9};function vo(e,t,r,n=$s,o,a){let s=t>=0?1:-1,i=Math.abs(t),c=Math.max(n.abs,n.rel*i),l={kappa:NaN,forces:null},u=o??(S=>{let w=e(S);return l.kappa=S,l.forces=w,w.Fx}),d=u(0);if(Math.abs(d)-i>=0)return sd(e,l,0);let p=a?s>0?a.drive:a.brake:void 0;if(p&&p.mag<i)return p.stop;let m=0,f=d,h=Math.abs(d)-i,b=Math.min(.3,Math.max(.004,Math.abs(r)||.02)),g=u(s*b),y=Math.abs(g)-i,x=NaN,v=0;for(;y<0&&b<.3;){let S=Math.min(.3,b*1.9),w=u(s*S),F=Math.abs(w);if(F<Math.abs(g)){x=S,v=w;break}m=b,f=g,h=y,b=S,g=w,y=F-i}if(y<0){let S=XN(u,s,m,f,b,g,x,v);if(S.mag<i){let w=sd(e,l,s*S.kappa);return a&&(a[s>0?"drive":"brake"]={mag:S.mag,stop:w}),w}b=S.kappa,y=S.mag-i}let k=s*b,R=n.settle;if(R!==void 0){let S=m,w=h,F=b,T=y;Math.abs(w)<Math.abs(T)&&([S,w,F,T]=[F,T,S,w]);let A=0;for(let C=0;C<n.iters&&b-m>n.kappa;C++){let P=T-w,L=A<2&&Math.abs(P)>1e-12?F-T*(F-S)/P:NaN;if(!(L>m&&L<b)){let D=y-h;L=A<2&&Math.abs(D)>1e-12?(m*y-b*h)/D:.5*(m+b),L>m&&L<b||(L=.5*(m+b)),A=0}let E=Math.abs(u(s*L))-i;k=s*L;let _=E!==T?Math.abs(E*(L-F)/(E-T)):1/0;if(Math.abs(E)<c&&(Math.abs(L-F)<=R||_<=R))break;A=Math.abs(E)>.5*Math.abs(T)?A+1:0,E<0?(m=L,h=E):(b=L,y=E),S=F,w=T,F=L,T=E}return sd(e,l,k)}let M=NaN;for(let S=0;S<n.iters&&b-m>n.kappa;S++){let w=y-h,F=Math.abs(w)>1e-12?(m*y-b*h)/w:.5*(m+b);F>m&&F<b||(F=.5*(m+b));let T=Math.abs(u(s*F))-i;if(k=s*F,Math.abs(T)<c&&(R===void 0||Math.abs(F-M)<=R))break;M=F,T<0?(m=F,h=T,y*=.5):(b=F,y=T,h*=.5)}return sd(e,l,k)}function sd(e,t,r){return t.forces!==null&&Object.is(t.kappa,r)?{kappa:r,forces:t.forces}:{kappa:r,forces:e(r===0?0:r)}}var pA=1e-6,jN=40,UN=(3-Math.sqrt(5))/2;function XN(e,t,r,n,o,a,s,i){let c,l,u,d=-Math.abs(a),p,m,f=-Math.abs(n);if(Number.isNaN(s)){c=.3;let g=.3*(1-pA),y=-Math.abs(e(t*g));if(y>=d)return{kappa:o,mag:-d};[l,p,u,m]=[o,d,r,f],o=g,d=y}else{c=s;let g=-Math.abs(i);[l,p,u,m]=g<=f?[c,g,r,f]:[r,f,c,g]}f<d&&([l,p]=[o,d],o=r,d=f);let h=c-r,b=0;for(let g=0;g<jN;g++){let y=pA*Math.abs(o)+1e-10,x=.5*(r+c);if(Math.abs(o-x)<=2*y-.5*(c-r))break;let v=!0;if(Math.abs(h)>y){let M=(o-l)*(d-m),S=(o-u)*(d-p),w=(o-u)*S-(o-l)*M;S=2*(S-M),S>0&&(w=-w),S=Math.abs(S);let F=h;if(h=b,Math.abs(w)<Math.abs(.5*S*F)&&w>S*(r-o)&&w<S*(c-o)){b=w/S;let T=o+b;(T-r<2*y||c-T<2*y)&&(b=x>=o?y:-y),v=!1}}v&&(h=o>=x?r-o:c-o,b=UN*h);let k=Math.abs(b)>=y?o+b:o+(b>=0?y:-y),R=-Math.abs(e(t*k));R<=d?(k>=o?r=o:c=o,u=l,m=p,l=o,p=d,o=k,d=R):(k<o?r=k:c=k,R<=p||l===o?(u=l,m=p,l=k,p=R):(R<=m||u===o||u===l)&&(u=k,m=R))}return{kappa:o,mag:-d}}var cd=e=>Math.max(2,.003*Math.abs(e)),qN=(e,t)=>Math.max(t.abs,t.rel*Math.abs(e)),i0=.5,QN=.03;function ZN(e,t,r,n,o,a=!1){let s=JN(e,t,r,n,o,a);return{kappaM:s.kappaM,kl:s.kl,kr:s.kr,fl:e.at(s.kl),fr:t.at(s.kr)}}function JN(e,t,r,n,o,a){let s=.5*(e.vx+t.vx),i=e.fxAt??(w=>e.at(w).Fx),c=t.fxAt??(w=>t.at(w).Fx),l=w=>{let F=(1+w)*s/e.vx-1,T=(1+w)*s/t.vx-1;return{kappaM:w,kl:F,kr:T,g:i(F)+c(T)-r}},u=qN(r,o),d=Math.max(-i0,Math.min(i0,n)),p=l(d);if(Math.abs(d)>QN){let w=l(.8*d);(p.g-w.g)/(d-w.kappaM)>0||(p=l(0))}if(Math.abs(p.g)<u)return p;let m=p.g<0?1:-1,f=p,h=p,b=.004,g=p,y=p;for(let w=0;w<12;w++){let F=f.kappaM+m*b;if(Math.abs(F)>i0)break;let T=l(F);if(Math.abs(T.g)<u)return T;if(Math.abs(T.g)<Math.abs(g.g)&&(g=T),Math.sign(T.g)!==Math.sign(f.g)){h=T;break}if(m*(T.g-f.g)<=0){if(!a)return g;let A=(Math.sqrt(5)-1)/2,C=y.kappaM,P=T.kappaM,L=l(P-A*(P-C)),E=l(C+A*(P-C));for(let D=0;D<40&&Math.abs(P-C)>1e-7;D++)m*(L.g-E.g)<0?(C=L.kappaM,L=E,E=l(C+A*(P-C))):(P=E.kappaM,E=L,L=l(P-A*(P-C)));let _=m*(L.g-E.g)>0?L:E;if(Math.abs(_.g)<u||Math.sign(_.g)===Math.sign(p.g))return Math.abs(_.g)<Math.abs(g.g)?_:g;f=m*(_.kappaM-f.kappaM)>0?f:y,h=_;break}y=f,f=T,b*=1.9}if(h===p)return g;let x=f,v=h,k=x.g,R=v.g,M=Math.abs(k)<Math.abs(R)?x:v,S=Math.min(1e-7,o.kappa);for(let w=0;w<30&&Math.abs(v.kappaM-x.kappaM)>S;w++){let F=R-k,T=Math.abs(F)>1e-12?(x.kappaM*R-v.kappaM*k)/F:.5*(x.kappaM+v.kappaM),A=Math.min(x.kappaM,v.kappaM),C=Math.max(x.kappaM,v.kappaM);T>A&&T<C||(T=.5*(A+C));let P=l(T);if(M=P,Math.abs(P.g)<u)break;Math.sign(P.g)===Math.sign(k)?(x=P,k=P.g,R*=.5):(v=P,R=P.g,k*=.5)}return M}function fA(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 jc(e,t,r,n,o,a=$s,s=!1){let i=ZN(e,t,r,o,a,s),c=i.fr.Fx-i.fl.Fx,l=na(n,r);if(Math.abs(c)<=l){let v=r-(i.fl.Fx+i.fr.Fx),k=Math.max(0,Math.abs(v)-cd(r))/2;return{left:{kappa:i.kl,forces:i.fl,want:i.fl.Fx+v/2,short:k},right:{kappa:i.kr,forces:i.fr,want:i.fr.Fx+v/2,short:k},locked:!0,spoolKappa:i.kappaM}}let u=Math.sign(c),d=r/2-u*l/2,p=r/2+u*l/2,m=vo(e.at,d,e.seed||i.kl,a,e.fxAt),f=vo(t.at,p,t.seed||i.kr,a,t.fxAt),h=Math.abs(d-m.forces.Fx)>cd(d),b=Math.abs(p-f.forces.Fx)>cd(p),g=Math.max(0,n.preloadN),y=ed(n.tbr);h&&!b?f=vo(t.at,fA(m.forces.Fx,u,g,y),f.kappa,a,t.fxAt):b&&!h&&(m=vo(e.at,fA(f.forces.Fx,-u,g,y),m.kappa,a,e.fxAt));let x=(v,k)=>({kappa:v.kappa,forces:v.forces,want:k,short:Math.max(0,Math.abs(k-v.forces.Fx)-cd(k))});return{left:x(m,d),right:x(f,p),locked:!1,spoolKappa:i.kappaM}}var eO={front:["FL","FR"],rear:["RL","RR"]},tO=Object.freeze({Fx:0,Fy:0,Mz:0});function ld(e,t,r,n){let o=r;for(let a of["front","rear"]){let[s,i]=eO[a],c=r[s]+r[i],l=mr(e,a,c);if(!l||!(na(l,c)>0))continue;let u=we(t,a),d=n.alpha[a],p=(a==="front"?e.trackFront:e.trackRear)/2e3,m=n.grip??1,f=x=>v=>u.forces({Fz:x,kappa:v,alpha:d,gamma:0}),h=x=>v=>{let k=u.forces({Fz:x,kappa:v,alpha:d,gamma:0});return{Fx:m*k.Fx,Fy:m*k.Fy,Mz:m*k.Mz}},b=nn(u),g=(x,v)=>{let k=Math.max(0,n.Fz[x]);return{at:k>0?m===1?f(k):h(k):()=>tO,fxAt:k>0?m===1?R=>b(k,R,d,0):R=>m*b(k,R,d,0):()=>0,vx:Math.max(.05,1-v*n.curvature),seed:0}},y=jc(g(s,p),g(i,-p),c,l,n.seed?.[a]??0);n.seed&&(n.seed[a]=y.spoolKappa),o===r&&(o={...r}),o[s]=y.left.want,o[i]=y.right.want}return o}var aa=["FL","FR","RL","RR"];function c0(e,t,r,n={}){let o={FL:0,FR:0,RL:0,RR:0},a={FL:!1,FR:!1,RL:!1,RR:!1},s={FL:!1,FR:!1,RL:!1,RR:!1};if(t===0&&!e.tvRearDiffN)return{want:o,held:a,left:0,atTop:s};let i=t>=0?1:-1,c=Math.abs(t),l={FL:0,FR:0,RL:0,RR:0},u={FL:1/0,FR:1/0,RL:1/0,RR:1/0};if(i>0){let f=["front","rear"].filter(h=>e.drive[h]);for(let h of f){let[b,g]=h==="front"?["FL","FR"]:["RL","RR"],y=e.drive[h],x=r[b]+r[g];y==="ideal"?(l[b]=r[b],l[g]=r[g],a[b]=a[g]=!0):l[b]=l[g]=x/2}for(let h of aa){let b=e.motorCap?.[h];b!==void 0&&(u[h]=Math.max(0,b))}}else if(e.brake.kind==="ideal")for(let f of aa)l[f]=r[f],a[f]=!0;else{let f=Math.min(1,Math.max(0,e.brake.front));l.FL=l.FR=f/2,l.RL=l.RR=(1-f)/2;for(let h of aa)a[h]=e.brake.abs;if(e.brake.abs){let h=Math.min(1,Math.max(0,e.brake.absUse??.9));if(h<1)for(let b of aa)u[b]=h*r[b]}}let d=Math.max(-1,Math.min(1,e.idealShift??0));if(d!==0){let f={front:i>0?e.drive.front==="ideal":e.brake.kind==="ideal",rear:i>0?e.drive.rear==="ideal":e.brake.kind==="ideal"};for(let h of["front","rear"]){if(!f[h])continue;let[b,g]=h==="front"?["FL","FR"]:["RL","RR"],[y,x]=(e.turn??1)>0?[b,g]:[g,b],[v,k]=d>0?[y,x]:[x,y],R=Math.abs(d)*l[v];l[v]-=R,l[k]+=R}}for(let f of aa){let h=n[f];a[f]&&h!==void 0&&(u[f]=Math.min(u[f],Math.max(0,h)))}let p=rO(c,l,u);for(let f of aa)o[f]=i*p.each[f],s[f]=l[f]>0&&Number.isFinite(u[f])&&p.each[f]>=u[f];let m=e.tvRearDiffN??0;return m&&(o.RL-=m/2,o.RR+=m/2),{want:o,held:a,left:p.left,atTop:s}}function rO(e,t,r){let n={FL:0,FR:0,RL:0,RR:0},o=aa.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((d,p)=>d+t[p],0),l=a/c,u=s.filter(d=>l*t[d]>=r[d]);if(u.length===0){for(let d of s)n[d]=l*t[d];a=0,s=[];break}for(let d of u)n[d]=r[d],a-=r[d];s=s.filter(d=>!u.includes(d))}return{each:n,left:Math.max(0,a)}}var Le=9.81,he=Math.PI/180,nO=8,oO=.02,aO=12,hA=e=>10*Math.max(Gs.abs,Gs.rel*Math.abs(e)),bA=1e-6,Wt=["FL","FR","RL","RR"],_t=e=>e==="FL"||e==="FR",zn=e=>_t(e)?"front":"rear";function Hs(e,t){let r=we(e,"front"),n=we(e,"rear");return r===n?ia(r,t):{front:ia(r,t),rear:ia(n,t)}}function ia(e,t){return eg(e,Math.min(t,Or(e)))}var Uc=e=>e==="FL"||e==="RL",gA=new WeakMap;function sO(e,t){let r=gA.get(e);r||gA.set(e,r=new Map);let n=100*Math.ceil(2*t*Le/100),o=r.get(n);if(!o){let a=Hs(e,n);o="front"in a?a:{front:a,rear:a},r.set(n,o)}return o}function zs(e,t,r=0,n,o=0,a=1){let s=t?.axG??0;if(t?.balance)return{axG:Number.isFinite(s)?s:0,fx:{FL:0,FR:0,RL:0,RR:0},balance:t.balance};let i=Number.isFinite(t?.tvRearDiffN)?t?.tvRearDiffN:0;if(!(!!s&&Number.isFinite(s))&&!i)return null;let l=e.massTotal*s*Le,u=s>=0?Math.min(1,Math.max(0,t?.driveFrontFrac??0)):Math.min(.99,Math.max(.01,Bs(e,s,r,n,o,a))),d=l*u/2,p=l*(1-u)/2;return{axG:s,fx:{FL:d,FR:d,RL:p-i/2,RR:p+i/2}}}function h0(e,t,r,n){return Math.abs(ca(e,t,r,n!==void 0?{steerMaxDeg:n}:{}).peak.steerDeg)}function b0(e,t,r,n){let o=e.tv;if(!o?.enabled)return 0;let a=VA(o)(t,Math.abs(r),n);return r<0?-a:a}function g0(e,t,r=0,n,o=0,a=0,s,i=1){let c=zs(e,{axG:t,driveFrontFrac:a},r,n,o,i),l=c?c.fx:{FL:0,FR:0,RL:0,RR:0};return c&&s&&n?ld(e,n,l,s):l}var qc=e=>Uc(e)?-1:1,md=(e,t,r,n,o)=>t*e.Fy(t*r,n,t*o);function p0(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 iO(e,t,r){let n=Math.abs(t),o=e.steerFront;if(o&&o.meanDeg.length>1){let u=t>=0,d=r&&o.travelSurface?ks(o,n/he,u?r.FL:r.FR,u?r.FR:r.FL):Ms(o,n/he);return{innerMag:d.innerDeg*he,outerMag:d.outerDeg*he,innerCamber:d.innerCamber,outerCamber:d.outerCamber,atLock:d.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),d=Math.atan(s/Math.max(.05,u-a/2)),p=Math.atan(s/(u+a/2));c=n+i*(d-n),l=n+i*(p-n)}return{innerMag:c,outerMag:l,innerCamber:0,outerCamber:0,atLock:!1}}function la(e,t,r){let n=(e.toeFrontDeg??0)*he,o=(e.toeRearDeg??0)*he,a=iO(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 dd(e,t,r){if(r.Fz<=0)return 0;let n=zt(we(e,zn(t))),o=qc(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 yA(e,t,r,n){if(!Zo(e))return null;let o=zt(we(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:dd(o,s,i)}}return Mc(e,r/he,a,bo(o.model),{FL:n.FL.travelMm,FR:n.FR.travelMm})}var xA=()=>({totalNm:[],aligningNm:[],lateralNm:[],longitudinalNm:[],jackingNm:[]});function RA(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 cO=Object.freeze({Fx:0,Fy:0,Mz:0});function vA(e,t,r){let n=t==="front"?(r?.FL??0)+(r?.FR??0):(r?.RL??0)+(r?.RR??0),o=mr(e,t,n);return o&&na(o,n)>0?{F:n,law:o}:null}function dr(e,t,r,n,o,a,s,i,c,l){let u=s?.fx,d=s?.axG??0,{wb:p,lf:m,lr:f,m:h}=p0(e),b=vA(e,"front",u),g=vA(e,"rear",u),y=l?.spool??{front:0,rear:0},x=i!==void 0&&i>0&&Number.isFinite(i)?i:null,v=te=>x===null?r:Math.sqrt(Math.max(0,te)*x),k=zt(we(t,"front")),R=zt(we(t,"rear")),M=nn(k),S=nn(R),w=e.trackFront/2e3,F=e.trackRear/2e3,T=!!(e.kinFront&&e.kinRear),A=T&&x===null?l?.travel??yo(e,e.kinFront,e.kinRear,r):null;l&&A&&(l.travel=A);let C=NaN,P=null,L=te=>{if(!T)return null;if(x===null)return A;let ae=v(te);return ae!==C&&(C=ae,P=yo(e,e.kinFront,e.kinRear,ae)),P},E={},_=l?.kap??{FL:0,FR:0,RL:0,RR:0},D=e.kinFront?.compliance,I=e.kinRear?.compliance,V=!!(D||I),O=!!(D?.toePerMz||I?.toePerMz),B=te=>_t(te)?D:I,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}},j=!1,$=s?.balance,N=0,W=0,Z=0,q=$?sO(t,h):null,Y=(te,ae)=>ae>0&&q?q[zn(te)].muX(ae)*ae:0,K=te=>{let ae=te/r,Ce=x===null?n+m*ae/r:n+m/x,pe=x===null?n-f*ae/r:n-f/x,me=L(te),xe=v(te),ge=$!==void 0,ke=ge?te/Le*Math.cos(n)+d*Math.sin(n):te/Le,Re=ge?d*Math.cos(n)-te/Le*Math.sin(n):d,ye=me?me(ke,Re,n/he,o/he):null,Me=ye?{FL:ye.FL.travel,FR:ye.FR.travel}:void 0,fe=lm(e,ke,Re,xe,n/he,o/he,Me,ye?.steeringJacking),be=fe.loads;j=fe.overturned;let Te=la(e,o,Me),Fe=Te.steer,Gt=0,mt=De=>{let Be=Math.max(0,be[De]),gt=qc(De),_e=_t(De)?k:R,Ze=B(De),Tr=0,Xt=0;if(Ze){let Ur=z[De];Tr=Ze.toePerFy*Ur.fy+Ze.toePerFx*Ur.fx+Ze.toePerMz*Ur.mz,Xt=Ze.camberPerFy*Ur.fy+Ze.camberPerFx*Ur.fx}let vt=Fe[De]+(ye?gt*ye[De].bumpToe*he:0)+gt*Tr*he,or=vt-(_t(De)?Ce:pe),At=(ye?ye[De].camberRoad:0)*he+gt*(Te.camber[De]+Xt)*he;return{Fz:Be,mir:gt,t:_e,gains:Ze,complianceToe:Tr,steerK:vt,slip:or,camberRad:At}},Kt=(De,Be)=>{let gt=x===null?ae/r:1/x,_e=_t(De)?m:-f,Ze=(Uc(De)?1:-1)*(_t(De)?w:F),Tr=(Math.cos(n)-Ze*gt)*Math.cos(Be.steerK)+(Math.sin(n)+_e*gt)*Math.sin(Be.steerK),Xt=_t(De)?M:S;return{at:Be.Fz>0?vt=>Be.t.forces({Fz:Be.Fz,kappa:vt,alpha:Be.mir*Be.slip,gamma:Be.mir*Be.camberRad}):()=>cO,fxAt:Be.Fz>0?vt=>Xt(Be.Fz,vt,Be.mir*Be.slip,Be.mir*Be.camberRad):()=>0,vx:Math.max(.05,Tr),seed:_[De]}};if($){let De=h*(d*Le-($.axDrag??0)),Be=0,gt=()=>({FL:mt("FL"),FR:mt("FR"),RL:mt("RL"),RR:mt("RR")}),_e=or=>({FL:Y("FL",or.FL.Fz),FR:Y("FR",or.FR.Fz),RL:Y("RL",or.RL.Fz),RR:Y("RR",or.RR.Fz)}),Ze=V?null:gt(),Tr=Ze?_e(Ze):null,Xt={},vt={};for(let or=0;or<aO;or++){let At=Ze??gt(),Ur=Tr??_e(At),io=De-N,Bo={...$.spec,turn:o<0?-1:1,...io<0&&$.brakeFront&&$.spec.brake.kind==="shares"?{brake:{...$.spec.brake,front:$.brakeFront(io)}}:{}},Ue={},Qe=c0(Bo,io,Ur,Ue),xr={},Mn={},rs={},co=(Ne,Oe)=>Ue[Ne]!==void 0&&Math.abs(Math.abs(Oe)-Ue[Ne])<=1e-9*Math.max(1,Ue[Ne]);for(let Ne=0;Ne<5;Ne++){let Oe=!1;for(let Xe of["front","rear"]){let[$e,it]=Xe==="front"?["FL","FR"]:["RL","RR"],Dr=Qe.want[$e]+Qe.want[it],Eu=mr(e,Xe,Dr);if(Eu&&na(Eu,Dr)>0){let He=Ir=>Math.max(0,Math.abs(Dr-Ir.left.forces.Fx-Ir.right.forces.Fx)-hA(Dr)),Ve=rs[Xe],Er=Ve!==void 0&&co($e,Qe.want[$e])&&co(it,Qe.want[it]),dt=Er?Ve:jc(Kt($e,At[$e]),Kt(it,At[it]),Dr,Eu,y[Xe],id,!0);if(!Er&&He(dt)>0&&(y[Xe]!==0||_[$e]!==0||_[it]!==0)){let Ir=jc({...Kt($e,At[$e]),seed:0},{...Kt(it,At[it]),seed:0},Dr,Eu,0,id,!0);He(Ir)<He(dt)&&(dt=Ir)}y[Xe]=dt.spoolKappa,_[$e]=dt.left.kappa,_[it]=dt.right.kappa;let ns=Qe.held[$e]&&Qe.held[it],os=He(dt);if(ns&&os>0){let Ir=Math.abs(Dr),_r=Math.abs(dt.left.forces.Fx+dt.right.forces.Fx),Gi=Qe.want[$e]*Qe.want[it]>=0&&Ir>0,Ki=Gi?Math.abs(Qe.want[$e])*_r/Ir:Math.abs(dt.left.forces.Fx),hh=Gi?Math.abs(Qe.want[it])*_r/Ir:Math.abs(dt.right.forces.Fx);(Ue[$e]===void 0||Ue[it]===void 0||Ki<Ue[$e]-1e-6||hh<Ue[it]-1e-6)&&(Ue[$e]=Math.min(Ki,Ue[$e]??1/0),Ue[it]=Math.min(hh,Ue[it]??1/0),rs[Xe]=dt,Oe=!0)}xr[$e]={kappa:dt.left.kappa,Fx:dt.left.forces.Fx,Fy:At[$e].mir*dt.left.forces.Fy,short:ns?0:os/2},xr[it]={kappa:dt.right.kappa,Fx:dt.right.forces.Fx,Fy:At[it].mir*dt.right.forces.Fy,short:ns?0:os/2};continue}for(let He of[$e,it]){let Ve=At[He],Er=Qe.want[He];if(Er===0||Ve.Fz<=0){let Sn=Ve.Fz<=0&&!Qe.held[He]?Math.abs(Er):0;Ve.Fz<=0&&Qe.held[He]&&Er!==0&&Ue[He]===void 0&&(Ue[He]=0,Oe=!0);let bh=Ze?Xt[He]??={}:null,dv=Ve.Fz>0?bh?.fy??md(Ve.t,Ve.mir,Ve.slip,Ve.Fz,Ve.camberRad):0;bh&&(bh.fy=dv),xr[He]={kappa:0,Fx:0,Fy:dv,short:Sn};continue}let dt=Sn=>Ve.t.forces({Fz:Ve.Fz,kappa:Sn,alpha:Ve.mir*Ve.slip,gamma:Ve.mir*Ve.camberRad}),ns=_t(He)?M:S,os=Ze?Xt[He]??={}:null,Ir=Sn=>Sn!==0||!os?ns(Ve.Fz,Sn,Ve.mir*Ve.slip,Ve.mir*Ve.camberRad):os.fx??=ns(Ve.Fz,0,Ve.mir*Ve.slip,Ve.mir*Ve.camberRad),_r=(co(He,Er)?Mn[He]:void 0)??vo(dt,Er,_[He],id,Ir,Ze?vt[He]??={}:void 0);_[He]=_r.kappa;let Gi=hA(Er),Ki=Math.abs(Er-_r.forces.Fx);if(Ki>Gi&&Math.abs(_r.forces.Fx)<Math.abs(Er)&&Qe.held[He]){let Sn=Math.abs(_r.forces.Fx);(Ue[He]===void 0||Sn<Ue[He])&&(Ue[He]=Sn,Mn[He]=_r,Oe=!0)}xr[He]={kappa:_r.kappa,Fx:_r.forces.Fx,Fy:Ve.mir*_r.forces.Fy,short:Qe.held[He]?0:Math.max(0,Ki-Gi)}}}if(!Oe)break;Qe=c0(Bo,io,Ur,Ue)}W=0,Z=0;for(let Ne=0;Ne<Wt.length;Ne++)(Ue[Wt[Ne]]!==void 0||Qe.atTop[Wt[Ne]])&&(W|=1<<Ne),Ue[Wt[Ne]]!==void 0&&(Z|=1<<Ne);let Xr=0,Pr=0;Be=0;for(let Ne of Wt){let Oe=At[Ne],Xe=xr[Ne];if(E[Ne]={Fz:Oe.Fz,travelMm:ye?.[Ne].travel??0,steerRad:Oe.steerK,slipRad:Oe.slip,camberRad:Oe.camberRad,Fy:Xe.Fy,Fx:Xe.Fx,kappa:Xe.kappa,fxShort:Xe.short+Qe.left/4,lifted:fe.lifted[Ne]},Oe.gains){let it=O&&Oe.gains.toePerMz?dd(Oe.t,Ne,E[Ne]):0;z[Ne]={fy:-Oe.mir*Xe.Fy,fx:Xe.Fx,mz:-Oe.mir*it*1e3};let Dr=z[Ne];Pr=Math.max(Pr,Math.abs(Oe.gains.toePerFy*Dr.fy+Oe.gains.toePerFx*Dr.fx+Oe.gains.toePerMz*Dr.mz-Oe.complianceToe))}let $e=Oe.steerK-n;Xr+=Xe.Fx*(Math.cos($e)-1)-Xe.Fy*Math.sin($e),Be+=Xe.Fy*Math.cos($e)+Xe.Fx*Math.sin($e)}let Lr=Math.abs(Xr-N);if(N=Xr,Lr<oO&&Pr<bA)break}return Be/h}for(let De=0;De<(V?nO:1);De++){Gt=0;let Be=0,gt={};for(let _e of Wt){let Ze=_t(_e)?b:g;if(Ze&&!gt[_e]){let[Pr,Lr]=_t(_e)?["FL","FR"]:["RL","RR"],Ne=mt(Pr),Oe=mt(Lr),Xe=zn(_e),$e=jc(Kt(Pr,Ne),Kt(Lr,Oe),Ze.F,Ze.law,y[Xe],Gs);y[Xe]=$e.spoolKappa,gt[Pr]={w:Ne,share:$e.left},gt[Lr]={w:Oe,share:$e.right}}let Tr=gt[_e]?.w??mt(_e),{Fz:Xt,mir:vt,t:or,gains:At,complianceToe:Ur,steerK:io,slip:Bo,camberRad:Ue}=Tr,Qe=u?.[_e]??0,xr,Mn=0,rs=0,co=0,Xr=gt[_e]?.share;if(Xr)_[_e]=Xr.kappa,rs=Xr.kappa,Mn=Xr.forces.Fx,co=Xr.short,xr=vt*Xr.forces.Fy;else if(Qe===0||Xt<=0)xr=md(or,vt,Bo,Xt,Ue),co=Xt<=0?Math.abs(Qe):0;else{let Pr=Xe=>or.forces({Fz:Xt,kappa:Xe,alpha:vt*Bo,gamma:vt*Ue}),Lr=_t(_e)?M:S,Ne=Xe=>Lr(Xt,Xe,vt*Bo,vt*Ue),Oe=vo(Pr,Qe,_[_e],Gs,Ne);_[_e]=Oe.kappa,rs=Oe.kappa,Mn=Oe.forces.Fx,co=Math.max(0,Math.abs(Qe-Mn)-Math.max($s.abs,$s.rel*Math.abs(Qe))),xr=vt*Oe.forces.Fy}if(E[_e]={Fz:Xt,travelMm:ye?.[_e].travel??0,steerRad:io,slipRad:Bo,camberRad:Ue,Fy:xr,Fx:Mn,kappa:rs,fxShort:co,lifted:fe.lifted[_e]},At){let Pr=O&&At.toePerMz?dd(or,_e,E[_e]):0;z[_e]={fy:-vt*xr,fx:Mn,mz:-vt*Pr*1e3};let Lr=z[_e];Be=Math.max(Be,Math.abs(At.toePerFy*Lr.fy+At.toePerFx*Lr.fx+At.toePerMz*Lr.mz-Ur))}Gt+=xr*Math.cos(io)+Mn*Math.sin(io)}if(Be<bA)break}return Gt/h},ne=te=>{let ae=We(e,0,d,te,0,o/he);return ae.FL+ae.FR+ae.RL+ae.RR},U=Math.max(20,3.5*ne(r)/h);if(x!==null){U=4*Le;for(let te=0;te<8;te++){let ae=Math.min(40*Le,3.5*ne(v(U))/h);if(ae<=U)break;U=ae}U=Math.max(20,U)}let Q=te=>K(te)-te,se=Math.max(.001,U*1e-4),de=(te,ae,Ce,pe)=>{let me=te,xe=Ce,ge=ae,ke=pe,Re=me;for(let ye=0;ye<40;ye++){let Me=ke-ge,fe=Math.abs(Me)>1e-12?(me*ke-xe*ge)/Me:.5*(me+xe),be=Math.min(me,xe),Te=Math.max(me,xe);fe>be&&fe<Te||(fe=.5*(me+xe));let Fe=Q(fe);if(Re=fe,Math.abs(Fe)<1e-4||Te-be<1e-6)break;Fe<0==ge<0?(me=fe,ge=Fe,ke*=.5):(xe=fe,ke=Fe,ge*=.5)}return Re},ue=(te,ae,Ce,pe=!1)=>{let me=(ye,Me)=>Ce>0?ye>0&&Me<0:Me>0&&ye<0,xe=te,ge=ae,ke=te+Ce*Math.min(Math.abs(ae),U);if(!pe&&Math.abs(ke-te)>se){let ye=Q(ke);if(me(ge,ye))return{root:de(xe,ge,ke,ye),last:xe};xe=ke,ge=ye}let Re=pe?U/24:Math.max(U/24,Math.abs(ke-te)/4);for(let ye=1;ye<=24;ye++){let Me=xe+Ce*Re;if(Math.abs(Me)>U)break;let fe=Q(Me);if(me(ge,fe))return{root:de(xe,ge,Me,fe),last:xe};if(pe&&fe*Ce<0&&(fe-ge)*Ce<0)break;xe=Me,ge=fe}return{root:null,last:xe}},ie=c??null;if(c===void 0&&a!==void 0&&Number.isFinite(a)&&Math.abs(a)<=U){let te=Q(a);if(Math.abs(te)<=1e-4)Q(a+se)<0&&Q(a-se)>0&&(ie=a);else{let ae=ue(a,te,Math.sign(te)).root;ie=ae!==null&&(ae===0||Math.sign(ae)===Math.sign(a))?ae:null}}let ve=ie===null;if(ie===null){let te=Q(0),ae=Q(se),Ce=Math.abs(te)<=1e-4,pe=Ce?x!==null?1:o!==0?Math.sign(o):ae>0?1:-1:Math.sign(te),me=Ce?pe*se:0,xe=Ce?pe>0?ae:Q(-se):te,ge=ue(me,xe,pe);ie=ge.root??(Ce?0:ge.last)}let Ie=K(ie);if(ve&&o!==0&&x===null){let te=Math.sign(o);if(ie*te<=0||(E.RL.Fy+E.RR.Fy)*te<0){let ae={...E},Ce=j,pe=te*Math.max(ie*te+se,n*te*r*r/f),me=null;if(pe*te<U){let xe=Q(pe);if(xe*te>0)me=ue(pe,xe,te).root;else{let ge=pe+te*U/24,ke=Q(ge);(ke-xe)*te>0&&(me=ue(ge,ke,te,ke*te<=0).root)}}me!==null&&me*te>0?(ie=me,Ie=K(ie)):(Object.assign(E,ae),j=Ce)}}let je=m*(E.FL.Fy*Math.cos(E.FL.steerRad)+E.FR.Fy*Math.cos(E.FR.steerRad))-f*(E.RL.Fy+E.RR.Fy);if($){je=0;for(let te of Wt){let ae=E[te],Ce=_t(te)?m:-f,pe=(Uc(te)?1:-1)*(_t(te)?w:F),me=Math.cos(ae.steerRad),xe=Math.sin(ae.steerRad);je+=Ce*(ae.Fy*me+ae.Fx*xe)-pe*(ae.Fx*me-ae.Fy*xe)}}else if(s||b||g){let te=ae=>(Uc(ae)?1:-1)*(_t(ae)?w:F);for(let ae of Wt){let Ce=E[ae],pe=_t(ae)?m:-f;je+=pe*Ce.Fx*Math.sin(Ce.steerRad)-te(ae)*Ce.Fx*Math.cos(Ce.steerRad)}}return l&&(l.held=W,l.ceiling=Z),x!==null&&ie<-1e-6?{ay:NaN,cn:NaN,wheels:E,overturned:j,res:NaN}:{ay:ie/Le,cn:je/(h*Le*p),wheels:E,overturned:j,res:Ie-ie}}function lO(e,t,r,n,o,a,s,i=0){let c=20*he,l=.001,u=(h,b)=>{let g=dr(e,t,r,h,n,b,s);return{cn:g.cn-i,ay:g.ay*Le}},d=h=>n===0||i!==0||Math.abs(h)<.05||Math.sign(h)===Math.sign(n),p=(h,b,g,y)=>{let x=u(h,y);if(Math.abs(x.cn)<1e-5)return{beta:h,trimmed:!0};let v=y===void 0?void 0:x.ay,k={pos:{b:h,cn:x.cn,ay:v},neg:{b:h,cn:x.cn,ay:v}},R=null,M=h,S=Math.abs(x.cn);for(let w=0;w<b.length&&!R;w++)for(let F of[k.pos,k.neg]){let T=F===k.pos?1:-1,A=h+T*b[w];if(Math.abs(A)>c)continue;let C=u(A,F.ay);if(Math.abs(C.cn)<S&&d(C.ay)&&(S=Math.abs(C.cn),M=A),C.cn===0&&d(C.ay))return{beta:A,trimmed:!0};if(C.cn<0!=F.cn<0){let P={lo:F.b,hi:A,ayLo:F.ay},L=kA(u,P),E=u(L,F.ay);if(Math.abs(E.cn)<l&&d(E.ay))return R=P,{beta:L,trimmed:!0}}F.b=A,F.cn=C.cn,y!==void 0&&(F.ay=C.ay)}return R?{beta:kA(u,R),trimmed:!0}:g?{beta:M,trimmed:!1}:null},m=[.25,.75,2,5].map(h=>h*he);if(o!==void 0&&Number.isFinite(o)&&Math.abs(o)<=c){let h=p(o,m,!1,a);if(h)return h;if(!s&&i===0&&a!==void 0&&Number.isFinite(a)){let b=uO(e,t,r,n,o,a,c);if(b&&d(b.ay))return{beta:b.beta,trimmed:!0,ay:b.ay}}}let f=[1,3,7,15,20].map(h=>h*he).filter(h=>h<=c);return p(0,f,!0)??{beta:0,trimmed:!1}}function kA(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 d=e(u,o),p=d.cn;if(o!==void 0&&(o=d.ay),i=u,Math.abs(p)<1e-5||Math.abs(n-r)<1e-5)break;p<0==a<0?(r=u,a=p,s*=.5):(n=u,s=p,a*=.5)}return i}function uO(e,t,r,n,o,a,s){let i=(p,m)=>{let f=dr(e,t,r,p,n,void 0,null,void 0,m);return{r:f.res,c:f.cn}},c=o,l=a,u=i(c,l),d=0;for(let p=0;p<mO;p++){let m=i(c+l0,l),f=i(c,l+u0),h=(m.r-u.r)/l0,b=(f.r-u.r)/u0,g=(m.c-u.c)/l0,y=(f.c-u.c)/u0,x=h*y-b*g;if(!Number.isFinite(x)||x===0||Math.abs(x)<hO*(Math.abs(h*y)+Math.abs(b*g)))return null;if(p===0)d=Math.sign(x);else if(Math.sign(x)!==d)return null;if(Math.abs(u.r)<=1e-4&&Math.abs(u.c)<=1e-5)return{beta:c,ay:l};let v=(u.c*b-u.r*y)/x,k=(u.r*g-u.c*h)/x,R=Math.min(1,dO/Math.max(Math.abs(v),1e-300),pO/Math.max(Math.abs(k),1e-300));if(c+=R*v,l+=R*k,Math.abs(c-o)>fO||Math.abs(c)>s||l*a<0)return null;u=i(c,l)}return null}var mO=8,l0=1e-5,u0=.001,dO=1*he,pO=2,fO=5*he,hO=.5;function TA(e,t,r,n,o,a,s,i){let c=dr(e,t,r,n,o,a,s,void 0,i),l=c.ay*Le/r,u={},d=0;for(let f of Wt){let h=c.wheels[f],b=we(t,zn(f)),g=Or(b),y=b.muY(Math.min(h.Fz,g)),x=b.muX(Math.min(h.Fz,g));d+=h.fxShort,u[f]={Fz:h.Fz,steerDeg:h.steerRad/he,slipDeg:h.slipRad/he,camberDeg:h.camberRad/he,Fy:h.Fy,Fx:h.Fx,Mz:dd(b,f,h),gripUtil:y*h.Fz>0?Math.hypot(h.Fy/(y*h.Fz),x*h.Fz>0?h.Fx/(x*h.Fz):0):0,...h.Fz>g?{pastTurnover:!0}:{},lifted:h.lifted}}let p=Mc(e,o/he,u,bo(we(t,"front").model),{FL:c.wheels.FL.travelMm,FR:c.wheels.FR.travelMm}),m=la(e,o,e.kinFront&&e.kinRear?{FL:c.wheels.FL.travelMm,FR:c.wheels.FR.travelMm}:void 0);return{wheels:u,ay:c.ay,ax:s?.axG??0,beta:n/he,yawRate:l*180/Math.PI,steerDeg:o/he,...m.atLock?{lockDeg:(m.steer.FL+m.steer.FR)/2/he}:{},converged:!0,trimmed:!c.overturned,overturned:c.overturned,driving:!1,fxShortfall:d,...p?{steering:p}:{}}}function Yn(e,t,r,n,o,a,s=0){let i=Math.max(8,r),c=sa(e,t,i,n,o,a,s);return n!==0&&o?.driving===void 0&&(c.driving=PO(e,t,i,c,a,s)),c}function sa(e,t,r,n,o,a,s){let i=n*he,c=zs(e,a,r,t),l=o&&Number.isFinite(o.ay)?o.ay*Le:void 0,u=o&&Number.isFinite(o.beta)?o.beta*he:void 0,{beta:d,trimmed:p,ay:m}=lO(e,t,r,i,u,l,c,s),f=TA(e,t,r,d,i,l,c,m),h={...f,trimmed:p&&!f.overturned};return h.driving=n===0?h.trimmed:o?.driving!==void 0&&o.driving&&h.trimmed&&Math.abs(h.beta-o.beta)<=bO,h}var bO=3;function ca(e,t,r,n={}){let o=Math.max(8,r),a=n.direction??1,s=n.yawDemandCn??0,i=n.steerMaxDeg??gO,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=m0.get(e)?.get(t)?.get(l);if(R)return R}let u=(R,M)=>M.trimmed&&Math.abs(M.beta-R.beta)<=pd&&Math.abs(M.ay-R.ay)*Le<=fd,d=!1,p=(R,M)=>{let S=sa(e,t,o,a*R,M,c(a*R),s);return u(M,S)?(S.driving=!0,S):(d=S.overturned,null)},m=[sa(e,t,o,0,void 0,c(0),s)],f=null,h=!1,b,g=R=>{let M=m.length-1;for(;M>1&&R.sb*(m[M].beta-m[M-1].beta)>=0;)M--;let S=a*(R.state.ay-m[M].ay)>0,w=F=>R.sb*(F.beta-R.state.beta)>0||a*F.steerDeg>=a*R.state.steerDeg||S&&a*F.ay>=a*R.state.ay;for(;m.length>Math.max(2,M)&&w(m[m.length-1]);)m.pop();b={state:R.state,stall:m[m.length-1]},m.push(R.state),f=Math.abs(R.state.steerDeg)},y=(R,M=!1)=>M||CO(m[m.length-1],R)?FO(e,t,o,a,m,R,c,s):null,x=m[0].trimmed?m[0]:null;if(!x){let R=0;for(let M=MA;M<=i&&!x;M+=MA){let S=sa(e,t,o,a*M,void 0,c(a*M),s);if(S.trimmed){let w=M;x=S;for(let F=0;F<6;F++){let T=.5*(R+w),A=sa(e,t,o,a*T,void 0,c(a*T),s);A.trimmed?(w=T,x=A):R=T}}else R=M}x&&(x.driving=!0,m.push(x))}if(x){let R=Math.abs(x.steerDeg),M=Math.min(d0,100/(o*o)),S=x;for(;R<i;){let w=Math.min(i,R+M),F=p(w,S);if(F){let L=y(F);if(L){g(L);break}if(m.push(F),w>=i||OA(e,a*w))break;Math.abs(F.beta-S.beta)<.5*pd&&Math.abs(F.ay-S.ay)*Le<.5*fd&&(M=Math.min(d0,1.5*M)),R=w,S=F;continue}if(M>yO){M*=.5;continue}let T=d,A=!1,C=null;for(let L of xO){let E=Math.min(i,R+L);if(E<=R)continue;let _=p(E,S);if(_){if(C=y(_,!0),C)break;m.push(_),R=E,S=_,M=Math.min(d0,100/(o*o)),A=!0;break}}if(A)continue;if(C){g(C);break}f=R,h=T;let P=T?null:wO(e,t,o,a,m,c,s);P&&g(P);break}}else f=0;let v=m[0];for(let R of m)a*R.ay>a*v.ay&&(v=R);let k={states:m,foldDeg:f,rollover:h,peak:v,...b?{fold:b}:{}};if(l!==null){let R=m0.get(e);R||(R=new WeakMap,m0.set(e,R));let M=R.get(t);M||(M=new Map,R.set(t,M)),M.size>256&&M.clear(),M.set(l,k)}return k}var m0=new WeakMap,gO=90,pd=1.5,fd=2.5,d0=5,yO=.002,xO=[.5,1],MA=2.5,PA=.01,Hn=.001,RO=.05,vO=.25,kO=5,MO=2,SA=1e-8,SO=1e-7,AO=1e-6;function LA(e,t,r,n,o,a,s){let i=n*he,c=o.ay*Le,l=b=>{let g=dr(e,t,r,i,b*he,c,zs(e,a(b),r,t));return{g:g.cn-s,ay:g.ay}},u=o.steerDeg,d=l(u),p=u+(u<0?-.001:.001),m=l(p),f=()=>m.g===0||Math.abs(p-u)<SA;for(let b=0;b<40&&Math.sign(d.g)===Math.sign(m.g)&&!f();b++){let g=(m.g-d.g)/(p-u),y=g!==0?p-m.g/g:p+2*(p-u);if(!Number.isFinite(y))return null;let x=2*Math.abs(p-u)+.001;if(y=p+Math.max(-x,Math.min(x,y-p)),u=p,d=m,p=y,m=l(p),Math.abs(p-o.steerDeg)>MO)return null}let h={x:p,ay:m.ay};if(Math.sign(d.g)!==Math.sign(m.g)){let b=u,g=d.g,y=p,x=m.g;for(let v=0;v<60&&x!==0&&Math.abs(y-b)>SA;v++){let k=(b*x-y*g)/(x-g),R=l(k);if(h={x:k,ay:R.ay},R.g===0)break;Math.sign(R.g)===Math.sign(g)?(b=k,g=R.g,x*=.5):(y=k,x=R.g,g*=.5)}}else if(!f())return null;return Math.abs(h.ay-o.ay)*Le>fd?null:{steerDeg:h.x,ay:h.ay}}function Xc(e,t,r,n,o){let a=TA(e,t,r,n.beta*he,n.steerDeg*he,n.ay*Le,zs(e,o(n.steerDeg),r,t));return{...a,trimmed:!a.overturned,driving:!a.overturned}}function wO(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],d=Math.sign(c.beta-u.beta);if(d===0||!u.driving)return null;let p=DA(e,t,r,a,s),m=p(u.beta,u),f=p(c.beta,c);if(!m||!f)return null;let h=n*f.steerDeg>=n*m.steerDeg,b=h?m:f,g=h?f:m,y=h?d:-d,x=null;for(let R=PA;Math.abs(g.beta-c.beta)<=pd;R*=1.5){let M=p(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 v=EA(p,n,b,g,x);if(!v)return null;let k=Xc(e,t,r,v,a);return!k.trimmed||Math.abs(k.beta-c.beta)>pd||Math.abs(k.ay-c.ay)*Le>fd?null:{state:k,sb:d}}function DA(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=LA(e,t,r,s,i,n,o);if(!c)return null;let l={beta:s,...c};return a.push(l),l}}function CO(e,t){let r=Math.abs(t.beta-e.beta);return r>vO&&r>kO*Math.abs(t.steerDeg-e.steerDeg)}function FO(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 d=o[u],p=Math.sign(a.beta-l.beta);if(p===0||Math.sign(l.beta-d.beta)!==p||!d.driving)return null;let m=DA(e,t,r,s,i),f=m(d.beta,d),h=m(l.beta,l);if(!f||!h||n*h.steerDeg<n*f.steerDeg)return null;let b=f,g=h,y=null;for(let x=PA;p*(a.beta-g.beta)>0;x=Math.min(RO,1.5*x)){let v=m(p*(a.beta-g.beta)>x?g.beta+p*x:a.beta);if(!v)return null;let k=n*v.steerDeg<=n*g.steerDeg;if(!y)k&&(y=[b,g,v]);else if(!k){let R=EA(m,n,...y);if(!R)return null;let M=Xc(e,t,r,R,s);return M.trimmed?{state:M,sb:p}:null}b=g,g=v}return null}function EA(e,t,r,n,o){let a=m=>-t*m.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,d=i-s,p=0;for(let m=0;m<100;m++){let f=.5*(s+i);if(Math.abs(c.beta-f)<=2*Hn-.5*(i-s))break;let h=!0;if(Math.abs(d)>Hn){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 v=d;if(d=p,Math.abs(x)<Math.abs(.5*y*v)&&x>y*(s-c.beta)&&x<y*(i-c.beta)){p=x/y;let k=c.beta+p;(k-s<2*Hn||i-k<2*Hn)&&(p=f>=c.beta?Hn:-Hn),h=!1}}h&&(d=c.beta>=f?s-c.beta:i-c.beta,p=_A*d);let b=e(Math.abs(p)>=Hn?c.beta+p:c.beta+(p>=0?Hn:-Hn));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 y0(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})),d=u[0],p=u[u.length-1],m=l(d),f=l(p);if(m>0||f<0)return null;if(f===0)return Xc(e,t,r,p,i);let h=d;for(let b=0;b<60&&Math.abs(p.beta-d.beta)>1e-9;b++){let g=(d.beta*f-p.beta*m)/(f-m),y=u[0];for(let R of u)Math.abs(R.beta-g)<Math.abs(y.beta-g)&&(y=R);let x=LA(e,t,r,g,y,i,c);if(!x)return null;let v={beta:g,...x};u.push(v),h=v;let k=l(v);if(Math.abs(k)<("steerDeg"in a?SO:AO))break;k<0?(d=v,m=k,f*=.5):(p=v,f=k,m*=.5)}return Xc(e,t,r,h,i)}function TO(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 y0(e,t,r,n.fold,a,{steerDeg:o});let u=typeof a.op=="function"?a.op(o):a.op,d=sa(e,t,r,o,l,u,a.yawDemandCn??0);return d.driving?d:null}function PO(e,t,r,n,o,a){if(!n.trimmed)return!1;let s=n.steerDeg<0?-1:1,{states:i}=ca(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],d=i[Math.min(l+1,i.length-1)],p=Math.abs(d.steerDeg)-Math.abs(u.steerDeg),m=p>0?Math.min(1,Math.max(0,(c-Math.abs(u.steerDeg))/p)):0,f=u.beta+m*(d.beta-u.beta),h=u.ay+m*(d.ay-u.ay);return Math.abs(n.beta-f)<=1&&Math.abs(n.ay-h)<=.05}function ko(e,t,r,n,o){let a=Math.max(8,r),s=n>=0?1:-1,i=Math.abs(n),c=(b,g)=>Yn(e,t,a,s*b,g,o),l=ca(e,t,a,{direction:s,op:o}),{fold:u}=l;if(u&&Math.abs(u.state.steerDeg)<=Ks){if(i>Math.abs(u.state.ay))return wA(e,t,a,s,i,o);if(i>Math.abs(u.stall.ay)){let b=y0(e,t,a,u,{direction:s,op:o},{ayG:i});if(b)return b}}let d=l.states.filter(b=>Math.abs(b.steerDeg)<=Ks),p=d[d.length-1],m=l.states.length>d.length;m&&Math.abs(p.steerDeg)<Ks&&d.push(c(Ks,p));let f=d.findIndex(b=>Math.abs(b.ay)>=i);if(f===0)return Yn(e,t,a,0,void 0,o);if(f>0)return AA(d[f-1],d[f],i,c);let h=IA(d,c,void 0,m||l.foldDeg===null);return h.ay>=i?AA(h.below,h.state,i,c):l.foldDeg!==null&&l.foldDeg<Ks?wA(e,t,a,s,i,o):h.state}var Ks=20;function AA(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 d=0;d<60;d++){let p=a.f===o.f?.5*(o.steer+a.steer):o.steer-o.f*(a.steer-o.steer)/(a.f-o.f),m=n(p,i),f=Math.abs(m.ay)-r;if(Math.abs(f)<u&&(l=m,u=Math.abs(f)),Math.abs(f)<=LO||a.steer-o.steer<=DO)break;f<0?(o={steer:p,f},c===-1&&(a.f*=.5),c=-1):(a={steer:p,f},c===1&&(o.f*=.5),c=1)}return l}var LO=1e-9,DO=1e-7;function IA(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=EO/4,c,l,u,d,p,m,f,h,b=null,g;if(o>0&&o<e.length-1){let R=e[o+1];g=w=>{if(w<s)return t(w,a);let F=t(w,e[o]);return F.ay===e[o].ay?t(w,a):F},c=Math.abs(a.steerDeg),l=Math.abs(R.steerDeg),u=s,d=-Math.abs(e[o].ay);let[M,S]=Math.abs(a.ay)>=Math.abs(R.ay)?[a,R]:[R,a];p=Math.abs(M.steerDeg),m=-Math.abs(M.ay),f=Math.abs(S.steerDeg),h=-Math.abs(S.ay)}else{let R=Math.abs(e[o].lockDeg??e[o].steerDeg),M=R-IO,S=o>0&&n&&M>Math.abs(a.steerDeg)?t(M,a):null;if(!S||Math.abs(S.ay)<=Math.abs(e[o].ay)){let w=t(s,a);return{state:w,below:a,ay:Math.abs(w.ay)}}g=w=>t(w,a),c=Math.abs(a.steerDeg),l=R,u=M,d=-Math.abs(S.ay),b=S,p=R,m=-Math.abs(e[o].ay),f=c,h=-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 S=!0;if(Math.abs(y)>i){let A=(u-p)*(d-h),C=(u-f)*(d-m),P=(u-f)*C-(u-p)*A;C=2*(C-A),C>0&&(P=-P),C=Math.abs(C);let L=y;if(y=x,Math.abs(P)<Math.abs(.5*C*L)&&P>C*(c-u)&&P<C*(l-u)){x=P/C;let E=u+x;(E-c<2*i||l-E<2*i)&&(x=M>=u?i:-i),S=!1}}S&&(y=u>=M?c-u:l-u,x=_A*y);let w=Math.abs(x)>=i?u+x:u+(x>=0?i:-i),F=g(w),T=-Math.abs(F.ay);T<=d?(w>=u?c=u:l=u,f=p,h=m,p=u,m=d,u=w,d=T,b=F):(w<u?c=w:l=w,T<=m||p===u?(f=p,h=m,p=w,m=T):(T<=h||f===u||f===p)&&(f=w,h=T))}let v=b??t(s,a),k=Math.abs(v.steerDeg)>s?e[o]:a;return{state:v,below:k,ay:Math.abs(v.ay)}}var EO=.001,IO=.01,_A=(3-Math.sqrt(5))/2;function wA(e,t,r,n,o,a){let s=l=>Math.abs(Yn(e,t,r,n*l,void 0,a).ay),i=0,c=Ks;if(s(c)<o)return Yn(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 Yn(e,t,r,n*.5*(i+c),void 0,a)}function x0(e,t,r,n,o){let a=ko(e,t,r,n,o);return a.steering?Math.abs(a.steering.totalNm):NaN}function R0(e,t,r,n,o){if(!Zo(e))return NaN;let a=n<0?-1:1,s=Math.abs(n),i=ko(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),d=c+l,p=Yn(e,t,r,a*u,void 0,o),m=Yn(e,t,r,a*d,void 0,o),f=p.steering?Math.abs(p.steering.totalNm):NaN,h=m.steering?Math.abs(m.steering.totalNm):NaN,b=Math.abs(m.ay)-Math.abs(p.ay);if(Number.isFinite(f)&&Number.isFinite(h)&&b>=.01||l===.4&&Number.isFinite(f)&&Number.isFinite(h)&&b>.001)return(h-f)/b}return NaN}function f0(e,t,r,n,o,a,s){let i=Math.max(8,r),c=s!==void 0&&Number.isFinite(s)?s*Le:void 0,l=dr(e,t,i,n*he,o*he,c,zs(e,a,i,t)),u=0;for(let d of Wt)u+=l.wheels[d].fxShort;return{ay:l.ay,cn:l.cn,fxShortfall:u}}function v0(e,t,r,n,o){let a=Math.max(8,r),s=ko(e,t,a,n,o),i=.5,c=f0(e,t,a,s.beta+i,s.steerDeg,o).cn,l=f0(e,t,a,s.beta-i,s.steerDeg,o).cn;return(c-l)/(2*i*he)*e.massTotal*Le*(e.wheelbase/1e3)}function k0(e,t,r,n){let o=Math.max(8,r),{branch:a,opts:s}=_O(e,t,o,n);return NA(e,t,o,a,s)}function _O(e,t,r,n){if(!e.tv?.enabled||n?.balance){let s=n?{op:n}:{};return{branch:ca(e,t,r,s),opts:s}}let o=h0(e,t,r),a={op:s=>{let i=b0(e,r,s,o);return i===0?n:{axG:n?.axG??0,driveFrontFrac:n?.driveFrontFrac,tvRearDiffN:i}}};return{branch:ca(e,t,r,a),opts:a}}function NA(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 Xc(e,t,r,n.peak,a);let i=(l,u)=>sa(e,t,r,l,u,a(l),s),c=n.states[0].driving||!n.peak.driving?n.states:n.states.slice(1);return IA(c,i,c.indexOf(n.peak),n.foldDeg===null).state}function M0(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(Le*o)),s=(n.betaMaxDeg??10)*he,i=(n.deltaMaxDeg??10)*he,[c,l]=n.betaRangeDeg?[n.betaRangeDeg[0]*he,n.betaRangeDeg[1]*he]:[-s,s],[u,d]=n.deltaRangeDeg?[n.deltaRangeDeg[0]*he,n.deltaRangeDeg[1]*he]:[-i,i],{lf:p,lr:m}=p0(e),f=o===void 0?0:m/o,h=o===void 0?0:(p+m)/o,b=n.nLines??9,g=n.nPts??21,y=n.steering!==!1&&Zo(e),x=y?bo(we(t,"front").model):void 0,v=(O,B,z,j)=>z===1?O:O+(B-O)*j/(z-1),k=e.tv?.enabled?h0(e,t,a):0,R=O=>{let B=b0(e,a,O/he,k);return!n.axG&&B===0?null:zs(e,{axG:n.axG??0,driveFrontFrac:n.driveFrontFrac,tvRearDiffN:B},a,t)},{lf:M,lr:S}=p0(e),w=n.reserves?Hs(t,e.massTotal*Le*1.2):null,F=O=>w?Dn(w,{FL:O.FL,FR:O.FR,RL:O.RL,RR:O.RR},{lf:M,lr:S}):null,T=[],A={ay:[],cn:[]},C=0;for(let O=0;O<b;O++){let B=v(u,d,b,O),z=R(B),j=[],$=[],N=[],W=[],Z=w?{stabil:[],agil:[]}:void 0,q=y?xA():void 0,Y;for(let U=0;U<g;U++){let Q=v(c,l,g,U),se=dr(e,t,a,Q,B,Y,z,o);if(Y=Number.isFinite(se.ay)?se.ay*Le:void 0,j.push(se.ay),$.push(se.cn),N.push(Q/he),W.push(B/he),Z){let de=F(se.wheels);Z.stabil.push(de.stabil),Z.agil.push(de.agil)}q&&RA(q,yA(e,t,B,se.wheels)),Math.abs(se.ay)>C&&(C=Math.abs(se.ay))}T.push({label:`\u03B4 ${(B/he).toFixed(0)}\xB0`,ay:j,cn:$,betaDeg:N,deltaDeg:W,reserve:Z,steering:q});let K=null,ne=1/0;for(let U=1;U<$.length;U++){if(!Number.isFinite($[U-1])||!Number.isFinite($[U])||$[U-1]!==0&&$[U-1]<0==$[U]<0)continue;let Q=$[U-1]===$[U]?0:$[U-1]/($[U-1]-$[U]),se=j[U-1]+Q*(j[U]-j[U-1]);if(o===void 0&&B!==0&&Math.abs(se)>=.05&&Math.sign(se)!==Math.sign(B))continue;let de=Math.abs(N[U-1]+Q*(N[U]-N[U-1])-f/he);de<ne&&(ne=de,K=se)}K!==null&&(A.ay.push(K),A.cn.push(0))}let P=[];for(let O=0;O<b;O++){let B=v(c,l,b,O),z=[],j=[],$=[],N=[],W=w?{stabil:[],agil:[]}:void 0,Z=y?xA():void 0,q;for(let Y=0;Y<g;Y++){let K=v(u,d,g,Y),ne=dr(e,t,a,B,K,q,R(K),o);if(q=Number.isFinite(ne.ay)?ne.ay*Le:void 0,z.push(ne.ay),j.push(ne.cn),$.push(B/he),N.push(K/he),W){let U=F(ne.wheels);W.stabil.push(U.stabil),W.agil.push(U.agil)}Z&&RA(Z,yA(e,t,K,ne.wheels))}P.push({label:`\u03B2 ${(B/he).toFixed(0)}\xB0`,ay:z,cn:j,betaDeg:$,deltaDeg:N,reserve:W,steering:Z})}let L=.5*he,E=R(h),_,D;if(o===void 0)_=(dr(e,t,a,f+L,h,void 0,E,o).cn-dr(e,t,a,f-L,h,void 0,E,o).cn)/(2*L),D=(dr(e,t,a,f,h+L,void 0,R(h+L),o).cn-dr(e,t,a,f,h-L,void 0,R(h-L),o).cn)/(2*L);else{let O=(j,$)=>dr(e,t,a,j,$,void 0,R($),o).cn,B=(j,$,N)=>Number.isFinite(j)?(-3*j+4*$-N)/(2*L):(N-$)/L,z=O(f,h);_=-B(z,O(f-L,h),O(f-2*L,h)),D=B(z,O(f,h+L),O(f,h+2*L))}let I=0;if(E&&E.axG){let O=dr(e,t,a,f,h,void 0,E,o),B=0;for(let z of Wt)B+=O.wheels[z].fxShort;I=B/Math.abs(e.massTotal*E.axG*Le)}let V=A.ay.reduce((O,B)=>Math.max(O,Math.abs(B)),0);return{isoBeta:P,isoDelta:T,trim:A,maxAy:C,stability:_,control:D,speed:o===void 0?a:Math.sqrt(V*Le*o),...o!==void 0?{radius:o}:{},axG:E?.axG??0,axShortfall:I,...x?{steeringAligningSource:x}:{}}}function OA(e,t){return la(e,t*he).atLock}function NO(e,t,r,n,o=Kn(e,t,r)){let a=r,s=e.massTotal,i=Wt.filter(g=>_t(g)?n.drivenFront:n.drivenRear),c=o.peakAt,l={front:n.drivenFront?mr(e,"front",1):void 0,rear:n.drivenRear?mr(e,"rear",1):void 0},u=new Map,d=(g,y)=>{let x=`${g}:${y}`,v=u.get(x);if(v===void 0){let k=Math.max(1,y*Yc);v=cr(we(t,g),k,0,!1,c(g,k)),u.set(x,v)}return v},p=(g,y)=>y>0?zc(y,x=>d(g,x)):0,m=(g,y,x,v)=>{let k=we(t,g),R=E=>{let _=Math.max(0,x[E]),D=c(g,_);return{Fz:_,a:p(g,_),b:D.fyPeak,slide:0,cap:I=>_>0?cr(k,_,I,!1,D):0}},[M,S]=g==="front"?["FL","FR"]:["RL","RR"],w=R(M),F=R(S),T=v[M]*w.b,A=v[S]*F.b,C=w.cap(T)+F.cap(A),P=Hc(w,F,T+A,y,C);return{l:M,r:S,full:P,asHeld:()=>({axle:g,strong:w.cap(T)>=F.cap(A)?M:S,full:P,open:Hc(w,F,T+A,Vs,C),sense:1})}},f=g=>({muX:y=>y>0?p(g,y)/y:0,muY:y=>y>0?c(g,y).fyPeak/y:0}),h={front:f("front"),rear:f("rear")},b=g=>({arms:{lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},halfTrack:{front:e.trackFront/2e3,rear:e.trackRear/2e3},ayDir:Math.sign(g)});return{limitAt:(g,y,x,v=0)=>{let k={FL:0,FR:0,RL:0,RR:0},R=We(e,g,0,a,0,y),M,S=I=>(M?.ax!==I&&(M={ax:I,loads:We(e,g,(I+v)/Le,a,0,y)}),M.loads),w=dm(I=>ws(x,S(I),R,c).short,-v,1),F=x,T={FL:0,FR:0,RL:0,RR:0},A,C=I=>{let V=w.at(I);k=S(V),F=ws(x,k,R,c).util;let O={FL:0,FR:0,RL:0,RR:0};T=O;let B=0,z=n.diffYaw?{fx:{FL:0,FR:0,RL:0,RR:0},axles:[]}:null;for(let j of i){let $=l[zn(j)];if($){if(Uc(j)){let q=m(zn(j),$,k,F);B+=q.full,O[q.l]=O[q.r]=q.full/2,z&&(z.fx[q.l]=z.fx[q.r]=q.full/2,z.axles.push(q.asHeld()))}continue}let N=Math.max(0,k[j]),W=c(zn(j),N),Z=cr(we(t,zn(j)),N,F[j]*W.fyPeak,!1,W);B+=Z,O[j]=Z,z&&(z.fx[j]=Z)}if(z){let j={};for(let $ of Wt){let N=Math.max(0,k[$]);j[$]={Fz:N,Fy:F[$]*c(zn($),N).fyPeak,Fx:z.fx[$]}}for(let $ of z.axles){let N=Em($,j,h,b(g))-$.full;B+=N;let[W,Z]=$.axle==="front"?["FL","FR"]:["RL","RR"];O[W]+=N/2,O[Z]+=N/2}}if(A)for(let j of A){let $=0;for(let N of j.wheels)$+=O[N];$>j.cap&&(B-=$-j.cap)}return B/s},P=()=>{let I=JS(C,-v,Ro).fx,V=w.edge();return V!==void 0&&I>V&&(I=V,C(I)),{ax:I,loads:k,wheels:T}},L=P(),E=n.motorCaps;if(!E)return L;if(!E.some(I=>I.wheels.reduce((V,O)=>V+L.wheels[O],0)>I.cap))return{...L,held:L.ax};A=E;let D=P();return{...L,held:D.ax,heldWheels:D.wheels}}}}var ud=.05,CA=.001,FA=16,hd=8;function S0(e,t,r,n){let o=Math.max(hd,r),a=n.nSteer??7,s=e.tv?.enabled?h0(e,t,o,n.steerMaxDeg):0,i=N=>{let W=b0(e,o,N,s);return W===0?void 0:{axG:0,tvRearDiffN:W}},c=n.yawDemandCn??0,l={op:i,yawDemandCn:c,...n.steerMaxDeg!==void 0?{steerMaxDeg:n.steerMaxDeg}:{}},u=ca(e,t,o,l),d=N=>{let W={},Z={};for(let q of Wt)W[q]=N.wheels[q].slipDeg*he,Z[q]=Math.min(1,N.wheels[q].gripUtil);return{steerDeg:N.steerDeg,ayMs:Math.max(0,N.ay*Le),ayG:N.ay,slip:W,util:Z,scrub:N.ay>0?OO(N,e.massTotal):0}},p=null,m=N=>{if(p&&N===p.steerDeg)return d(p);let W=TO(e,t,o,u,N,l);if(W)return d(W);let Z=u.states[0];for(let q of u.states)q.steerDeg<=N&&(Z=q);return d(Z)},f=u.peak.driving&&u.peak.ay>0?NA(e,t,o,u,l):null,h=f?Math.max(0,f.ay*Le):0,b=f?[...u.states.filter(N=>N.steerDeg<f.steerDeg),f]:u.states,g=f?b.findIndex(N=>N.ay*Le>=.995*h):0,y=b[g].steerDeg,{fold:x}=u;if(f&&x&&u.peak===x.state){let N=.995*h/Le,W=u.states.indexOf(x.stall),Z=W-1;for(;Z>0&&u.states[Z].beta===x.stall.beta;)Z--;let q=Math.sign(x.stall.beta-u.states[Z].beta),Y=W;for(;Y>0&&u.states[Y].ay>=N&&Math.sign(u.states[Y].beta-u.states[Y-1].beta)!==-q;)Y--;u.states[Y].ay<N&&(p=y0(e,t,o,x,l,{ayG:N},u.states.slice(Y,W+1)))}if(p)y=p.steerDeg;else if(g>0){let N=b[g-1].steerDeg,W=y;for(let Z=0;Z<8&&W-N>.001;Z++){let q=.5*(N+W);m(q).ayMs>=.995*h?W=q:N=q}y=W}let v=[];for(let N=0;N<(h>0?a:1);N++){let W=N/(a-1);v.push(m(y*(W+Math.sin(Math.PI/2*W))/2))}v[0].ayMs=0;let k=[],R=[],M=[],S=[],w=[],F=Kn(e,t,o,void 0,n.diffYaw===!0),T=NO(e,t,o,n,F),A=n.axDrag??0,C=N=>{let W=F.limitAt(N.ayMs/Le,N.steerDeg,N.util,A+N.scrub);return{axD:W.edge!==void 0&&W.edge>0?W.edge:W.ax,locked:W.axUnlocked-W.ax>ud}},P=N=>{let W=T.limitAt(N.ayMs/Le,N.steerDeg,N.util,A+N.scrub);return{axA:W.ax,wA:{wheels:W.wheels,held:W.held??W.ax,...W.heldWheels?{heldWheels:W.heldWheels}:{}}}},L=v.map(N=>({p:N,...P(N),...C(N)})),E=[];for(let N=0;N+1<L.length;N++){let W=L[N],Z=L[N+1],q=[];W.locked!==Z.locked?q.push({read:C,past:Y=>Y.locked===Z.locked,braking:!0}):(Z.axA>W.axA+ud&&q.push({read:P,past:Y=>(Y.axA??-1/0)>W.axA}),-Z.axD>-W.axD+ud&&q.push({read:C,past:Y=>-(Y.axD??0)>-W.axD}));for(let{read:Y,past:K,braking:ne}of q){let U=W.p.steerDeg,Q=Z.p.steerDeg,se=null,de=W.axD,ue=Z.axD;for(let ie=0;ie<FA&&Q-U>CA&&!(ne&&Math.abs(ue-de)<=ud);ie++){let ve=.5*(U+Q),Ie=m(ve),je=Y(Ie);K(je)?(Q=ve,se={p:Ie,r:je},ue=je.axD??ue):(U=ve,de=je.axD??de)}if(se){let{p:ie,r:ve}=se,Ie=ve.axD!==void 0&&ve.locked!==void 0?{axD:ve.axD,locked:ve.locked}:C(ie),je=ve.axA!==void 0&&ve.wA!==void 0?{axA:ve.axA,wA:ve.wA}:P(ie);E.push({p:ie,...je,...Ie})}}}L.push(...E),L.sort((N,W)=>N.p.steerDeg-W.p.steerDeg);let _=N=>N.axA+A+N.p.scrub,D=.001*Math.max(1,v[v.length-1].ayMs),I=[];for(let N=0;N+1<L.length;N++){let W=L[N],Z=L[N+1];if(!(_(W)>=0&&_(Z)<0))continue;let q=W.p.steerDeg,Y=Z.p.steerDeg,K=null,ne=null;for(let se=0;se<FA&&Y-q>CA;se++){let de=.5*(q+Y),ue=m(de),ie=P(ue);_({p:ue,axA:ie.axA})>=0?(q=de,K={p:ue,wA:ie.wA}):(Y=de,ne={p:ue,wA:ie.wA})}let U=K??ne,Q=U?.p;if(U&&Q&&Q.ayMs>W.p.ayMs&&Q.ayMs<Z.p.ayMs){let se=-(A+Q.scrub);I.push({p:Q,axA:se,wA:{wheels:U.wA.wheels,held:Math.min(U.wA.held,se)},steady:!0,...C(Q)})}}L.push(...I),L.sort((N,W)=>N.p.steerDeg-W.p.steerDeg);let V=!1;for(let{p:N,axA:W,wA:Z,axD:q,steady:Y}of L){let K=k.length-1,ne=K>=0&&(Y||V?!(N.ayMs>k[K]):N.ayMs-k[K]<D);V=Y===!0&&!ne,ne?(W>R[K]&&(M[K]=Z),R[K]=Math.max(R[K],W),S[K]=Math.min(S[K],q)):(k.push(N.ayMs),R.push(W),M.push(Z),S.push(q),w.push(N.scrub))}for(let N=k.length-2;N>=0;N--)R[N+1]>R[N]&&(M[N]=M[N+1]),R[N]=Math.max(R[N],R[N+1]),S[N]=Math.min(S[N],S[N+1]);let O=k[k.length-1],B=e.massTotal,z=M.map(({wheels:N})=>({FL:N.FL/B,FR:N.FR/B,RL:N.RL/B,RR:N.RR/B})),j=N=>N?{FL:N.FL/B,FR:N.FR/B,RL:N.RL/B,RR:N.RR/B}:void 0,$=n.motorCaps?{axAccelHeld:M.map(N=>N.held),axAccelWheelsHeld:M.map(N=>j(N.heldWheels))}:{};return{ayMax:O,ay:k,axAccel:R,axAccelWheels:z,...$,axDecel:S,axScrub:w,rollover:u.rollover,atLock:f!==null&&OA(e,f.steerDeg)}}function OO(e,t){let r=e.beta*he,n=0;for(let o of Wt){let a=e.wheels[o],s=a.steerDeg*he-r;n+=a.Fx*(Math.cos(s)-1)-a.Fy*Math.sin(s)}return n/t}var XJ=Math.PI/180,qJ={speeds:Array.from({length:23},(e,t)=>8+t),steerMaxDeg:14,steerSteps:29};function BA(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 Ys={enabled:!1,kp:3e3,ffLow:150,ffHigh:300,vLow:18,vHigh:25},VA=e=>BA(e.ffLow,e.ffHigh,e.vLow,e.vHigh);var cn={power_limit_kw:{value:0,label:"battery power limit (0 = none)",unit:"kW"},v_limit_endurance:{value:0,label:"endurance speed limit (0 = none)",unit:"km/h"},endurance_reserve:{value:0,label:"endurance energy reserve (0 = flat out)",unit:"%"},grip_scale:{value:1,label:"grip scale (rig \u2192 road)",unit:"-"},stiffness_scale:{value:1,label:"stiffness scale (rig \u2192 road)",unit:"-"},camber_front_deg:{value:0,label:"static camber front (\u2212 top in)",unit:"\xB0"},camber_rear_deg:{value:0,label:"static camber rear (\u2212 top in)",unit:"\xB0"},cg_height:{value:300,label:"CG height",unit:"mm"},tire_vertical_rate:{value:100,label:"tyre vertical rate",unit:"N/mm"},tire_vertical_damping:{value:0,label:"tyre vertical damping",unit:"N\xB7s/mm"},arb_front:{value:20,label:"ARB front (@wheel)",unit:"N/mm"},arb_rear:{value:15,label:"ARB rear (@wheel)",unit:"N/mm"},heave_spring_front:{value:0,label:"Heave spring front (@wheel)",unit:"N/mm"},heave_spring_rear:{value:0,label:"Heave spring rear (@wheel)",unit:"N/mm"},unsprung_mass:{value:8,label:"unsprung mass/corner",unit:"kg"},brake_balance:{value:.6,label:"brake balance (front)",unit:"-"},damper_front:{value:2.5,label:"damper front",unit:"N\xB7s/mm"},damper_rear:{value:2.5,label:"damper rear",unit:"N\xB7s/mm"},cop_long:{value:.5,label:"CoP aft of front",unit:"\xB7wb"},cop_height:{value:300,label:"CoP height",unit:"mm"},ride_height_front:{value:30,label:"static ride height front (laden)",unit:"mm"},ride_height_rear:{value:35,label:"static ride height rear (laden)",unit:"mm"},I_yaw:{value:295,label:"yaw inertia Izz",unit:"kg\xB7m\xB2"},I_roll:{value:95,label:"roll inertia Ixx",unit:"kg\xB7m\xB2"},I_pitch:{value:380,label:"pitch inertia Iyy",unit:"kg\xB7m\xB2"},chassis_torsion:{value:0,label:"chassis torsional stiffness (0 = rigid)",unit:"N\xB7m/\xB0"},I_twist_front:{value:0,label:"twist inertia, front end (0 = lumped)",unit:"kg\xB7m\xB2"},I_twist_rear:{value:0,label:"twist inertia, rear end (0 = lumped)",unit:"kg\xB7m\xB2"},I_wheel:{value:0,label:"rotating inertia per wheel",unit:"kg\xB7m\xB2"},I_rotor:{value:0,label:"driveline inertia at the motor",unit:"kg\xB7m\xB2"},ackermann_pct:{value:50,label:"Ackermann",unit:"%"},toe_front_deg:{value:0,label:"static toe front (+ in)",unit:"\xB0"},toe_rear_deg:{value:0,label:"static toe rear (+ in)",unit:"\xB0"},spring_front:{value:35,label:"spring front (@spring)",unit:"N/mm"},spring_rear:{value:40,label:"spring rear (@spring)",unit:"N/mm"},mr_front:{value:1,label:"motion ratio front",unit:"-"},mr_rear:{value:1,label:"motion ratio rear",unit:"-"},track_front:{value:1200,label:"track front",unit:"mm"},track_rear:{value:1200,label:"track rear",unit:"mm"},wheelbase:{value:1535,label:"wheelbase",unit:"mm"},rc_front:{value:30,label:"roll centre front",unit:"mm"},rc_rear:{value:40,label:"roll centre rear",unit:"mm"},tv_enabled:{value:0,label:"torque vectoring",unit:"0/1"},tv_kp:{value:3e3,label:"TV yaw-rate gain",unit:"N per rad/s"},tv_ff_low:{value:150,label:"TV feedforward, low speed",unit:"N"},tv_ff_high:{value:300,label:"TV feedforward, high speed",unit:"N"},tv_v_low:{value:18,label:"TV feedforward ramp start",unit:"m/s"},tv_v_high:{value:25,label:"TV feedforward ramp end",unit:"m/s"}},VO=["k_yaw","k_roll","k_pitch"];function Qc(e){for(let t of VO)delete e[t];for(let t of Object.keys(cn)){let r=e[t];if(!r){e[t]={...cn[t]};continue}e[t]={...r,label:cn[t].label,unit:cn[t].unit}}return e}function ee(e,t){return e[t]?.value??cn[t].value}function ua(e){let t=ee(e,"chassis_torsion");return t>0&&Number.isFinite(t)?t:void 0}function Zc(e,t){if(ua(e)===void 0)return;let r=ee(e,t==="front"?"I_twist_front":"I_twist_rear");return r>0&&Number.isFinite(r)?r:void 0}function bd(e){let t=(r,n)=>e[r]?.value??n;return{enabled:t("tv_enabled",0)>=.5,kp:t("tv_kp",Ys.kp),ffLow:t("tv_ff_low",Ys.ffLow),ffHigh:t("tv_ff_high",Ys.ffHigh),vLow:t("tv_v_low",Ys.vLow),vHigh:t("tv_v_high",Ys.vHigh)}}var $A=[10,25,50,100,200,300];function A0(e,t,r,n,o){let s=$A.map(i=>Math.round(i<=25?r*i:r*25+n*(i-25)));return{id:e,label:t,speedMmS:[...$A],reboundN:s,bumpN:s.map(i=>Math.round(i*o))}}var gd={name:"Generic FS damper",curves:[A0("c1","Soft",1.6,1,.65),A0("c2","Medium",3,1.6,.65),A0("c3","Firm",8,2.4,.65)]};function yd(e){let t=e.curves.length;return t>0?e.curves[Math.floor((t-1)/2)].id:""}var Mo=25;function Ws(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 GA(e,t){return t>=0?Ws(e.rebound,t):-Ws(e.bump,-t)}function KA(e,t,r){return t*GA(e,t*r)}var w0=(e,t)=>e.curves.find(r=>r.id===t);function Jc(e,t){let r=w0(e,yd(e)),n=(t&&w0(e,t.bump))??r,o=(t&&w0(e,t.rebound))??r;return{bump:{speedMmS:n?.speedMmS??[],forceN:n?.bumpN??[]},rebound:{speedMmS:o?.speedMmS??[],forceN:o?.reboundN??[]}}}var xd=5e3;function el(e,t){let r=t>0?t:1,n=[],o=[],a=e.bump.speedMmS.map(c=>c/r).filter(c=>c<xd),s=e.rebound.speedMmS.map(c=>c/r).filter(c=>c<xd),i=c=>{n.push(c),o.push(KA(e,r,c))};i(-xd);for(let c=a.length-1;c>=0;c--)i(-a[c]);i(0);for(let c of s)i(c);return i(xd),{kind:"map",input:"velocity",x:n,y:o}}var C0=64;function tl(e,t,r){let n=t>0?t:1,o=Math.max(r,1e-6),a=0;for(let s=0;s<C0;s++){let i=Math.sin((s+.5)*Math.PI/C0),c=n*o*i;a+=n*(Ws(e.rebound,c)+Ws(e.bump,c))*i}return a*(Math.PI/C0)/(Math.PI*o)}function ma(e,t,r,n,o=e){let a=(c,l,u)=>{if(!c||c.curves.length===0)return;let d=Jc(c,l);return{law:d,curve:el(d,u),rate:tl(d,u,Mo)}},s=a(e,t?.front,r),i=a(o??e,t?.rear,n);return!s&&!i?null:{...s?{front:s}:{},...i?{rear:i}:{}}}var HA=(e,t)=>({...e,y:e.y.map(r=>r*t)}),BO=e=>({...e,x:e.x.map(t=>-t).reverse(),y:e.y.map(t=>-t).reverse()});function F0(e,t,r){let n=Math.abs(r)>0?Math.abs(r):1,o=Jc(e,t);return{law:o,curve:HA(el(o,n),.5),rate:tl(o,n,Mo)/2,mr:n,ratio:n,share:.5}}function T0(e,t,r,n,o){let a=n*(Math.abs(r)>0?Math.abs(r):1),s=Jc(e,t),i=HA(el(s,a),1/n);return{law:s,curve:o?BO(i):i,rate:tl(s,a,Mo)/n,mr:a/n,ratio:a,share:1/n}}function rl(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 Rd=["front","rear","heaveFront","heaveRear","rollFront","rollRear"];function nl(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 Wn(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 al(e){return e.kind==="coil"?2:1}function ol(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 YA(e){return ol(e)/2}function WA(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 zA(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 $O(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 sl(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*ol(e.section)/e.barLength,a=2*o/(n*n),s=YA(e.armSection??e.section),i=3*e.E*s/n**3,c=e.dropLinkRate??1/0;return{rateAtLink:zA([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*ol(e.section)/e.barLength,a=2*o/(n*n),s=3*e.E*WA(e.blade)/n**3,i=e.dropLinkRate??1/0;return{rateAtLink:zA([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*ol(e.section)/e.length,a=2*o/(n*n);return{rateAtLink:a,contributions:{barTwist:a},torsional:o}}case"coil":{let n=Wn(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=$O(e.linkTravel,e.force,t);return{rateAtLink:Math.max(0,n),contributions:{},torsional:0}}}}function vd(e,t,r=0){if(e.kind==="none")return{wheelRate:0,motionRatio:0,rateAtLink:0};if(e.kind==="direct")return{wheelRate:Math.max(0,e.wheelRate),motionRatio:1,rateAtLink:0};let n=t?fb(t,r):1,o=t?hb(t,r):0,a=sl(e,o).rateAtLink;return{wheelRate:Math.max(0,a*n*n),motionRatio:n,rateAtLink:a}}function il(e,t){let r=e.damper??0;return!r||e.design.kind==="none"?0:al(e.design)*r*t*t}var GO=150;function KO(e){return J(e,[0,-.5,1])<-1e-9?X(e,-1):e}function jA(e){let t=e.hardpoints,r=H(t.rockerPivotB,t.rockerPivotA),n=oe(t.rockerPivotA,X(H(t.rockerToDamper,t.rockerPivotA),.6)),o=KO(re(le(r,H(t.rockerToDamper,t.rockerPivotA))));return{outer:n,inner:oe(n,X(o,GO)),attach:"rocker"}}function UA(e,t,r,n){let o=H(r,t),a=qr(o);if(a<1e-9)return[...t];let s=X(o,1/a),i=Uv(t,r,.5),c=s[0]<0?-1:1,l=n!==void 0?n*c:J(H(Fn(e,t,s),i),s),u=Math.max(-a/2,Math.min(a/2,l));return oe(i,X(s,u))}function P0(e){switch(e.kind){case"ubar":case"blade":return e.armLength;case"torsionTube":return e.leverArm;default:return}}var D0=[0,1,0];function L0(e,t,r){let n=H(r,t),o=J(n,n);if(o<1e-12)return[...t];let a=Math.max(0,Math.min(1,J(H(e,t),n)/o));return oe(t,X(n,a))}var HO=(e,t,r)=>Pe(e,t)<=Pe(e,r)?t:r,zO=2;function YO(e,t,r){let n=r.geometry,o;switch(e.attach){case"rocker":o=UA(t,n.rockerPivotA,n.rockerPivotB,e.shaftStationOuter);break;case"lowerArm":o=HO(t,L0(t,n.lcaFront,n.uprightLower),L0(t,n.lcaRear,n.uprightLower));break;case"upright":o=L0(t,n.uprightLower,n.mcpherson?n.pushrodOuter:n.uprightUpper);break}return Pe(o,t)>zO?o:void 0}function WO(e,t){let r=le(D0,e),n=t?-1:1;if(qr(r)<1e-6)return[n,0,0];let o=re(r);return(Math.abs(o[0])>.5?o[0]*n<0:o[2]>0)?X(o,-1):o}function XA(e,t,r,n){let o=e.linkage,a=r.placement,s=rt(Ye(t,o,r.state),a),i=rt(o.outer,a),c=rt(o.inner,a),l=re(H(i,c)),u=J(H(s,i),l),d=WO(l,a.isFront),p=oe(c,X(d,n)),m=J(le(D0,X(d,-1)),l),f=n>0&&Math.abs(m)>1e-9?u/(n*m):0,h=oe(p,sr(H(c,p),D0,f)),b=YO(o,s,r);return{outer:s,...b?{mount:b}:{},tip:h,root:p,linkTravel:u,twist:f}}function pr(e,t){let r={};for(let o of Zr)r[o]=wt(qe(e,o));let n={vehicle:e,ctx:r};return t&&(n.kc=sm(n,t)),n}function jO(e,t,r,n){let o=e.corner.hardpoints,a=ps(e.rocker,t.points.rockerAngle),s=i=>rt(i,r);return{ucaFront:s(o.ucaFront),ucaRear:s(o.ucaRear),lcaFront:s(o.lcaFront),lcaRear:s(o.lcaRear),tieInner:s(Ko(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:Tn(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 kd(e,t,r,n){let o=ze(t,e.vehicle.config),a=o.isFront?o.sideSign*n:0,s;try{s=Ht(Ae(e.ctx[t],r,a))}catch{return null}if(!s)return null;let i=qe(e.vehicle,t).config.loadedRadius,c=jO(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 Md=.5;function UO(e,t){let r=([i,c,l])=>{let u=re(H(c,i)),d=H(l,i),p=re(H(d,X(u,J(d,u))));return[u,p,le(u,p)]},n=r(e),o=r(t),a=[0,1,2].map(i=>[0,1,2].map(c=>o[0][i]*n[0][c]+o[1][i]*n[1][c]+o[2][i]*n[2][c]));return{rot:a,move:i=>{let c=H(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 qA=e=>[(e[2][1]-e[1][2])/2,(e[0][2]-e[2][0])/2,(e[1][0]-e[0][1])/2];function Sd(e,t,r){let n=ze(t,e.vehicle.config),o=e.ctx[t],a=r.rigid?void 0:{loadedRadius:r.loadedRadius},s=r.state?null:Ae(o,r.travel,r.steer,void 0,a),i=r.state??Et(s),c=Ae(o,r.travel+Md,r.steer,void 0,a),l=Ae(o,r.travel-Md,r.steer,void 0,a),u=(s?s.ok:r.converged)&&c.ok&&l.ok,d=Et(c),p=Et(l),m=(F,T)=>rt(F.points[T],n),f=o.inv.strut?"pushrodOuter":"uprightUpper",h=m(i,f),b=m(i,"uprightLower"),g=F=>{let T=H(b,h);return Math.hypot(...le(T,H(m(i,F),h)))/Math.hypot(...T)},y=g("tieOuter")>=g("wheelCenter")?"tieOuter":"wheelCenter",x=[h,b,m(i,y)],v=F=>UO(x,[m(F,f),m(F,"uprightLower"),m(F,y)]),k=v(d),R=v(p),M=qA(k.rot),S=qA(R.rot),w=[NaN,NaN,NaN];return{solved:u,state:i,at:F=>m(i,F),velocity:F=>u?X(H(k.move(F),R.move(F)),1/(2*Md)):w,omega:u?X(H(M,S),1/(2*Md)):w}}function Ad(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 QA(e,t,r){let n=Sd(e,t,Qt(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 ZA(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 JA(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 XO(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 qO=.1*Math.PI/180;function E0(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]))*qO<=o*n}function wd(e,t){return!e.valid||!e.cpLeft||!e.cpRight?!1:E0([e.lateral,e.height],e.cpLeft,e.cpRight,e.sinAngle,t)}function js(e){let t=(o,a,s)=>{let i=o&&a?[a[0]-o[0],a[1]-o[1]]:s;return!o||!i||!(Math.abs(i[0])>1e-9)?Number.NaN:o[1]-o[0]*i[1]/i[0]},r=t(e.cpLeft,e.icLeft,e.lineLeft),n=t(e.cpRight,e.icRight,e.lineRight);return Number.isFinite(r)&&Number.isFinite(n)?{left:r,right:n}:null}function Us(e){let t=js(e);if(!t||!e.cpLeft||!e.cpRight)return null;let r=(t.left+t.right)/2,n=e.cpRight[0]-e.cpLeft[0],o=e.cpRight[1]-e.cpLeft[1],a=Math.hypot(n,o)||1;return{height:r,heightAboveGround:(0-e.cpLeft[0])*(-o/a)+(r-e.cpLeft[1])*(n/a)}}var QO=1;function ew(e){let t=js(e);return!t||Math.abs(t.left-t.right)>QO?null:Us(e)}function Xs(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 $r(e,t,r){let n=r==="front"?"FL":"RL",o=r==="front"?"FR":"RR",a=QA(e,n,t),s=QA(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=ZA(a),c=ZA(s),l=JA(a,i),u=JA(s,c),d={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 d;let p=i?[i[0]-a.cp[0],i[1]-a.cp[1]]:l,m=c?[c[0]-s.cp[0],c[1]-s.cp[1]]:u,f=Math.hypot(p[0],p[1]),h=Math.hypot(m[0],m[1]),b=f>0&&h>0?Math.abs(p[0]*m[1]-p[1]*m[0])/(f*h):0,g=Ad(a.cp,p,s.cp,m)??XO(a.cp,l,s.cp);if(!g)return{...d,sinAngle:b};let y=s.cp[0]-a.cp[0],x=s.cp[1]-a.cp[1],v=Math.hypot(y,x)||1,k=y/v,R=x/v,M=(a.cp[0]+s.cp[0])/2,S=(a.cp[1]+s.cp[1])/2,w=(g[0]-a.cp[0])*-R+(g[1]-a.cp[1])*k,F=(g[0]-M)*k+(g[1]-S)*R;return{lateral:g[0],height:g[1],heightAboveGround:w,lateralAlongGround:F,valid:!0,icLeft:i,icRight:c,lineLeft:l,lineRight:u,sinAngle:b,cpLeft:a.cp,cpRight:s.cp}}function jn(e,t){return{front:$r(e,t,"front"),rear:$r(e,t,"rear")}}function Cd(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 ZO(e,t){return{camber:Cd(e.travel,e.camber,t),toe:Cd(e.travel,e.toe,t),motionRatio:Cd(e.travel,e.motionRatio,t),damperLen:e.damperLen?Cd(e.travel,e.damperLen,t):0}}var tw=e=>ZO(e,0).motionRatio;function I0(e,t){if(e.kind!=="coil")return null;let r=t??e.motionRatio,n=Wn(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 Fd(e,t){if(e.kind==="none")return 0;if(e.kind==="tabulated"){let n=a=>JO(e,a);return(n(.5)-n(-.5))/(2*.5)/2}if((e.gap??0)>0)return 0;let r=t??e.motionRatio;return Wn(e.rate,0)*r*r/2}function cl(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 JO(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 _0={kind:"coil",rate:120,motionRatio:.7,gap:5,bothWays:!1};var rw=new WeakMap;function Td(e,t){let r=rw.get(e);r||(r=new Map,rw.set(e,r));let n=`${t.attach}|${t.outer.join(",")}|${JSON.stringify(t.mount??null)}`,o=r.get(n);if(o)return o;let a=zo(e,t);return r.set(n,a),a}var tV=32,ll=new Map,nw=new WeakMap,rV=1;function nV(e){let t=nw.get(e);return t===void 0&&(t=rV++,nw.set(e,t)),t}function N0(e,t){if(!t.linkage)return null;let r=en(e,t.linkage,t.design.kind),n=`${nV(e)}|${r?"unit":"bar"}|${JSON.stringify(t.linkage)}`,o=ll.get(n);if(o)return o;let a=xs(e,t.linkage,{kind:t.design.kind});return ll.size>=tV&&ll.delete(ll.keys().next().value),ll.set(n,a),a}var ow=e=>e!=null&&e.design.kind!=="none"&&e.design.kind!=="coil";function oV(e,t,r){if(!(!ow(r)||!So(e)||ow(t)))return r}function Pd(e,t,r=0){let n=(a,s)=>{if(!(!a||a.design.kind==="none"))return vd(a.design,N0(s,a),r).wheelRate},o=(a,s,i)=>{let c=n(s,a),l=n(oV(a,s,i),a);return{...c!==void 0?{element:c}:{},...l!==void 0?{bar:l}:{}}};return{front:o(e.front,t.arbFrontDesign,t.rollBarFrontDesign),rear:o(e.rear,t.arbRearDesign,t.rollBarRearDesign)}}function ul(e,t,r=0){let{front:n,rear:o}=Pd(e,t,r),a=s=>s.element===void 0&&s.bar===void 0?void 0:(s.element??0)+(s.bar??0);return{front:a(n),rear:a(o)}}function Qs(e,t){let r=(n,o)=>{if(!n||n.design.kind==="none")return;let a=n.linkage?Td(o,n.linkage).atDesign:void 0;return Fd(n.design,a)};return{front:r(t.heaveFrontDesign,e.front),rear:r(t.heaveRearDesign,e.rear)}}function lw(e,t){let r=(a,s)=>{if(!a||a.design.kind!=="coil")return;let i=a.linkage?Td(s,a.linkage).atDesign:void 0;return I0(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 Ld(e,t){let r=(o,a)=>o?cl(o,O0(o,a)):0,n=(o,a)=>o?il(o,V0(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 O0=(e,t)=>e.linkage?Td(t,e.linkage).atDesign:void 0,V0=(e,t)=>vd(e.design,N0(t,e),0).motionRatio;function uw(e,t){let r=t.damperSetup,n=t.heaveDamperModel??t.damperModel,o=t.rollDamperModel??t.damperModel,a=(p,m,f)=>{if(!p||!n?.curves.length)return;let h=O0(p,m);if(cl(p,h)>0)return F0(n,r?.[f],h??(p.design.kind==="coil"?p.design.motionRatio:1))},s=(p,m,f)=>{if(!p||!o?.curves.length)return;let h=V0(p,m);if(!(il(p,h)>0))return;let b=N0(m,p)!==null;return T0(o,r?.[f],h,al(p.design),b&&h>0)},i={},c=a(t.heaveFrontDesign,e.front,"heaveFront"),l=a(t.heaveRearDesign,e.rear,"heaveRear"),u=s(t.arbFrontDesign,e.front,"rollFront"),d=s(t.arbRearDesign,e.rear,"rollRear");return c&&(i.heaveFront=c),l&&(i.heaveRear=l),u&&(i.rollFront=u),d&&(i.rollRear=d),i}function Dd(e,t){let r=t.heaveDamperModel??t.damperModel,n=t.rollDamperModel??t.damperModel,o=(i,c)=>So(i)?{source:"none"}:nl(i.config.coilover,c),a=(i,c)=>{if(!i)return{source:"none"};let l=cl(i,O0(i,c))>0;return nl(i.coilover,l?r:void 0)},s=(i,c)=>{if(!i||i.design.kind!=="coil")return{source:"none"};let l=il(i,V0(i,c))>0;return nl(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 mw(e){let t=(r,n)=>{let o={};return r?.linkage&&r.design.kind==="coil"&&(o.heave=r.linkage),n?.linkage&&n.design.kind!=="none"&&n.design.kind!=="direct"&&(o.roll=n.linkage,o.rollKind=n.design.kind),o.heave||o.roll?o:void 0};return{front:t(e.heaveFrontDesign,e.arbFrontDesign),rear:t(e.heaveRearDesign,e.arbRearDesign)}}var So=e=>e.config.actuation==="decoupled",da="a decoupled axle damps in its heave and roll elements, set below";function dw(e,t,r={}){let n={...t},o=(d,p)=>{let m=n[d];m&&typeof m=="object"&&"value"in m&&(n[d]={...m,value:p})},{front:a,rear:s}=ul(e,t);a!==void 0&&o("arb_front",a),s!==void 0&&o("arb_rear",s);for(let[d,p,m]of[[t.heaveFrontDesign,e.front,"heave_spring_front"],[t.heaveRearDesign,e.rear,"heave_spring_rear"]]){if(!d||d.design.kind==="none")continue;let f=d.linkage?Td(p,d.linkage).atDesign:void 0;o(m,Fd(d.design,f))}let i=sV(e,t,r),c=aV(e,i);n.kinFront=c.kinFront,n.kinRear=c.kinRear;let l=lV(e,i);n.steerFront=c.steerFront,Number.isFinite(l.ackermannPct)&&o("ackermann_pct",l.ackermannPct);let u=d=>So(d)?0:d.measured?.springRate??d.config.springRate;o("spring_front",u(e.front)),o("spring_rear",u(e.rear));for(let[d,p]of[[e.front,"spring_front"],[e.rear,"spring_rear"]])So(d)&&(n.readouts={...n.readouts,[p]:"a decoupled axle has no corner spring; its heave and roll elements carry the car"});for(let[d,p]of[[e.front,"damper_front"],[e.rear,"damper_rear"]])So(d)&&(o(p,0),n.readouts={...n.readouts,[p]:da});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 aV(e,t){return{kinFront:sw(e.front),kinRear:sw(e.rear),steerFront:e.front.measured?void 0:Ed(e.front,t)}}var aw=new WeakMap;function sw(e){let t=aw.get(e);return t||aw.set(e,t=Ps(e)),t}function sV(e,t,r={}){return iV(e,t,r.front,r.rear)}function iV(e,t,r,n){let o=e.front.config.loadedRadius;if(!((on(r??t.tireModel)??0)>0))return o;let a={...t,surveyedRadiusFront:o,surveyedRadiusRear:e.rear.config.loadedRadius};return Id(a,r,n).front??o}var iw=new WeakMap;function Ed(e,t=e.config.loadedRadius){let r=iw.get(e);r||(r=new Map,iw.set(e,r));let n=r.get(t);if(n)return n;let o=t===e.config.loadedRadius?void 0:{loadedRadius:t},a=Ib(e,It(e.config),void 0,void 0,void 0,void 0,o);return r.size>=4&&r.clear(),r.set(t,a),a}var cw=new WeakMap;function cV(e){return ct(e,{travelMin:-1,travelMax:1,steps:3}).samples[1].metrics.motionRatio??1}var qs=e=>e.measured?tw(e.measured):cV(e);function lV(e,t=e.front.config.loadedRadius){let r=()=>e.front.measured?void 0:Ed(e.front,t);return{...uV(e),get steerFront(){return r()},get ackermannPct(){let n=r();return n?_b(n,qt(e.front),e.config.wheelbase):Number.NaN}}}function uV(e){let t=cw.get(e);if(t)return t;let r=e.front.measured,n=e.rear.measured,a=!r||!n?jn(pr(e),{heave:0,pitch:0,roll:0,steer:0}):null,s={wheelbase:e.config.wheelbase,trackFront:r?r.track:qt(e.front),trackRear:n?n.track:qt(e.rear),mrFront:qs(e.front),mrRear:qs(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:Xs(a.front),rcGainRear:n||!a?0:Xs(a.rear),rcFrontValid:r?!0:!!a?.front.valid,rcRearValid:n?!0:!!a?.rear.valid};return cw.set(e,s),s}var Jt={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}},hw=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ln=(e,t,r,n=1/0)=>typeof e=="number"&&Number.isFinite(e)?Math.min(n,Math.max(r,e)):t;function pa(e){if(hw(e))switch(e.kind){case"open":case"spool":return{kind:e.kind};case"clutch":{let t=Jt.clutch;return{kind:"clutch",preloadNm:ln(e.preloadNm,t.preloadNm,0),rampDriveDeg:ln(e.rampDriveDeg,t.rampDriveDeg,1,90),rampCoastDeg:ln(e.rampCoastDeg,t.rampCoastDeg,1,90),faces:Math.round(ln(e.faces,t.faces,0)),muClutch:ln(e.muClutch,t.muClutch,0,1),rFrictionMm:ln(e.rFrictionMm,t.rFrictionMm,1),rRampMm:ln(e.rRampMm,t.rRampMm,1)}}case"torsen":{let t=Jt.torsen,r=ln(e.preloadNm,0,0);return{kind:"torsen",tbrDrive:ln(e.tbrDrive,t.tbrDrive,1),tbrCoast:ln(e.tbrCoast,t.tbrCoast,1),...r>0?{preloadNm:r}:{}}}default:return}}function _d(e){if(!hw(e))return;let t=pa(e.front),r=pa(e.rear);return t||r?{...t?{front:t}:{},...r?{rear:r}:{}}:void 0}function fa(e){let t=Br(e),r=n=>n>=2?"independent":n===1?"diff":"none";return{front:r(t.front),rear:r(t.rear)}}function ml(e){if(!e.driveline)return;let t=fa(e),r=e.r_dyn.value,n=s=>{if(t[s]!=="diff")return;let i=pa(e.driveline?.[s]);if(!(!i||i.kind==="independent"))return{kind:i.kind,drive:Kc(i,"drive",r),coast:Kc(i,"coast",r),hubs:Kc(i,"hubs",r)}},o=n("front"),a=n("rear");return o||a?{...o?{front:o}:{},...a?{rear:a}:{}}:void 0}var mV={kind:{label:"Differential"},preloadNm:{label:"Preload",unit:"N\xB7m"},rampDriveDeg:{label:"Drive ramp",unit:"\xB0"},rampCoastDeg:{label:"Coast ramp",unit:"\xB0"},faces:{label:"Friction faces"},muClutch:{label:"Clutch friction \u03BC"},rFrictionMm:{label:"Friction radius",unit:"mm"},rRampMm:{label:"Ramp radius",unit:"mm"},tbrDrive:{label:"Drive bias ratio",unit:": 1"},tbrCoast:{label:"Coast bias ratio",unit:": 1"}},pw=e=>{let t=e==="front"?"Front":"Rear";return Object.fromEntries(Object.entries(mV).map(([r,n])=>[`${e}.${r}`,{section:t,...n}]))},Nd={...pw("front"),...pw("rear")},fw=e=>e.motorModel?.kind==="ice"?e.motorPlacement==="front"?"front":"rear":null;function bw(e,t){let r=fw(t);if(!(!r||fw(e)===r||t.driveline?.[r]))return{...t.driveline,[r]:{...Jt.clutch}}}function Mr(e,t,r,n){return e>0?!(r>0)||!Number.isFinite(r)?e:Math.max(1,e-t/r):n}function Od(e,t,r){let n=Math.max(0,Math.min(1,r)),o=Mr(e.freeRadius,e.staticLoad,e.tyreRate,e.surveyed),a=Mr(t.freeRadius,t.staticLoad,t.tyreRate,t.surveyed);return n*o+(1-n)*a}function Zs(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 Un(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 dl(e,t){if(!e)return pV(t);let r=t-go(e,0).camber;return r?{...e,camber:e.camber.map(n=>n+r)}:e}function dV(e){return{kinFront:dl(e.kinFront,ee(e,"camber_front_deg")),kinRear:dl(e.kinRear,ee(e,"camber_rear_deg"))}}function pV(e){let t=[-40,0,40];return{travel:t,motionRatio:t.map(()=>1),camber:t.map(()=>e),toe:t.map(()=>0),damperLen:t.map(()=>0)}}var gw=9.81,yw=e=>e>1?e/100:e;function ha(e,t,r){let n=t??e.tireModel??wc(),o=r??e.tireModelRear??n,a={grip:ee(e,"grip_scale"),stiffness:ee(e,"stiffness_scale")},s=_m(n,a);return{front:s,rear:o===n?s:_m(o,a)}}function un(e,t,r){let n=ha(e,t,r),o=Ke(n.front);return zt(n.rear===n.front?o:Sm(o,Ke(n.rear)))}function B0(e,t,r){let n=yw(e.front_mass_diss.value),o=ha(e,t,r),a=Ke(o.front),s=o.rear===o.front?a:Ke(o.rear),i=t??e.tireModel,c=r??e.tireModelRear??i,l=e.m.value*gw*n/2,u=e.m.value*gw*(1-n)/2,d=(i?a.verticalStiffness():0)||ee(e,"tire_vertical_rate"),p=(c?s.verticalStiffness():0)||ee(e,"tire_vertical_rate"),m=on(i)??0,f=on(c)??0,h=e.surveyedRadiusFront&&e.surveyedRadiusRear?Od({freeRadius:m,staticLoad:l,tyreRate:d,surveyed:e.surveyedRadiusFront},{freeRadius:f,staticLoad:u,tyreRate:p,surveyed:e.surveyedRadiusRear},n):void 0,b=e.surveyedRadiusFront?Mr(m,l,d,e.surveyedRadiusFront):void 0,g=e.surveyedRadiusRear?Mr(f,u,p,e.surveyedRadiusRear):void 0;return{ev:a,evR:s,Wf:l,Wr:u,tireRate:d,tireRateRear:p,tyreFreeRadius:m,tyreFreeRadiusRear:f,cgStandingRadius:h,standingFront:b,standingRear:g}}function Id(e,t,r){let n=B0(e,t,r);return{front:n.standingFront,rear:n.standingRear}}function xw(e,t,r){return B0(e,t,r).cgStandingRadius}function jt(e,t,r){let n=yw(e.front_mass_diss.value),o=ee(e,"mr_front")||1,a=ee(e,"mr_rear")||1,{ev:s,evR:i,Wf:c,Wr:l,tireRate:u,tireRateRear:d,tyreFreeRadius:p,tyreFreeRadiusRear:m,cgStandingRadius:f,standingFront:h,standingRear:b}=B0(e,t,r),g=$c(e),y=ml(e),x=ma(e.damperModel,e.damperSetup,o,a,e.damperModelRear??e.damperModel),v=e.readouts?.damper_front===da,k=e.readouts?.damper_rear===da,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,ee(e,"cop_long"))),copHeight:ee(e,"cop_height"),...e.aeroModel?{model:e.aeroModel}:{},rideHeightFront:ee(e,"ride_height_front"),rideHeightRear:ee(e,"ride_height_rear")};return{massTotal:e.m.value,frontMassFrac:n,steeringSystem:e.steeringSystem,tv:bd(e),cgHeight:Zs(ee(e,"cg_height"),e.cgReference?.standingRadius,f),...f!==void 0?{cgStandingRadius:f}:{},wheelbase:ee(e,"wheelbase"),trackFront:ee(e,"track_front"),trackRear:ee(e,"track_rear"),wheelRateFront:ee(e,"spring_front")*o*o,wheelRateRear:ee(e,"spring_rear")*a*a,tireRate:u,...d!==u?{tireRateRear:d}:{},tireDamping:ee(e,"tire_vertical_damping"),arbFront:ee(e,"arb_front"),arbRear:ee(e,"arb_rear"),...ua(e)?{chassisTorsion:ua(e)}:{},brakeBalanceFront:g.balanceFront,brakes:g,...y?{driveline:y}:{},heaveSpringFront:ee(e,"heave_spring_front"),heaveSpringRear:ee(e,"heave_spring_rear"),unsprungPerCorner:ee(e,"unsprung_mass"),unsprungCgHeight:fV(e,{Wf:c,Wr:l,tireRate:u,tireRateRear:d,tyreFreeRadius:p,tyreFreeRadiusRear:m,standingFront:h,standingRear:b}),tyreFreeRadius:p,...m!==p?{tyreFreeRadiusRear:m}:{},rcHeightFront:Un(ee(e,"rc_front"),e.rcRoad?.gainFront,e.rcRoad?.radiusFront,h),rcHeightRear:Un(ee(e,"rc_rear"),e.rcRoad?.gainRear,e.rcRoad?.radiusRear,b),corneringStiffnessFront:s.corneringStiffness(c),corneringStiffnessRear:i.corneringStiffness(l),damperFront:x?.front&&!v?x.front.rate:ee(e,"damper_front")*o*o,damperRear:x?.rear&&!k?x.rear.rate:ee(e,"damper_rear")*a*a,...x?.front&&!v?{damperCurveFront:x.front.curve}:{},...x?.rear&&!k?{damperCurveRear:x.rear.curve}:{},aero:R,ackermannPct:ee(e,"ackermann_pct"),toeFrontDeg:ee(e,"toe_front_deg"),toeRearDeg:ee(e,"toe_rear_deg"),yawInertia:ee(e,"I_yaw"),steerFront:e.steerFront,...dV(e)}}function fV(e,t){let r=(a,s,i,c)=>a??(s>0?Mr(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 Vd={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 Rw(e,t=e.batteryModel){if(!t)return e;let r=An(t),n=(o,a)=>({...o,value:a});return{...e,capacity:n(e.capacity,r.capacityAh),ocv:n(e.ocv,r.voltageAtFull)}}var kw={damper_front:`the damper part sets it: its front curve at ${Mo} mm/s`,damper_rear:`the damper part sets it (the rear's own, where the car names one): its rear curve at ${Mo} mm/s`};function Bd(e){let t=!!(e.damperModelId||e.damperModel),r=t||!!(e.damperModelIdRear||e.damperModelRear);return{...t?{damper_front:kw.damper_front}:{},...r?{damper_rear:kw.damper_rear}:{}}}function Mw(e,t=e.damperModel,r=e.damperModelRear??t){if(!t&&!r)return e;let n=ee(e,"mr_front")||1,o=ee(e,"mr_rear")||1,a=ma(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!==da&&(i.damper_front=s(e.damper_front,"damper front",a.front.rate/(n*n))),a.rear&&e.readouts?.damper_rear!==da&&(i.damper_rear=s(e.damper_rear,"damper rear",a.rear.rate/(o*o))),i}var Sw={how:"scripts/paramTiers.ts: each row \xB120 % (switches flipped, springs on the suspension), first car of every gallery template, largest change to any event time, % of it",templates:["fs-ev-comparison","fs-ev-single","fs-combustion","fs-ev-awd","fs-ev-rwd-hubs","fs-ev-one-motor","formula-1","touring-car","street-car","cup-car","stock-car","hill-climb","suspension","direct-coilover","pushrod","pullrod","third-spring","mcpherson-strut","tyre-study"],rows:{endurance_reserve:{group:"Powertrain",score:"infinite",byTemplate:{"fs-ev-comparison":"infinite","fs-ev-single":"infinite","fs-combustion":null,"fs-ev-awd":0,"fs-ev-rwd-hubs":"infinite","fs-ev-one-motor":"infinite","formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:0,"direct-coilover":null,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":null,"tyre-study":"infinite"}},gear_ratio:{group:"Powertrain",score:11.9893,byTemplate:{"fs-ev-comparison":11.9893,"fs-ev-single":11.9893,"fs-combustion":5.6255,"fs-ev-awd":5.8819,"fs-ev-rwd-hubs":11.5358,"fs-ev-one-motor":7.2758,"formula-1":.2473,"touring-car":.2195,"street-car":.0998,"cup-car":.2431,"stock-car":.0645,"hill-climb":3.1703,suspension:1.8984,"direct-coilover":.2195,pushrod:1.9001,pullrod:1.9126,"third-spring":1.9001,"mcpherson-strut":.111,"tyre-study":11.9893}},driven_wheels:{group:"Powertrain",score:11.9893,byTemplate:{"fs-ev-comparison":11.9893,"fs-ev-single":11.9893,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:1.9216,"direct-coilover":0,pushrod:1.9171,pullrod:1.919,"third-spring":1.9171,"mcpherson-strut":0,"tyre-study":11.9893}},power_scale:{group:"Powertrain",score:11.9893,byTemplate:{"fs-ev-comparison":11.9893,"fs-ev-single":11.9893,"fs-combustion":10.2883,"fs-ev-awd":4.2843,"fs-ev-rwd-hubs":11.6138,"fs-ev-one-motor":7.2758,"formula-1":2.6682,"touring-car":2.5337,"street-car":1.938,"cup-car":2.6155,"stock-car":1.2193,"hill-climb":1.869,suspension:1.9216,"direct-coilover":2.5337,pushrod:1.9171,pullrod:1.919,"third-spring":1.9171,"mcpherson-strut":1.9778,"tyre-study":11.9893}},grip_scale:{group:"Tyres",score:11.4886,byTemplate:{"fs-ev-comparison":10.9135,"fs-ev-single":10.9135,"fs-combustion":11.4886,"fs-ev-awd":11.3513,"fs-ev-rwd-hubs":11.3513,"fs-ev-one-motor":11.3905,"formula-1":10.9225,"touring-car":7.4484,"street-car":7.2578,"cup-car":7.1946,"stock-car":10.4642,"hill-climb":9.5384,suspension:8.3679,"direct-coilover":7.4484,pushrod:8.3929,pullrod:8.3807,"third-spring":8.3929,"mcpherson-strut":7.35,"tyre-study":10.9135}},front_mass_diss:{group:"Mass & chassis",score:10.3816,byTemplate:{"fs-ev-comparison":1.1854,"fs-ev-single":1.1854,"fs-combustion":1.5398,"fs-ev-awd":1.9682,"fs-ev-rwd-hubs":1.9682,"fs-ev-one-motor":4.5048,"formula-1":5.2182,"touring-car":1.241,"street-car":3.5067,"cup-car":.7277,"stock-car":2.2367,"hill-climb":10.3816,suspension:.5046,"direct-coilover":1.241,pushrod:.4796,pullrod:.4587,"third-spring":.4796,"mcpherson-strut":3.4131,"tyre-study":1.1854}},m:{group:"Mass & chassis",score:9.7815,byTemplate:{"fs-ev-comparison":9.7815,"fs-ev-single":9.7815,"fs-combustion":7.2245,"fs-ev-awd":5.6765,"fs-ev-rwd-hubs":9.2239,"fs-ev-one-motor":7.0296,"formula-1":5.3736,"touring-car":3.7044,"street-car":1.9146,"cup-car":2.6724,"stock-car":3.7623,"hill-climb":5.4157,suspension:3.8549,"direct-coilover":3.7044,pushrod:3.8507,pullrod:3.8527,"third-spring":3.8507,"mcpherson-strut":1.9399,"tyre-study":9.7815}},cop_long:{group:"Aerodynamics",score:6.6543,byTemplate:{"fs-ev-comparison":1.032,"fs-ev-single":1.032,"fs-combustion":1.0669,"fs-ev-awd":1.0452,"fs-ev-rwd-hubs":1.0452,"fs-ev-one-motor":1.0521,"formula-1":5.9878,"touring-car":.1327,"street-car":.0018,"cup-car":.2696,"stock-car":.6469,"hill-climb":6.6543,suspension:.3644,"direct-coilover":.1327,pushrod:.3575,pullrod:.355,"third-spring":.3575,"mcpherson-strut":.0072,"tyre-study":1.032}},front_aero_diss:{group:"Aerodynamics",score:5.2168,byTemplate:{"fs-ev-comparison":.9064,"fs-ev-single":.9064,"fs-combustion":.8657,"fs-ev-awd":.8967,"fs-ev-rwd-hubs":.8967,"fs-ev-one-motor":.8574,"formula-1":4.2912,"touring-car":.0708,"street-car":.0018,"cup-car":.2207,"stock-car":.5291,"hill-climb":5.2168,suspension:.2835,"direct-coilover":.0708,pushrod:.2831,pullrod:.2823,"third-spring":.2831,"mcpherson-strut":.0072,"tyre-study":.9064}},power_limit_kw:{group:"Powertrain",score:4.5916,byTemplate:{"fs-ev-comparison":.4828,"fs-ev-single":.4828,"fs-combustion":null,"fs-ev-awd":4.5916,"fs-ev-rwd-hubs":.5453,"fs-ev-one-motor":3.6198,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:.0626,"direct-coilover":null,pushrod:.0625,pullrod:.0626,"third-spring":.0625,"mcpherson-strut":null,"tyre-study":.4828}},soc:{group:"Powertrain",score:3.5618,byTemplate:{"fs-ev-comparison":3.2245,"fs-ev-single":3.2245,"fs-combustion":0,"fs-ev-awd":1.6179,"fs-ev-rwd-hubs":3.3095,"fs-ev-one-motor":3.5618,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":3.2245}},effi_pgb:{group:"Powertrain",score:3.5269,byTemplate:{"fs-ev-comparison":3.5269,"fs-ev-single":3.5269,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:.0626,"direct-coilover":0,pushrod:.0625,pullrod:.0626,"third-spring":.0625,"mcpherson-strut":0,"tyre-study":3.5269}},c_l:{group:"Aerodynamics",score:3.4342,byTemplate:{"fs-ev-comparison":.9751,"fs-ev-single":.9751,"fs-combustion":.9539,"fs-ev-awd":1.0777,"fs-ev-rwd-hubs":.9886,"fs-ev-one-motor":1.0797,"formula-1":3.4342,"touring-car":.8979,"street-car":.0715,"cup-car":.2158,"stock-car":.5467,"hill-climb":1.2705,suspension:.9751,"direct-coilover":.8979,pushrod:.9734,pullrod:.9708,"third-spring":.9734,"mcpherson-strut":.0704,"tyre-study":.9751}},ocv:{group:"Powertrain",score:3.3244,byTemplate:{"fs-ev-comparison":3.0446,"fs-ev-single":3.0446,"fs-combustion":0,"fs-ev-awd":1.4595,"fs-ev-rwd-hubs":3.1854,"fs-ev-one-motor":3.3244,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":3.0446}},capacity:{group:"Powertrain",score:3.3244,byTemplate:{"fs-ev-comparison":3.0446,"fs-ev-single":3.0446,"fs-combustion":0,"fs-ev-awd":1.4595,"fs-ev-rwd-hubs":3.1854,"fs-ev-one-motor":3.3244,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":3.0446}},A:{group:"Aerodynamics",score:2.3707,byTemplate:{"fs-ev-comparison":.802,"fs-ev-single":.802,"fs-combustion":.7928,"fs-ev-awd":.9333,"fs-ev-rwd-hubs":.7926,"fs-ev-one-motor":.961,"formula-1":2.3707,"touring-car":.6374,"street-car":.4904,"cup-car":.2428,"stock-car":.1932,"hill-climb":1.1486,suspension:.802,"direct-coilover":.6374,pushrod:.7991,pullrod:.7982,"third-spring":.7991,"mcpherson-strut":.4873,"tyre-study":.802}},rho:{group:"Aerodynamics",score:2.3707,byTemplate:{"fs-ev-comparison":.802,"fs-ev-single":.802,"fs-combustion":.7928,"fs-ev-awd":.9333,"fs-ev-rwd-hubs":.7926,"fs-ev-one-motor":.961,"formula-1":2.3707,"touring-car":.6374,"street-car":.4904,"cup-car":.2428,"stock-car":.1932,"hill-climb":0,suspension:.802,"direct-coilover":.6374,pushrod:.7991,pullrod:.7982,"third-spring":.7991,"mcpherson-strut":.4873,"tyre-study":.802}},cg_height:{group:"Mass & chassis",score:2.2005,byTemplate:{"fs-ev-comparison":1.8282,"fs-ev-single":1.8282,"fs-combustion":1.6978,"fs-ev-awd":2.2005,"fs-ev-rwd-hubs":1.8919,"fs-ev-one-motor":1.9269,"formula-1":.6248,"touring-car":1.2858,"street-car":1.4681,"cup-car":.992,"stock-car":1.2052,"hill-climb":.6037,suspension:1.8282,"direct-coilover":1.2858,pushrod:1.8142,pullrod:1.8229,"third-spring":1.8142,"mcpherson-strut":1.7176,"tyre-study":1.8282}},l_to_d_ratio:{group:"Aerodynamics",score:1.4351,byTemplate:{"fs-ev-comparison":.7905,"fs-ev-single":.7905,"fs-combustion":.6962,"fs-ev-awd":.5843,"fs-ev-rwd-hubs":.8444,"fs-ev-one-motor":.9611,"formula-1":1.4351,"touring-car":.3671,"street-car":.528,"cup-car":.5631,"stock-car":.4634,"hill-climb":.2349,suspension:.2456,"direct-coilover":.3671,pushrod:.2491,pullrod:.2456,"third-spring":.2491,"mcpherson-strut":.5265,"tyre-study":.7905}},tv_enabled:{group:"Torque vectoring",score:1.2381,byTemplate:{"fs-ev-comparison":1.2381,"fs-ev-single":1.2381,"fs-combustion":0,"fs-ev-awd":1.2293,"fs-ev-rwd-hubs":1.2293,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":.1209,"cup-car":.1617,"stock-car":0,"hill-climb":9e-4,suspension:.3086,"direct-coilover":0,pushrod:.2933,pullrod:.3089,"third-spring":.2933,"mcpherson-strut":.1326,"tyre-study":1.2381}},c_w:{group:"Aerodynamics",score:1.1499,byTemplate:{"fs-ev-comparison":.6319,"fs-ev-single":.6319,"fs-combustion":.5577,"fs-ev-awd":.462,"fs-ev-rwd-hubs":.6559,"fs-ev-one-motor":.7504,"formula-1":1.1499,"touring-car":.2914,"street-car":.4211,"cup-car":.4486,"stock-car":.3694,"hill-climb":.1625,suspension:.1945,"direct-coilover":.2914,pushrod:.1979,pullrod:.1948,"third-spring":.1979,"mcpherson-strut":.4196,"tyre-study":.6319}},brake_balance:{group:"Brakes",score:1.0132,byTemplate:{"fs-ev-comparison":.8303,"fs-ev-single":.8303,"fs-combustion":.6932,"fs-ev-awd":.9772,"fs-ev-rwd-hubs":.8148,"fs-ev-one-motor":1.0132,"formula-1":.97,"touring-car":.9585,"street-car":.7184,"cup-car":.1468,"stock-car":.0764,"hill-climb":.9096,suspension:.8303,"direct-coilover":.9585,pushrod:.8578,pullrod:.8454,"third-spring":.8578,"mcpherson-strut":.7099,"tyre-study":.8303}},stiffness_scale:{group:"Tyres",score:.871,byTemplate:{"fs-ev-comparison":.5088,"fs-ev-single":.5088,"fs-combustion":.4874,"fs-ev-awd":.3745,"fs-ev-rwd-hubs":.4753,"fs-ev-one-motor":.5706,"formula-1":.5776,"touring-car":.4346,"street-car":.1077,"cup-car":.4012,"stock-car":.1613,"hill-climb":.871,suspension:.5088,"direct-coilover":.4346,pushrod:.5253,pullrod:.5172,"third-spring":.5253,"mcpherson-strut":.1518,"tyre-study":.5088}},cop_height:{group:"Aerodynamics",score:.2837,byTemplate:{"fs-ev-comparison":.155,"fs-ev-single":.155,"fs-combustion":.1546,"fs-ev-awd":.1557,"fs-ev-rwd-hubs":.1557,"fs-ev-one-motor":.1542,"formula-1":.1173,"touring-car":.0072,"street-car":.0023,"cup-car":.0745,"stock-car":.1568,"hill-climb":.2837,suspension:.0421,"direct-coilover":.0072,pushrod:.0437,pullrod:.04,"third-spring":.0437,"mcpherson-strut":.0076,"tyre-study":.155}},spring_rear:{group:"Suspension",score:.2822,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":.0355,"touring-car":.1169,"street-car":.2242,"cup-car":.0902,"stock-car":.2822,"hill-climb":.1929,suspension:0,"direct-coilover":.1169,pushrod:.1142,pullrod:.2148,"third-spring":.1142,"mcpherson-strut":.1786,"tyre-study":0}},spring_front:{group:"Suspension",score:.2388,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":.0189,"touring-car":.0958,"street-car":.2388,"cup-car":.1462,"stock-car":.1719,"hill-climb":.1873,suspension:0,"direct-coilover":.0958,pushrod:.1257,pullrod:.0612,"third-spring":.1257,"mcpherson-strut":.1911,"tyre-study":0}},arb_front:{group:"Suspension",score:.1792,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":.0235,"touring-car":.0589,"street-car":.1792,"cup-car":.0215,"stock-car":.0926,"hill-climb":.1095,suspension:null,"direct-coilover":.0589,pushrod:.0455,pullrod:.049,"third-spring":.0455,"mcpherson-strut":.1435,"tyre-study":null}},fr_0:{group:"Tyres",score:.158,byTemplate:{"fs-ev-comparison":.158,"fs-ev-single":.158,"fs-combustion":.1097,"fs-ev-awd":.0708,"fs-ev-rwd-hubs":.1442,"fs-ev-one-motor":.1168,"formula-1":.07,"touring-car":.0492,"street-car":.1006,"cup-car":.065,"stock-car":.0262,"hill-climb":.0334,suspension:.0217,"direct-coilover":.0492,pushrod:.0229,pullrod:.0223,"third-spring":.0229,"mcpherson-strut":.0989,"tyre-study":.158}},arb_rear:{group:"Suspension",score:.1047,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":.0224,"touring-car":.0365,"street-car":.0832,"cup-car":.1047,"stock-car":.0436,"hill-climb":.0734,suspension:null,"direct-coilover":.0365,pushrod:.0411,pullrod:.0332,"third-spring":.0411,"mcpherson-strut":.0643,"tyre-study":null}},unsprung_mass:{group:"Mass & chassis",score:.102,byTemplate:{"fs-ev-comparison":.0477,"fs-ev-single":.0477,"fs-combustion":.0512,"fs-ev-awd":.0545,"fs-ev-rwd-hubs":.0514,"fs-ev-one-motor":.0799,"formula-1":.0313,"touring-car":.0471,"street-car":.102,"cup-car":.0315,"stock-car":.042,"hill-climb":.0278,suspension:.0477,"direct-coilover":.0471,pushrod:.0452,pullrod:.0468,"third-spring":.0452,"mcpherson-strut":.0876,"tyre-study":.0477}},camber_front_deg:{group:"Steering & alignment",score:.0576,byTemplate:{"fs-ev-comparison":.0065,"fs-ev-single":.0065,"fs-combustion":.008,"fs-ev-awd":.0075,"fs-ev-rwd-hubs":.0075,"fs-ev-one-motor":.0098,"formula-1":.0358,"touring-car":.0272,"street-car":.0025,"cup-car":.0191,"stock-car":.0576,"hill-climb":.0389,suspension:.0019,"direct-coilover":.0272,pushrod:.0017,pullrod:.0016,"third-spring":.0017,"mcpherson-strut":.002,"tyre-study":.0065}},camber_rear_deg:{group:"Steering & alignment",score:.0262,byTemplate:{"fs-ev-comparison":.0081,"fs-ev-single":.0081,"fs-combustion":.0085,"fs-ev-awd":.0054,"fs-ev-rwd-hubs":.0096,"fs-ev-one-motor":.0097,"formula-1":.0028,"touring-car":.0106,"street-car":8e-4,"cup-car":5e-4,"stock-car":.0035,"hill-climb":.0262,suspension:.0081,"direct-coilover":.0106,pushrod:.0082,pullrod:.0083,"third-spring":.0082,"mcpherson-strut":3e-4,"tyre-study":.0081}},I_yaw:{group:"Mass & chassis",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},I_roll:{group:"Mass & chassis",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},I_pitch:{group:"Mass & chassis",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},ride_height_front:{group:"Aerodynamics",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},ride_height_rear:{group:"Aerodynamics",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tire_vertical_rate:{group:"Tyres",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tire_vertical_damping:{group:"Tyres",score:0,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":0,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},r_dyn:{group:"Tyres",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},damper_front:{group:"Suspension",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},damper_rear:{group:"Suspension",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_kp:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_ff_low:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_ff_high:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_v_low:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_v_high:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},wheelbase:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},track_front:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},track_rear:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},rc_front:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},rc_rear:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},chassis_torsion:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_twist_front:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_twist_rear:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_wheel:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_rotor:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},v_limit_endurance:{group:"Powertrain",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},mr_front:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},mr_rear:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},heave_spring_front:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},heave_spring_rear:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},toe_front_deg:{group:"Steering & alignment",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},toe_rear_deg:{group:"Steering & alignment",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},ackermann_pct:{group:"Steering & alignment",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}}}};function Xn(e){return!!e&&typeof e=="object"&&"value"in e&&"label"in e}var yV={Batteriekapazit\u00E4t:"pack capacity",Rollwiderstandsbeiwert:"rolling-resistance coefficient"},ww=e=>yV[e]??e;function $d(e){let t=[];for(let r of Object.keys(e)){if(r==="motor"||r==="name")continue;let n=e[r];Xn(n)&&t.push({key:r,label:ww(n.label),value:n.value,unit:n.unit})}return t}var xV=[{title:"Mass & chassis",keys:["m","front_mass_diss","cg_height","unsprung_mass","wheelbase","track_front","track_rear","rc_front","rc_rear","chassis_torsion","I_twist_front","I_twist_rear","I_yaw","I_roll","I_pitch","I_wheel","I_rotor"]},{title:"Aerodynamics",keys:["A","c_l","c_w","l_to_d_ratio","front_aero_diss","cop_long","cop_height","ride_height_front","ride_height_rear","rho"]},{title:"Tyres",keys:["grip_scale","stiffness_scale","tire_vertical_rate","tire_vertical_damping","fr_0","r_dyn"]},{title:"Powertrain",keys:["gear_ratio","driven_wheels","effi_pgb","power_scale","power_limit_kw","v_limit_endurance","endurance_reserve","capacity","ocv","soc"]},{title:"Suspension",keys:["spring_front","spring_rear","mr_front","mr_rear","arb_front","arb_rear","heave_spring_front","heave_spring_rear","damper_front","damper_rear"]},{title:"Steering & alignment",keys:["camber_front_deg","camber_rear_deg","toe_front_deg","toe_rear_deg","ackermann_pct"]},{title:"Brakes",keys:["brake_balance"]},{title:"Torque vectoring",keys:["tv_enabled","tv_kp","tv_ff_low","tv_ff_high","tv_v_low","tv_v_high"]}],RV=.5,Aw=e=>e==="infinite"?1/0:typeof e=="number"?e:null,vV=e=>/front/.test(e)?e.replace("front","rear"):/rear/.test(e)?e.replace("rear","front"):null,Are=(()=>{let e=Sw.rows,t=o=>{let a=vV(o),s=Aw(e[o]?.score),i=a&&e[a]?Aw(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>=RV&&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 $0={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 Cw(e){let t=new Map;for(let a of $d(e))t.set(a.key,a);let r=new Set,n=[];for(let a of xV){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=$d(e).filter(a=>!r.has(a.key));return o.length&&n.push({title:"Other",rows:o}),n}var G0={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"},K0={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"},Fw=e=>!!(e.aeroModelId||e.aeroModel);function kV(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"),!r.arb_front&&t(e.rollBarFrontDesign)&&(r.arb_front="the front anti-roll bar design sets it"),!r.arb_rear&&t(e.rollBarRearDesign)&&(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 MV=e=>!!(e.batteryModelId||e.batteryModel),Tw={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"},wre=Object.keys(Tw);function H0(e){if(!(e.motorModelId||e.motorModel))return{};let t=kt(e.motorModel),r={effi_pgb:"the motor model states its own efficiency",...t?Tw:{}};return(e.motorCount!=null||t)&&(r.driven_wheels="the motor layout in Powertrain sets which wheels are driven"),r}function SV(e,t){let r={};return t.geometry&&Object.assign(r,$0,kV(e)),Fw(e)&&Object.assign(r,G0),MV(e)&&Object.assign(r,Vd),Object.assign(r,H0(e)),Object.assign(r,Bd(e)),Object.assign(r,Qm(e)),e.readouts&&Object.assign(r,e.readouts),r}function Pw(e,t){let r=SV(e,t);return Fw(e)||Object.assign(r,K0),r}function z0(e){let t=e.cop_long;return Xn(t)?1-t.value:.5}function AV(e,t){let r=e.front_aero_diss,n=e.cop_long;!Xn(r)||!Xn(n)||(t===r.label?n.value=1-r.value:t===n.label&&(r.value=1-n.value))}function wV(e,t){AV(e,t);let r=e.c_l,n=e.c_w,o=e.l_to_d_ratio;!Xn(r)||!Xn(n)||(t===r.label||t===n.label?Xn(o)&&n.value!==0&&(o.value=r.value/n.value):Xn(o)&&t===o.label&&o.value!==0&&(n.value=r.value/o.value))}function Js(e,t,r){let n=!1;for(let o of Object.keys(e)){if(o==="motor"||o==="name")continue;let a=e[o];if(Xn(a)&&ww(a.label)===t){a.value=r,n=!0;break}}return n&&wV(e,t),n}function Gd(e,t,r=0,n,o){let a=()=>({cl:e.c_l.value,cw:e.c_w.value,frontShare:z0(e),A:e.A.value,platform:null});if(!e.aeroModel)return a();let s=Cn(n??jt(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:z0(e),A:s.area,platform:s}}var Lw=e=>typeof e=="object"&&e!==null&&typeof e.value=="number"&&typeof e.label=="string";function Dw(e,t=e.aeroModel){if(!t)return e;let r=mo(t,{wheelbase:ee(e,"wheelbase")}).at(ee(e,"ride_height_front"),ee(e,"ride_height_rear")),{cl:n,balanceFront:o}=Nh(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(Lw(e.cop_long)?e.cop_long:void 0,cn.cop_long,1-o)};return Lw(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 pl={dsTarget:.25,accelStep:.25,vTol:.002,scanSteps:24,seamIters:8,fitSpacing:1},CV=32;function Ew(e,t,r){let n=Math.round(e/t);return Math.max(1,Math.min(Number.isFinite(n)?n:1,Math.floor(r/CV)||1))}function Nt(e){let t=pl,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 Iw=Math.PI/180,Kd=.02,_w=new WeakMap;function fl(e){let t=_w.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)*Iw,l=(e.bank?.[i]??0)*Iw,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 _w.set(e,s),s}function Hd(e,t,r){return e.n0[t]+e.k[t]*r*r}function Nw(e,t){return e.k[t]<0?Math.sqrt(Math.max(0,e.n0[t])/-e.k[t]):1/0}function Ow(e,t){if(!e)return null;let r=1/0,n=-1/0;for(let o=0;o<e.n0.length;o++){let a=Hd(e,o,t[o]??0);a<r&&(r=a),a>n&&(n=a)}return r>=1-Kd&&n<=1+Kd?null:{lo:r,hi:n}}var ei=[.1,.25,.5,.75,1,1.25,1.5,2,2.5];function Vw(e){let t=e.lo>=1-Kd?1:1-1.25*(1-e.lo)-.05,r=e.hi<=1+Kd?1:1+1.25*(e.hi-1)+.05,n=[...ei].reverse().find(a=>a<=t)??ei[0],o=ei.find(a=>a>=r)??ei[ei.length-1];return ei.filter(a=>a>=n&&a<=o)}function Y0(e,t,r){return r<1?Math.max(e,t):Math.min(e,t)}function Bw(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,d=s.kappaMax===void 0?t.kappaMax:t.kappaMax===void 0?s.kappaMax:Math.min(s.kappaMax,t.kappaMax),p=d!==void 0?{kappaMax:d}:{};return n?{vMax:s.vMax,...p,axAccel:(m,f,h=1,b=1)=>s.axAccel(m,f,h,b)+t.axAccel(u(m),m,f,h,b)-r.axAccel(m,f,h,b),axDecel:(m,f,h=1,b=1)=>{let g=y=>s.axDecel(m,f,h,y)+t.axDecel(u(m),m,f,h,y)-r.axDecel(m,f,h,y);return b===1?g(1):Y0(g(b),g(1),b)},ay:(m,f,h=1)=>Math.max(0,s.ay(m,f,h)+t.ay(u(m),m,f,h)-r.ay(m,f,h)),scrub:(m,f,h=1)=>(s.scrub?.(m,f,h)??0)+t.scrub(u(m),m,f,h)-(r.scrub?.(m,f,h)??0)}:{vMax:s.vMax,...p,axAccel:(m,f,h=1,b=1)=>t.axAccel(u(m),m,f,h,b),axDecel:(m,f,h=1,b=1)=>t.axDecel(u(m),m,f,h,b),ay:(m,f,h=1)=>t.ay(u(m),m,f,h),scrub:(m,f,h=1)=>t.scrub(u(m),m,f,h)}}}function zd(e,t,r,n,o){let a=e.length,s=r?a:a-1,i=S=>r?(S+1)%a:S+1,{brakeAhead:c,apexAhead:l}=FV(e,t,r),u=new Array(a),d=new Array(a),p=new Array(a),m=new Array(a).fill(0),f=0,h=0,b=0,g=Math.max(0,Math.min(1,n.kept)),y=g>=1?0:n.up,x=g>=1?0:n.down,v=4*y*(1-g),k=S=>{let{v:w,gear:F,tau:T,target:A}=S;f=0,h=0,b=0;for(let C=0;C<s;C++){let P=i(C),L=e[P];for(let D=0;T<=0&&D<n.count;D++){let I=F;if(w<L-1e-9?n.best(w)>F&&(n.rpm(w,F)>=n.limitRpm||c[C]>=w*v)?I=F+1:F>0&&w<n.vIdle(F)&&(I=F-1):L<w-1e-9&&F>0&&n.best(l[C])<F&&n.rpm(w,F-1)<=n.limitRpm&&(I=F-1),I===F)break;A=I,I>F?f++:h++,T=I>F?y:x,T<=0&&(F=A)}u[C]=w,d[C]=F+1,p[C]=n.rpm(w,F);let E=T>0;m[C]=E?1:0;let _=L;if(!E)w<L&&(_=Math.min(L,Math.sqrt(Math.max(0,w*w+2*o(C,w,n.share(w,F))*t[C]))));else if(w<L){let D=o(C,w,g>0?g*n.share(w,F):0),I=Math.min(L,Math.sqrt(Math.max(0,w*w+2*D*t[C]))),V=w+I>0?2*t[C]/(w+I):1/0;if(V<=T)_=I,b+=V,T-=V;else{let O=Math.min(L,Math.max(0,w+D*T)),B=Math.max(0,t[C]-(w+O)*.5*T);b+=T,T=0,F=A,_=Math.min(L,Math.sqrt(Math.max(0,O*O+2*o(C,O,n.share(O,F))*B)))}}else{let D=w+_>0?2*t[C]/(w+_):0;b+=Math.min(D,T),T-=D,T<=0&&(F=A)}w=_}return{v:w,gear:F,tau:T,target:A}},R=n.best(e[0]),M={v:e[0],gear:R,tau:0,target:R};if(r)for(let S=0;S<6;S++){let w=k(M),F=Math.abs(w.v-M.v)<=1e-9&&w.gear===M.gear&&w.target===M.target&&Math.abs(w.tau-M.tau)<=1e-12;if(M=w,F)break}else{let S=k(M);u[a-1]=S.v,d[a-1]=S.gear+1,p[a-1]=n.rpm(S.v,S.gear),m[a-1]=S.tau>0?1:0}return{v:u,gear:d,rpm:p,shifting:m,upshifts:f,downshifts:h,gapTime:b}}function FV(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,d=r?(u+1)%n:u+1,p=e[d]<e[u]-1e-9;s=p?0:s+t[u],i=p?Math.min(i,e[d]):e[u],l<n&&(o[u]=s,a[u]=i)}return{brakeAhead:o,apexAhead:a}}var W0=.001,j0=9.81,hl=(e,t)=>Yd(e?.gradient?.[t]??0);function Yd(e){return e===0?0:-j0*Math.sin(e*Math.PI/180)}function ti(e,t){let r=new Array(t);for(let n=0;n<t;n++)r[n]=Yd(e?.[n]??0);return r}function Wd(e,t){let r=e?.[t];return r!=null&&r>0?r:1}var Ao=(e,t)=>Wd(e?.mu,t),ba=(e,t)=>e?.bank?.[t]??0;function TV(e,t,r,n,o,a){let s=e.ay(t,r,Ao(o,a)),i=ba(o,a);if(!i)return s;let c=i*Math.PI/180,l=n===0?0:-Math.sign(n)*j0*Math.sin(c);return Math.max(0,(s+l)/Math.cos(c))}function lt(e,t){if(!t)return e;let r=t*Math.PI/180;return e*Math.cos(r)+j0*Math.sin(r)}function U0(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 qn=(e,t,r)=>t?t(r):e,PV=1e-4;function LV(e,t){let r=Math.abs(t);return e.kappaMax!==void 0&&r>e.kappaMax?e.kappaMax:r}function DV(e,t,r){if(e.kappaMax===void 0&&!t)return;let n=0,o=-1,a=0;for(let i=0;i<r.npts;i++){let c=qn(e,t,i).kappaMax,l=Math.abs(r.curvature[i]);c===void 0||!(l>c)||(n+=r.ds[i],l/c>a&&(a=l/c,o=i))}if(o<0)return;let s=qn(e,t,o).kappaMax;return{length:n,at:r.s[o],radius:1/Math.abs(r.curvature[o]),lockRadius:1/s}}function ri(e,t,r,n,o,a,s){let i=Nt(r),c=[];for(let l=0;l<t.length;l++){let u=t[l],d=qn(e,o,l),p=LV(d,u),m=a!==void 0&&a>0?Math.min(d.vMax,a):d.vMax,f=s?Math.min(m,s(l)):m,h=p<=0?f:U0(b=>b*b*p-TV(d,b,0,u,n,l),W0,f,i.scanSteps,Math.min(i.vTol,PV));c.push({v:h,ax:0,ay:h*h*u})}return c}function EV(e,t,r,n,o,a,s=1,i=0,c=0,l){if(r.v<=t.v)return 0;let u=m=>{let f=lt(m*m*n,c),h=(l?e.axDecel(m,Math.abs(f),s,l(m)):e.axDecel(m,Math.abs(f),s))+i;return Math.sqrt(Math.max(0,m*m+2*h*o))},d=r.v;r.v=U0(m=>u(m)-t.v,W0,r.v,a.scanSteps,a.vTol),r.ay=r.v*r.v*n;let p=Math.abs(lt(r.ay,c));return r.ax=(l?e.axDecel(r.v,p,s,l(r.v)):e.axDecel(r.v,p,s))+i,d-r.v}function IV(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(lt(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 $w(e,t,r,n,o,a){let s=Nt(n),i=r.npts,c=0;for(let l=0;l<s.seamIters;l++){let u=0;c++;for(let d=i-1;d>=0;d--){let p=(d+1)%i;u=Math.max(u,EV(qn(e,o,d),t[p],t[d],r.curvature[d],r.ds[d],s,Ao(r,d),hl(r,d),ba(r,d),a?m=>a(d,m):void 0))}if(u<=s.vTol)break}return c}function Gw(e,t,r,n,o,a){let s=Nt(n),i=r.npts,c=0;for(let l=0;l<s.seamIters;l++){let u=0;c++;for(let d=0;d<i;d++){let p=(d+1)%i;u=Math.max(u,IV(qn(e,o,d),t[p],t[d],r.curvature[d],r.ds[d],Ao(r,d),hl(r,d),ba(r,d),a?a[d]:1))}if(u<=s.vTol)break}return c}function _V(e,t,r){let n=r.load?fl(t):null;if(!n||!r.load)return{pick:r.envelope};let o=t.npts;return{pick:Bw(n,r.load,e,r.envelope),cap:a=>Nw(n,a%o),n:(a,s)=>Hd(n,a,s)}}function Kw(e,t,r,n,o,a,s){return zd(n,r.ds,o,a,(i,c,l)=>{let u=c*c*r.curvature[i];return qn(e,t,i).axAccel(c,Math.abs(lt(u,ba(r,i))),Ao(r,i),s?l*s[i]:l)+hl(r,i)})}function Hw(e,t){return{gear:e.gear.slice(0,t),engineRpm:e.rpm.slice(0,t),shifting:e.shifting.slice(0,t)}}function zw(e,t,r,n){if(!e.scrub)return{};let o=!1,a=n.map((s,i)=>{let c=qn(e,t,i),l=lt(s*s*r.curvature[i],ba(r,i)),u=c.scrub?c.scrub(s,Math.abs(l),Ao(r,i)):0;return u!==0&&(o=!0),u});return o?{axScrub:a}:{}}function er(e,t,r,n={}){let o=Nt(r),a=t.npts,s=t.closed&&!n.standingStart,{pick:i,cap:c,n:l}=_V(e,t,n),u=n.driveDerate,d=n.brakeFade;if(!s)return NV(e,t,o,n.standingStart===!0,i,u,n.vCeiling,d,c,l,n.shifts);let p=ri(e,t.curvature,o,t,i,n.vCeiling,c),m=$w(e,p,t,o,i,d),f=Gw(e,p,t,o,i,u),h=n.shifts?Kw(e,i,t,p.map(v=>v.v),!0,n.shifts,u):void 0;if(h)for(let v=0;v<a;v++)p[v].v=h.v[v];for(let v=0;v<a;v++){let k=p[v];k.ay=k.v*k.v*t.curvature[v];let R=p[(v+1)%a].v;k.ax=(R*R-k.v*k.v)/(2*t.ds[v])}let b=p.map(v=>v.v),g=p.map(v=>v.ax),y=p.map(v=>v.ay),x=0;for(let v=0;v<a;v++){let k=b[v]+b[(v+1)%a];k>0&&(x+=2*t.ds[v]/k)}return{states:p,v:b,ax:g,ay:y,laptime:x,sweeps:{backward:m,forward:f},...l?{loadFactor:b.map((v,k)=>l(k,v))}:{},...zw(e,i,t,b),...h?Hw(h,a):{},...Yw(e,i,t)}}function Yw(e,t,r){let n=DV(e,t,r);return n?{pastLock:n}:{}}function NV(e,t,r,n,o,a,s,i,c,l,u){let d=t.npts,p=t.closed?d:d-1,m=p+1,f=new Array(m);for(let x=0;x<m;x++)f[x]=t.curvature[x%d];let h=ri(e,f,r,t,o,s,c);n&&(h[0].v=0);for(let x=p-1;x>=0;x--){let v=h[x],k=h[x+1];if(v.v<=k.v)continue;let R=qn(e,o,x),M=w=>{let F=lt(w*w*t.curvature[x],ba(t,x)),T=(i?R.axDecel(w,Math.abs(F),Ao(t,x),i(x,w)):R.axDecel(w,Math.abs(F),Ao(t,x)))+hl(t,x);return Math.sqrt(Math.max(0,w*w+2*T*t.ds[x]))},S=n&&x===0?v.v:W0;v.v=U0(w=>M(w)-k.v,S,v.v,r.scanSteps,r.vTol)}for(let x=0;x<p;x++){let v=h[x],k=h[x+1];v.ay=v.v*v.v*t.curvature[x];let R=lt(v.ay,ba(t,x));v.ax=qn(e,o,x).axAccel(v.v,Math.abs(R),Ao(t,x),a?a[x]:1)+hl(t,x),k.v=Math.min(k.v,Math.sqrt(Math.max(0,v.v*v.v+2*v.ax*t.ds[x])))}let b=u?Kw(e,o,t,h.map(x=>x.v),!1,u,a):void 0;if(b)for(let x=0;x<m;x++)h[x].v=b.v[x];let g=0;for(let x=0;x<p;x++){let v=h[x].v+h[x+1].v;v>0&&(g+=2*t.ds[x]/v)}let y=h.slice(0,d);for(let x=0;x<d;x++){let v=y[x];v.ay=v.v*v.v*t.curvature[x];let k=x<p?h[x+1].v:v.v;v.ax=t.ds[x]>0?(k*k-v.v*v.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,v)=>l(v,x.v))}:{},...zw(e,o,t,y.map(x=>x.v)),...b?Hw(b,d):{},...Yw(e,o,t)}}var Ww=(e,t)=>{let r=e[t]?.value;return Number.isFinite(r)&&r>0?r:0};function ga(e,t,r){let n=e.m.value,o=e.r_dyn?.value??0,a=Ww(e,"I_wheel"),s=e.motorModel?.kind==="ice"?0:Ww(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,d=(l*a+s*i*i)/c,p=u*a/c,m=n+d+p;return{mass:n,driven:d,undriven:p,effective:m,powerFactor:n/m,tractionFactor:n/(n+p)}}function ya(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 bl=36e5,qw=Math.PI*2,X0=e=>Math.max(0,Math.min(1,e));function q0(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=Ou(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/qw),l=Math.max(0,i*o/(n*a)),u=r.efficiency(c,l);return u>.01?u:.5}}var jw=new WeakMap;function ni(e){if(e.batteryModel)return e.batteryModel;let t=e.capacity.value,r=e.ocv.value,n=jw.get(e);if(n&&n.capacityAh===t&&n.ocv===r)return n.model;let o=Ah(t,r);return jw.set(e,{capacityAh:t,ocv:r,model:o}),o}function Q0(e){let t=e.params,r=qg(t,Zm(e));if(kt(t.motorModel)||Yt(t).mode!=="hydraulic")return r;let n;return(o,a,s,i=0)=>{if(!(o>0))return 0;n??=OV(e);let c=ad(n.inp,n.ev,o,a,i);return c?Math.min(o,c.regenFront+c.regenRear):r(o,a,s)}}var Uw=new WeakMap;function OV(e){let t=e.params,r=Uw.get(t);if(!r){let n=Bn(t);r={inp:jt(n.regen?t:{...t,energy:{...n,regen:!0}}),ev:un(t)},Uw.set(t,r)}return r}var gl=e=>e.airTempC??lr;function jd(e,t){return e.thermal?e.thermal.startC??t:ss}function Xw(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 Qw=()=>({windingC:[],derate:[],lossW:[],torqueNm:[],ampsRms:[]});function VV(e){let t=e.motorModel;if(kt(t))return;let r=t?Ou(t).maxTorque:s=>et(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/qw),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 BV(e,t){let r=e.motorModel?.thermal;if(!r||!t)return;let n=r.torqueConstant;return{...t,th:wh(r),amps:o=>n>0?Math.abs(o)/n:0}}function $V(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 d=e.currentFor(l,n,o),p=u?c/l:1,m=r*p;return{dq:d*m,lossJ:d*d*e.resistance(n,o)*m,energyJ:l*m,short:c>i,cutoff:u,seconds:m}}function GV(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 KV(e){let{drivenFront:t,drivenRear:r}=ya(e);return ga(e.params,t,r)}function oi(e,t,r,n,o=Vn,a,s,i,c,l,u){let d=e.params,p=d.rho.value,m=d.fr_0.value,f=d.m.value,h=e.FG,b=d.aeroModel?jt(d):void 0,g=q0(d),y=An(ni(d)),x=y.chargeC,v=d.motorModel?.kind==="ice",k=X0(a??(v?1:d.soc.value)),R=gl(d),M=s??jd(y,R),S=M,w=0,F=0,T=0,A=0,C=-1,P=-1,L=-1,E=i||d.motorModel?.thermal?VV(d):void 0,_=BV(d,E),D=_?_.th.startC:0,I=D,V=0,O=1,B=-1,z=0,j=0,$=Q0(e),N=u?.scrub,W=KV(e),Z=N?f/W.tractionFactor:0,q=W.effective-f,Y=Math.min(t.length,r.length);for(let K=0;K<Y;K++){let ne=r[K],U=ne*ne,Q=n[K]-(c?.[K]??0),{cl:se,cw:de,A:ue}=Gd(d,ne,Q/9.81,b),ie=.5*p*se*ue*U,ve=.5*p*de*ue*U,Ie=(h+ie)*-m,je=N?-Z*(N[K]??0):0,te=Ie+ve+je+f*Q;q>0&&(te+=q*n[K]);let ae=te*t[K];l?.driveN?.push(te>0?te:0);let Ce=K+1<r.length?r[K+1]:ne,pe=.5*(ne+Ce),me=pe>0?t[K]/pe:0,xe=0,ge=k,ke=M,Re=0,ye=0,Me=me;if(v){te>0&&(ye=ae/g(ne,te),w+=ye/bl),l?.netKwh.push(w-F),l?.powerKw?.push(me>0?ye/me/1e3:0);continue}if(te>0){let fe=ae/g(ne,te),be=$V(y,fe,me,k,M);be.short&&C<0&&(C=K),be.cutoff&&P<0&&(P=K);let Te=k*x,Fe=Math.min(be.dq,Te),Gt=be.dq>0?Fe/be.dq:1;Fe>=Te&&L<0&&(L=K),w+=be.energyJ*Gt/bl,ye=be.energyJ*Gt,Me=be.seconds,T+=be.lossJ*Gt,A+=Fe,me>0&&(Re=Fe/be.seconds),k=X0(k-Fe/x),M=Xw(y,M,be.dq>0&&me>0?Fe/me:0,be.lossJ*Gt,me,R),M>S&&(S=M),xe=te}else if(o.regen){let fe=u?lt(u.ay[K],u.bank?.[K]??0)/9.81:0,be=$(-te,ne,Q/9.81,fe),Te=o.regenEfficiency*be*t[K],Fe=GV(y,Te,me,k,M),Gt=(1-k)*x,mt=Math.min(Fe.dq,Gt),Kt=Fe.dq>0?mt/Fe.dq:1;F+=Fe.energyJ*Kt/bl,ye=-Fe.energyJ*Kt,T+=Fe.lossJ*Kt,A-=mt,me>0&&(Re=-mt/me),k=X0(k+mt/x),M=Xw(y,M,mt>0&&me>0?-mt/me:0,Fe.lossJ*Kt,me,R),M>S&&(S=M),xe=-be*Kt}if(l?.netKwh.push(w-F),l?.powerKw?.push(me>0?ye/Me/1e3:0),l?.pack){let fe=l.pack;fe.soc.push(ge),fe.amps.push(Re),fe.volts.push(y.ocv(ge)-Re*y.resistance(ge,ke)),fe.cellC.push(ke)}if(_){let fe=_.rpm(ne),be=_.th.derate(fe,D,_.peak(fe));be<O&&(O=be),be<1&&B<0&&(B=K),j+=me,be<1&&(z+=me);let Te=_.torque(xe,fe,be),Fe=_.th.lossW(fe,Te,D);V+=Fe*me,i&&(i.windingC.push(D),i.derate.push(be),i.lossW.push(Fe),i.torqueNm.push(Te),i.ampsRms.push(_.amps(Te))),D=_.th.step(D,Fe,me),D>I&&(I=D)}else E&&i&&i.torqueNm.push(E.torque(xe,E.rpm(ne),1))}return{drive:w,regen:F,net:w-F,chargeAh:A/3600,loss:T/bl,socEnd:k,shortAt:C,cutoffAt:P,emptyAt:L,tempEndC:M,tempMaxC:S,..._?{motorTempEndC:D,motorTempMaxC:I,motorLossKwh:V/bl,motorDerateMin:O,motorDerateAt:B,motorDerateTimeFrac:j>0?z/j:0}:{}}}var HV=.5,zV=.02,YV=6;function Zw(e,t,r,n,o,a,s,i){let c=n(),l=1,u=f=>{let h=Qw(),b=oi(e,t,f.v,f.ax,r,o,a,h,s,void 0,{ay:f.ay,bank:i,...f.axScrub?{scrub:f.axScrub}:{}});return{trace:h,peak:b.motorTempMaxC??0,frac:b.motorDerateTimeFrac??0}},d=u(c);if(!d.trace.derate.length||d.frac===0)return{lap:c,solves:l,converged:!0,peakWindingC:d.peak,derateTimeFrac:d.frac};let p=d.trace.derate.slice(),m=!1;for(let f=0;f<YV;f++){let h=n(p);l++;let b=Math.abs(h.laptime-c.laptime);if(c=h,d=u(c),b<zV){m=!0;break}let g=d.trace.derate,y=new Array(p.length);for(let x=0;x<p.length;x++)y[x]=p[x]+HV*((g[x]??1)-p[x]);p=y}return{lap:c,derate:p,solves:l,converged:m,peakWindingC:d.peak,derateTimeFrac:d.frac}}var WV=.1;function Jw(e){if(e.motorModel?.kind==="ice")return 0;let t=e.power_limit_kw?.value??0;return t>0?t*1e3:0}function Z0(e,t,r){return e.motorModel?.kind==="ice"?1/0:An(ni(e)).maxPower(t??e.soc.value,r,Jw(e)).watts}function Ud(e,t,r,n){let o=Z0(e,r,n);if(!Number.isFinite(o))return 1/0;if(o<=0)return 0;let a=Math.max(WV,t),s=q0(e),i=o*.9/a;return o*s(t,i)/a}var jV=180/Math.PI;function Xd(e,t,r,n){let o=e*t,a=e*(1-t);return o/r-a/n}var qd=e=>e*9.81*jV;var UV=.1*9.81;var hne=Math.PI/180;function Qd(e,t,r,n=0){let o=We(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?Xd(e.massTotal,e.frontMassFrac,2*i,2*c):0,u=qd(l),d=u>.15?"understeer":u<-.15?"oversteer":"neutral";return{gradient:u,balance:d,cAlphaFront:i,cAlphaRear:c}}var Mne=Math.PI/180,Sne=180/Math.PI;var eC=2220446049250313e-31;function QV(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 d=1/l;for(let p=0;p<t;p++)e[a][p]*=d;for(let p=0;p<t;p++)e[p][a]*=l}}}}}function ZV(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 JV(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])<=eC*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],d=e[a][a-1]*e[a-1][a];if(c===a-1){let p=.5*(u-l),m=p*p+d,f=Math.sqrt(Math.abs(m));l+=s,m>=0?(f=p+(p>=0?Math.abs(f):-Math.abs(f)),r[a-1]=r[a]=l+f,f!==0&&(r[a]=l-d/f),n[a-1]=n[a]=0):(r[a-1]=r[a]=l+p,n[a]=f,n[a-1]=-f),a-=2}else{if(i===60)throw new Error("eigenvalues: QR iteration did not converge");if(i===10||i===20||i===30||i===40||i===50){s+=l;for(let g=0;g<=a;g++)e[g][g]-=l;let b=Math.abs(e[a][a-1])+Math.abs(e[a-1][a-2]);u=l=.75*b,d=-.4375*b*b}i++;let p=a-2,m=0,f=0,h=0;for(;p>=c;p--){let b=e[p][p],g=l-b,y=u-b;m=(g*y-d)/e[p+1][p]+e[p][p+1],f=e[p+1][p+1]-b-g-y,h=e[p+2][p+1];let x=Math.abs(m)+Math.abs(f)+Math.abs(h);if(m/=x,f/=x,h/=x,p===c)break;let v=Math.abs(e[p][p-1])*(Math.abs(f)+Math.abs(h)),k=Math.abs(m)*(Math.abs(e[p-1][p-1])+Math.abs(b)+Math.abs(e[p+1][p+1]));if(v<=eC*k)break}for(let b=p+2;b<=a;b++)e[b][b-2]=0,b!==p+2&&(e[b][b-3]=0);for(let b=p;b<=a-1;b++){b!==p&&(m=e[b][b-1],f=e[b+1][b-1],h=b!==a-1?e[b+2][b-1]:0,l=Math.abs(m)+Math.abs(f)+Math.abs(h),l!==0&&(m/=l,f/=l,h/=l));let g=Math.sqrt(m*m+f*f+h*h),y=m>=0?g:-g;if(y!==0){b===p?c!==p&&(e[b][b-1]=-e[b][b-1]):e[b][b-1]=-y*l,m+=y,l=m/y,u=f/y;let x=h/y;f/=m,h/=m;for(let k=b;k<=a;k++){let R=e[b][k]+f*e[b+1][k];b!==a-1&&(R+=h*e[b+2][k],e[b+2][k]-=R*x),e[b+1][k]-=R*u,e[b][k]-=R*l}let v=a<b+3?a:b+3;for(let k=c;k<=v;k++){let R=l*e[k][b]+u*e[k][b+1];b!==a-1&&(R+=x*e[k][b+2],e[k][b+2]-=R*h),e[k][b+1]-=R*f,e[k][b]-=R}}}}}}while(c<a-1&&a>=0)}return r.map((i,c)=>({re:i,im:n[c]}))}function tC(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 QV(r),ZV(r),JV(r)}function rC(e){let t=[],r=new Array(e.length).fill(!1),n=tC(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 J0(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,d=-1;for(let h=c;h<r;h++)for(let b=c;b<r;b++){let g=e[h][b]*e[h][b]+t[h][b]*t[h][b];g>d&&(d=g,l=h,u=b)}if(!(d>0))break;if([e[c],e[l]]=[e[l],e[c]],[t[c],t[l]]=[t[l],t[c]],u!==c){for(let h=0;h<r;h++)[e[h][c],e[h][u]]=[e[h][u],e[h][c]],[t[h][c],t[h][u]]=[t[h][u],t[h][c]];[n[c],n[u]]=[n[u],n[c]]}let p=e[c][c],m=t[c][c],f=p*p+m*m;for(let h=c+1;h<r;h++){let b=(e[h][c]*p+t[h][c]*m)/f,g=(t[h][c]*p-e[h][c]*m)/f;if(!(b===0&&g===0))for(let y=c;y<r;y++)e[h][y]-=b*e[c][y]-g*t[c][y],t[h][y]-=b*t[c][y]+g*e[c][y]}}let o=new Array(r).fill(0),a=new Array(r).fill(0);o[r-1]=1;for(let c=r-2;c>=0;c--){let l=e[c][c],u=t[c][c],d=l*l+u*u;if(!(d>0))continue;let p=0,m=0;for(let f=c+1;f<r;f++)p+=e[c][f]*o[f]-t[c][f]*a[f],m+=e[c][f]*a[f]+t[c][f]*o[f];o[c]=-(p*l+m*u)/d,a[c]=-(m*l-p*u)/d}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 e3(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 J0(r,n)}function Zd(e,t=r=>e3(e,r)){return rC(e).map(r=>({...r,vector:t(r.eigenvalue)}))}function xa(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 nC(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),d=r*(l[2].re**2+l[2].im**2);return u+d>0?[u/(u+d),d/(u+d)]:[0,0]};return xa(Zd(i),c,0)}function oC(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=nC({sprungMass:o,unsprungMass:e.unsprungCornerMass??e.unsprungPerCorner,springRate:s,damperRate:n,tireRate:yt(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 Jd(e,t,r){let n=Ge(e);return{front:oC(e,n,"front",t??n.rideDampingFront),rear:oC(e,n,"rear",r??n.rideDampingRear)}}var One=180/Math.PI;var ey=["FL","FR","RL","RR"];function t3(e,t){let r=e.chassisTorsion??0;if(!(r>0)||!Number.isFinite(r))return;let n=Math.max(0,Math.min(1,e.frontMassFrac));return{stiffness:r*(180/Math.PI),inertiaFront:e.twistInertiaFront??n*t,inertiaRear:e.twistInertiaRear??(1-n)*t,massFront:n}}function r3(e){let t=e.chassis;if(!t||!(t.stiffness>0)||!(t.inertiaFront>0)||!(t.inertiaRear>0))return;let r=t.inertiaFront+t.inertiaRear,n=t.inertiaRear/r,o=-t.inertiaFront/r;return{share:[n,n,o,o],inertia:t.inertiaFront*t.inertiaRear/r,stiffness:t.stiffness,moment:t.massFront*n+(1-t.massFront)*o}}var ce={zFL:0,vzFL:1,zFR:2,vzFR:3,zRL:4,vzRL:5,zRR:6,vzRR:7,zBody:8,vzBody:9,pitch:10,pitchRate:11,roll:12,rollRate:13,x:14,vx:15,y:16,vy:17,yaw:18,yawRate:19,twist:20,twistRate:21},ep=20,aC=[ce.zFL,ce.zFR,ce.zRL,ce.zRR],sC=[ce.vzFL,ce.vzFR,ce.vzRL,ce.vzRR],mn={fzFL:0,fzFR:1,fzRL:2,fzRR:3,fzBody:4,myBody:5,mxBody:6,fx:7,fy:8,mz:9},ty=10;function tp(e){let t=r3(e),r=t?ep+2:ep,n=Array.from({length:r},()=>new Array(r).fill(0)),o=Array.from({length:r},()=>new Array(ty).fill(0));n[ce.zFL][ce.vzFL]=1,n[ce.zFR][ce.vzFR]=1,n[ce.zRL][ce.vzRL]=1,n[ce.zRR][ce.vzRR]=1,n[ce.zBody][ce.vzBody]=1,n[ce.pitch][ce.pitchRate]=1,n[ce.roll][ce.rollRate]=1,n[ce.x][ce.vx]=1,n[ce.y][ce.vy]=1,n[ce.yaw][ce.yawRate]=1;let{inertia:a}=e,s=[1,0,3,2],i=(c,l,u,d)=>{c[aC[l]]-=u,c[sC[l]]-=d,c[ce.zBody]+=u,c[ce.vzBody]+=d,c[ce.pitch]-=u*e.leverX[l],c[ce.pitchRate]-=d*e.leverX[l],c[ce.roll]+=u*e.leverY[l],c[ce.rollRate]+=d*e.leverY[l],t&&(c[ce.twist]+=u*e.leverY[l]*t.share[l],c[ce.twistRate]+=d*e.leverY[l]*t.share[l])};for(let c=0;c<4;c++){let l=c<2,u=w=>w?l?w.front:w.rear:0,d=e.springRate[c]+u(e.heaveSpring),p=e.springRate[c]+u(e.arb),m=e.damperRate[c]+u(e.heaveDamper),f=e.damperRate[c]+u(e.rollDamper),h=(d+p)/2,b=(d-p)/2,g=(m+f)/2,y=(m-f)/2,x=new Array(r).fill(0);i(x,c,h,g),(b!==0||y!==0)&&i(x,s[c],b,y);let v=e.wheelMass[c],k=e.leverX[c],R=e.leverY[c],M=aC[c],S=sC[c];for(let w=0;w<r;w++){let F=x[w];F!==0&&(n[S][w]+=F/v,n[ce.vzBody][w]-=F/e.bodyMass,n[ce.pitchRate][w]+=k*F/a.yy,n[ce.rollRate][w]-=R*F/a.xx,t&&(n[ce.twistRate][w]-=R*t.share[c]*F/t.inertia))}n[S][M]-=e.tyreRate[c]/v,n[S][S]-=e.tyreDamping[c]/v,o[S][mn.fzFL+c]=1/v}return o[ce.vzBody][mn.fzBody]=1/e.bodyMass,o[ce.pitchRate][mn.myBody]=1/a.yy,o[ce.rollRate][mn.mxBody]=1/a.xx,o[ce.vx][mn.fx]=1/e.totalMass,o[ce.vy][mn.fy]=1/e.totalMass,o[ce.yawRate][mn.mz]=1/a.zz,t?(n[ce.twist][ce.twistRate]=1,n[ce.twistRate][ce.twist]-=t.stiffness/t.inertia,o[ce.twistRate][mn.mxBody]=t.moment/t.inertia,{A:n,B:o,params:e,n:r,twist:t}):{A:n,B:o,params:e,n:r}}function ry(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,d=(e.damperRear??2.5)*1e3,p=yt(e,"front")*1e3,m=yt(e,"rear")*1e3,f=(e.tireDamping??0)*1e3,h=e.rollInertia??i*.6*.6,b=t3(e,h);return{bodyMass:i,totalMass:e.massTotal,wheelMass:[s,s,s,s],inertia:{xx:h,yy:e.pitchInertia??i*1.2*1.2,zz:e.yawInertia??e.massTotal*1.2*1.2},...b?{chassis:b}:{},leverX:[r,r,-n,-n],leverY:[o,-o,a,-a],springRate:[c,c,l,l],damperRate:[u,u,d,d],tyreRate:[p,p,m,m],tyreDamping:[f,f,f,f],arb:{front:e.arbFront*1e3,rear:e.arbRear*1e3},heaveSpring:{front:(e.heaveSpringFront??0)*1e3,rear:(e.heaveSpringRear??0)*1e3},rollDamper:{front:(e.rollDamperFront??0)*1e3,rear:(e.rollDamperRear??0)*1e3},heaveDamper:{front:(e.heaveDamperFront??0)*1e3,rear:(e.heaveDamperRear??0)*1e3}}}function iC(e){let t=Array.from({length:ce.rollRate+1},(r,n)=>n);return e.twist?[...t,ce.twist,ce.twistRate]:t}function cC(e){let t=e.params,r=e.twist,n=[...t.wheelMass,t.bodyMass,t.inertia.yy,t.inertia.xx,...r?[r.inertia]:[]];if(!n.every(u=>u>0))return{};let o=iC(e),a=o.map(u=>o.map(d=>e.A[u][d]));if(!a.every(u=>u.every(Number.isFinite)))return{};let i=Zd(a,u=>{let d=u.re*u.re-u.im*u.im,p=2*u.re*u.im,m=n.map((h,b)=>n.map((g,y)=>(b===y?d:0)-u.re*a[2*b+1][2*y+1]-a[2*b+1][2*y])),f=n.map((h,b)=>n.map((g,y)=>(b===y?p:0)-u.im*a[2*b+1][2*y+1]));return J0(m,f)}),c=u=>{let d=n.map((m,f)=>m*(u[f].re**2+u[f].im**2)),p=d.reduce((m,f)=>m+f,0)||1;return[d[0]+d[1]+d[2]+d[3],d[4],d[5],d[6],...r?[d[7]]:[]].map(m=>m/p)},l={heave:xa(i,c,1),pitch:xa(i,c,2),roll:xa(i,c,3)};return r?{...l,twist:xa(i,c,4)}:l}var mC=Math.SQRT2;function lC(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 rp(e){let t=Ge(e),r=e.wheelbase/1e3,n=r*(1-e.frontMassFrac),o=r*e.frontMassFrac,a=t.rollRateTotal*(180/Math.PI),s=e.rollInertia??t.sprungMass*.6*.6,i=2*t.rideRateFront*1e3,c=2*t.rideRateRear*1e3,l=i*n*n+c*o*o,u=e.pitchInertia??t.sprungMass*1.2*1.2,d=tp(ry(e)),p=cC(d),m={roll:lC(p.roll,a,s),pitch:lC(p.pitch,l,u)},f=n3(d,p.twist,e);return f?{...m,twist:f}:m}function uC(e,t,r){let n=e.params,o=n.tyreRate[t]+n.springRate[t]+r;return Math.sqrt(Math.max(0,o)/n.wheelMass[t])/(2*Math.PI)}function n3(e,t,r){let n=e.twist;if(!n||!t)return;let o=uC(e,0,e.params.arb?.front??0),a=uC(e,2,e.params.arb?.rear??0),s=Math.max(o,a),i=s>0?t.freq/s:NaN;return{freq:t.freq,dampingRatio:t.dampingRatio,freeFree:Math.sqrt(n.stiffness/n.inertia)/(2*Math.PI),hopFront:o,hopRear:a,hop:s,ratio:i,meets:i>=mC,lumped:r.twistInertiaFront===void 0||r.twistInertiaRear===void 0}}var np=9.81,Qn=Math.PI/180;function dC(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 ai(e,t,r,n,o){let{wb:a,lf:s,lr:i,m:c}=dC(e),l=0;for(let x=0;x<16;x++){let v=l/r,k=o-n-s*v/r,R=-n+i*v/r,M=We(e,l/np,0,r),S=Math.max(0,M.FL+M.FR),w=Math.max(0,M.RL+M.RR),F=t(k,S),T=t(R,w),A=(F*Math.cos(o)+T)/c;if(l=.5*(l+A),Math.abs(A-l)<1e-4)break}let u=l/r,d=o-n-s*u/r,p=-n+i*u/r,m=We(e,l/np,0,r),f=Math.max(0,m.FL+m.FR),h=Math.max(0,m.RL+m.RR),b=t(d,f),g=t(p,h),y=s*b*Math.cos(o)-i*g;return{ay:l/np,cn:y/(c*np*a)}}function ny(e,t,r,n={}){let o=Math.max(8,r),a=(n.betaMaxDeg??10)*Qn,s=(n.deltaMaxDeg??10)*Qn,i=n.nLines??9,c=n.nPts??21,l=(g,y,x,v)=>x===1?g:g+(y-g)*v/(x-1),u=[],d={ay:[],cn:[]},p=0;for(let g=0;g<i;g++){let y=l(-s,s,i,g),x=[],v=[],k=[],R=[];for(let M=0;M<c;M++){let S=l(-a,a,c,M),w=ai(e,t,o,S,y);x.push(w.ay),v.push(w.cn),k.push(S/Qn),R.push(y/Qn),Math.abs(w.ay)>p&&(p=Math.abs(w.ay))}u.push({label:`\u03B4 ${(y/Qn).toFixed(0)}\xB0`,ay:x,cn:v,betaDeg:k,deltaDeg:R});for(let M=1;M<v.length;M++)if(v[M-1]===0||v[M-1]<0!=v[M]<0){let S=v[M-1]===v[M]?0:v[M-1]/(v[M-1]-v[M]);d.ay.push(x[M-1]+S*(x[M]-x[M-1])),d.cn.push(0);break}}let m=[];for(let g=0;g<i;g++){let y=l(-a,a,i,g),x=[],v=[],k=[],R=[];for(let M=0;M<c;M++){let S=l(-s,s,c,M),w=ai(e,t,o,y,S);x.push(w.ay),v.push(w.cn),k.push(y/Qn),R.push(S/Qn)}m.push({label:`\u03B2 ${(y/Qn).toFixed(0)}\xB0`,ay:x,cn:v,betaDeg:k,deltaDeg:R})}let f=.5*Qn,h=(ai(e,t,o,f,0).cn-ai(e,t,o,-f,0).cn)/(2*f),b=(ai(e,t,o,0,f).cn-ai(e,t,o,0,-f).cn)/(2*f);return{isoBeta:m,isoDelta:u,trim:d,maxAy:p,stability:h,control:b,speed:o}}function o3(e){return!e.corneringStiffnessFront||!e.corneringStiffnessRear?null:{Cf:2*e.corneringStiffnessFront,Cr:2*e.corneringStiffnessRear}}function yl(e,t){let r=o3(e);if(!r)return null;let{Cf:n,Cr:o}=r,{wb:a,lf:s,lr:i,m:c}=dC(e),l=e.yawInertia??c*1*1,u=Math.max(3,t),d=-(n+o)/(c*u),p=(-s*n+i*o)/(c*u)-u,m=(-s*n+i*o)/(l*u),f=-(s*s*n+i*i*o)/(l*u),h=d+f,b=d*f-p*m,g=h*h-4*b,y,x,v;if(g<0)y=h/2,x=Math.sqrt(Math.max(0,b)),v=x>0?-h/(2*x):1;else{let P=Math.sqrt(g);y=Math.max((h+P)/2,(h-P)/2),x=Math.sqrt(Math.abs(b)),v=x>0?-h/(2*x):1}let k=h<0&&b>0,R=Xd(c,e.frontMassFrac,n,o),M=qd(R),S=M>.15?"understeer":M<-.15?"oversteer":"neutral",w=s*n-i*o,F=P=>P*3.6,T=null,A=null;w>1e-6?A=F(Math.sqrt(n*o*a*a/(c*w))):w<-1e-6&&(T=F(Math.sqrt(n*o*a*a/(c*-w))));let C=u/(a+R*u*u);return{stable:k,yawFreq:x/(2*Math.PI),dampingRatio:v,eigReal:y,understeerGradient:M,balance:S,characteristicSpeed:T,criticalSpeed:A,yawRateGain:C}}var a3={envelopeTrim:{name:"Grip envelope, trim",code:"`solvePoint` in src/core/dynamics/twoTrack.ts (`twoTrackLimitState`, `twoTrackStateAtAy`)"},envelopeLimits:{name:"Grip envelope, limits",code:"`calcGGV` in src/core/laptime/ggv.ts"},qssLap:{name:"QSS lap",code:"`solveLap` in src/core/laptime/solver.ts, with its energy (`energyOverPath`)"},tyreReadouts:{name:"Tyre readouts",code:"`lapReserves` in src/core/dynamics/lapReserve.ts"},transientPlant:{name:"Transient plant",code:"`dynamicReplay` in src/core/dynamics/dynamicReplay.ts"},plannerRequest:{name:"Optimal, the request",code:"`planCarFrom` in src/core/plan/request.ts"},ymd:{name:"Yaw moment diagram",code:"`twoTrackYMD` in src/core/dynamics/twoTrack.ts"},stepSteer:{name:"Step steer",code:"`steerRun` in src/core/dynamics/steerRun.ts"},drive:{name:"Drive",code:"`liveCar` in src/core/drive/liveCar.ts"}},oy=Object.keys(a3),xl=["envelopeTrim","envelopeLimits","qssLap","tyreReadouts","ymd"];var s3="the longitudinal condition is set directly; what a motor could deliver is the lap solver\u2019s question",i3="no tractive force is applied at a constant speed",ay="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)",sy="Drive runs no torque vectoring: its aids are ABS and traction control",pC="the readouts split the drive by room or through the diff, never by a controller",c3=[{key:"damper_front",tools:["ymd"],why:"dampers act on velocity; every point here is at constant attitude"},{key:"damper_rear",tools:["ymd"],why:"dampers act on velocity; every point here is at constant attitude"},{key:"tire_vertical_damping",tools:xl,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:xl,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:xl,why:"inertia resists change; a steady corner has none"},{key:"I_pitch",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no pitch dynamics (reduced planner model)"},...["I_twist_front","I_twist_rear"].flatMap(e=>[{key:e,tools:xl,why:"inertia resists change; a steady corner has none"},{key:e,tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no twist dynamics (reduced planner model)"}]),...["capacity","ocv","soc"].flatMap(e=>[{key:e,tools:["ymd"],why:"energy does not enter a single steady-state point"},{key:e,tools:oy.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:xl,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:ay},{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:sy},{key:"tv_enabled",tools:["transientPlant","stepSteer"],why:ay},{key:"tv_enabled",tools:["drive"],why:sy},{key:"tv_enabled",tools:["tyreReadouts"],why:pC,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:ay},{key:e,tools:["drive"],why:sy},{key:e,tools:["tyreReadouts"],why:pC,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:i3,ymd:{moving:s3}})),...["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:oy.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:oy.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 fC(e=0){let t=[],r=new Set;for(let n of c3){if(!n.tools.includes("ymd")||n.onCar||r.has(n.key)||e<0&&n.ymd?.liveBraking)continue;r.add(n.key);let o=e>0?n.ymd?.driving??n.ymd?.moving??n.why:e<0?n.ymd?.moving??n.why:n.why;t.push({key:n.key,why:o})}return t}var hC=Math.PI/180;function yC(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 bC(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 xC(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[d,p]of[[s,1-c],[Math.min(o-1,s+1),c]])if(!(p<=0))for(let[m,f]of[[i,1-l],[Math.min(a-1,i+1),l]])f<=0||(u+=p*f*n(e.isoDelta[d],m,d));return u}function RC(e,t,r){let n=e.isoDelta[0],o=(n.betaDeg[1]-n.betaDeg[0])*hC||1,a=e.isoDelta.length>1?(e.isoDelta[1].deltaDeg[0]-e.isoDelta[0].deltaDeg[0])*hC:1,s=R=>xC(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]),d=s((R,M)=>bC(R.cn,M,o)),p=s((R,M,S)=>bC(e.isoDelta.map(w=>w.cn[M]),S,a||1)),m=Math.max(1e-6,e.maxAy),f=Math.abs(i)/m,h=Math.max(1e-6,...e.isoDelta.flatMap(R=>R.cn.filter(Number.isFinite).map(Math.abs))),b=Math.abs(c)/h,g=i===0?c:c*Math.sign(i),y=[];y.push(`${yC(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?d/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 v=Math.abs(e.control),k=v>1e-9?Math.abs(p)/v:1;return k<.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."):k<.5&&y.push(`Steering response is down to about ${(100*k).toFixed(0)} % of its straight-ahead value \u2014 the front is well into the non-linear part of its curve.`),f>.97?y.push(`At the edge of the diagram: ${Math.abs(i).toFixed(2)} g is essentially all this car has at this speed.`):f<.25&&y.push("Well inside the limit \u2014 this is the linear region the handling balance is measured in."),{ay:i,cn:c,betaDeg:l,deltaDeg:u,stability:d,control:p,gripUsed:f,notes:y}}var gC=1e-4;function iy(e){let t=null,r=p=>{if(!t)return!0;let m=Math.abs(p),f=Math.abs(t.ay);return m>f*(1+gC)?!0:m<f*(1-gC)?!1:p>0&&t.ay<0};for(let p=0;p<e.isoDelta.length;p++){let m=e.isoDelta[p];for(let f=1;f<m.cn.length;f++){if(!(m.cn[f-1]===0||m.cn[f-1]<0!=m.cn[f]<0))continue;let b=m.cn[f-1]===m.cn[f]?0:m.cn[f-1]/(m.cn[f-1]-m.cn[f]),g=m.ay[f-1]+b*(m.ay[f]-m.ay[f-1]);r(g)&&(t={ay:g,d:p,b:b<.5?f-1:f})}}if(!t)return null;let n=RC(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,d=t.ay<0?-1:1;return{ay:Math.abs(t.ay),turn:d,betaDeg:e.isoDelta[t.d].betaDeg[t.b]*d,deltaDeg:e.isoDelta[t.d].deltaDeg[t.b]*d,d:t.d,b:t.b,limitedBy:c,controlFrac:o,stiffnessFrac:a,onGridEdge:u}}function vC(e=0){return fC(e)}var l3=vC(0);function kC(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 u3=kC(0);var m3=9.81;function d3(e){let t=e.wheelbase/1e3;return{lf:t*(1-e.frontMassFrac),lr:t*e.frontMassFrac}}function Rl(e,t,r,n){let o=t.tire;if(!o)return null;let s=(r==="limit"?k0(e,o,t.speed):ko(e,o,t.speed,t.ayG)).wheels;return Dn(n??ia(o,e.massTotal*m3*1.2),{FL:s.FL,FR:s.FR,RL:s.RL,RR:s.RR},d3(e))}function p3(e){if(!e.tire)return e.cornerStiffness;let t=we(e.tire,"front"),r=we(e.tire,"rear");return{front:n=>t.corneringStiffness(n),rear:n=>r.corneringStiffness(n)}}var MC=[{key:"understeer",label:"Understeer gradient",unit:"\xB0/g",compute:(e,t)=>Qd(e,t.ayG,p3(t),t.speed).gradient},{key:"rollGradient",label:"Roll gradient",unit:"\xB0/g",compute:e=>Ge(e).rollGradient},{key:"pitchGradient",label:"Pitch gradient",unit:"\xB0/g",compute:e=>Ge(e).pitchGradient},{key:"tlltdFront",label:"TLLTD front",unit:"%",compute:e=>100*lc(e)},{key:"rollStiffFront",label:"Front roll-stiffness",unit:"%",compute:e=>100*Ge(e).frontRollStiffFrac},{key:"rideFreqFront",label:"Ride freq front",unit:"Hz",compute:e=>Ge(e).rideFreqFront},{key:"rideFreqRear",label:"Ride freq rear",unit:"Hz",compute:e=>Ge(e).rideFreqRear},{key:"rollFreq",label:"Roll-mode freq",unit:"Hz",compute:e=>rp(e).roll.freq},{key:"pitchFreq",label:"Pitch-mode freq",unit:"Hz",compute:e=>rp(e).pitch.freq},{key:"zetaFront",label:"Damping \u03B6 front",unit:"-",compute:e=>Jd(e).front.dampingRatio},{key:"zetaRear",label:"Damping \u03B6 rear",unit:"-",compute:e=>Jd(e).rear.dampingRatio},{key:"yawFreq",label:"Yaw natural freq",unit:"Hz",compute:(e,t)=>yl(e,t.speed)?.yawFreq??NaN},{key:"yawZeta",label:"Yaw damping \u03B6",unit:"-",compute:(e,t)=>yl(e,t.speed)?.dampingRatio??NaN},{key:"stabilitySpeed",label:"Char./critical speed",unit:"km/h",compute:(e,t)=>{let r=yl(e,t.speed);return r?r.criticalSpeed??r.characteristicSpeed??NaN:NaN}},{key:"maxAy",label:"Max lateral accel",unit:"g",compute:(e,t)=>t.fyAxle?ny(e,t.fyAxle,t.speed,{betaMaxDeg:12,deltaMaxDeg:12}).maxAy:NaN},{key:"yawReserveRear",label:"Yaw stability reserve",unit:"N\xB7m",compute:(e,t)=>Rl(e,t,"operating")?.stabil??NaN},{key:"yawReserveFront",label:"Yaw agility reserve",unit:"N\xB7m",compute:(e,t)=>Rl(e,t,"operating")?.agil??NaN},{key:"limitBalance",label:"Limit balance (+US / \u2212OS)",unit:"-",compute:(e,t)=>Rl(e,t,"limit")?.rel??NaN},{key:"yawStiffness",label:"Yaw stiffness N_\u03B2",unit:"N\xB7m/rad",compute:(e,t)=>t.tire?v0(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorque",label:"Steering holding torque",unit:"N\xB7m",compute:(e,t)=>t.tire?x0(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorqueGradient",label:"Steering feedback gradient",unit:"N\xB7m/g",compute:(e,t)=>t.tire?R0(e,t.tire,t.speed,t.ayG):NaN}],cy=Object.fromEntries(MC.map(e=>[e.key,e]));var dn=9.81;function f3(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 h3={front:!1,rear:!0};function si(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*$b(n,t,s):o*Math.sqrt(1-s*s)}function SC(e,t,r,n,o,a,s,i){let c=e[t]+e[r];if(!(c>0))return;let l=si(n,o[t],a[t],i),u=si(n,o[r],a[r],i),d=!(l+u>0);if(d&&(l=n.muX(o[t])*o[t],u=n.muX(o[r])*o[r]),!(l+u>0))return;let p=s?.[t],m=s?.[r];if(p===void 0&&m===void 0){e[t]=c*(l/(l+u)),e[r]=c-e[t];return}let f=[Math.min(l,p??1/0),Math.min(u,m??1/0)],h=d?void 0:AC(n,o,a,t,r,l,u,s,i);if(h&&c>f[0]+f[1]){let b=Math.min(c-h.capC,h.xMax),g=Math.min(a[h.o],h.fyO(b));a[h.c]+=a[h.o]-g,a[h.o]=g,e[h.o]=b,e[h.c]=c-b;return}e[t]=wC(c,f,[l,u])[0],e[r]=c-e[t]}function AC(e,t,r,n,o,a,s,i,c){let l=i[n]??1/0,u=i[o]??1/0,d,p,m;if(l<a&&!(u<s))[d,p,m]=[n,o,s];else if(u<s&&!(l<a))[d,p,m]=[o,n,a];else return;let f=i[d],h=i[p]??1/0,b=e.muX(t[p])*t[p],g=e.muY(t[p])*t[p],y=e.muX(t[d])*t[d],x=e.muY(t[d])*t[d];if(!(b>0&&g>0&&y>0&&x>0))return;let v=(T,A)=>c?lM(c,T,A):Math.sqrt(Math.max(0,1-A*A)),k=(T,A)=>c?$b(c,T,A):Math.sqrt(Math.max(0,1-A*A)),R=T=>g*v(t[p],T/b),M=x*v(t[d],f/y),S=r[d]+r[p]-M,w=Math.min(h,b*k(t[p],0)),F=S<=0?w:Math.max(m,Math.min(w,S<g?b*k(t[p],S/g):0));return{c:d,o:p,capC:f,xMax:F,fyO:R}}function wC(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 CC(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?Gc(b,g,y):s==="own"?b+g:2*Math.min(b,g),u={FL:si(n,t.FL,r.FL,c?.front),FR:si(n,t.FR,r.FR,c?.front),RL:si(o,t.RL,r.RL,c?.rear),RR:si(o,t.RR,r.RR,c?.rear)},d=(b,g)=>u[g],p=l(u.FL,u.FR,a.front),m=l(u.RL,u.RR,a.rear);if(i&&i.total>0&&p+m>0){let b=(R,M)=>Math.min(d(R,M),i.caps[M]??1/0),g=(R,M,S,w,F)=>{let T=M==="FL"?c?.front:c?.rear,A=w||s!=="own"?void 0:AC(R,t,r,M,S,d(R,M),d(R,S),i.caps,T),C=A?A.capC+A.xMax:l(b(R,M),b(R,S),w);return[C,Math.max(F,C)]},[y,x]=g(n,"FL","FR",a.front,p),[v,k]=g(o,"RL","RR",a.rear,m);return wC(i.total,[y,v],[x,k])[0]/i.total}if(p+m>0)return p/(p+m);let f=n.muX(t.FL)*t.FL+n.muX(t.FR)*t.FR,h=o.muX(t.RL)*t.RL+o.muX(t.RR)*t.RR;return f+h>0?f/(f+h):.5}function ly(e,t,r,n){return{car:t?PC(t,r.loadFactor[n]):e,ayTyre:lt(r.ay[n],r.bank?.[n]??0),axCar:r.ax[n]-(r.axGrade?.[n]??0)}}function FC(e,t){if(!e.aero?.model)return 0;let r=Math.min(t.v.length,t.ax.length,t.ay.length),n=t.loadFactor?ap(e):void 0,o=0,a=0;for(let s=0;s<r;s++){let i=t.ds?.[s]??1,c=ly(e,n,t,s);o+=i,Nb(c.car,t.v[s],c.axCar/dn,c.ayTyre/dn)&&(a+=i)}return o>0?a/o:0}function TC(e,t,r){let n=Or(we(t,"front")),o=Or(we(t,"rear")),a=Math.min(r.v.length,r.ax.length,r.ay.length),s=r.loadFactor?ap(e):void 0,i=0,c=0;for(let l=0;l<a;l++){let u=r.ds?.[l]??1,d=ly(e,s,r,l);i+=u;let p=We(d.car,d.ayTyre/dn,d.axCar/dn,r.v[l]);(p.FL>n||p.FR>n||p.RL>o||p.RR>o)&&(c+=u)}return i>0?c/i:0}function op(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=Hs(t,e.massTotal*dn*1.2),l=Ls(c,"front"),u=Ls(c,"rear"),d={mu:1},p=$=>({muX:N=>d.mu*$.muX(N),muY:N=>d.mu*$.muY(N)}),m=r.mu?p(l):l,f=r.mu?u===l?m:p(u):u,h=r.mu?{front:m,rear:f}:c,b=zt(we(t,"front")),g=zt(we(t,"rear")),y=Gb(b,l),x=g===b?y:Gb(g,u),v={front:y,rear:x},k=n.driven??h3,R={front:mr(e,"front",1),rear:mr(e,"rear",1)},M={front:0,rear:0},S=new Array(o),w=new Array(o),F=new Array(o),T=1/0,A=0,C=0,P=Or(b),L=Or(g),E=0,_=0,D=0,I=0,V=0,O=0,B=["FL","FR","RL","RR"],z=n.perWheel?Object.fromEntries(B.map($=>[$,{Fz:new Array(o),alpha:new Array(o),Fy:new Array(o),Fx:new Array(o),Mz:new Array(o),used:new Array(o),FxCap:new Array(o),FyCap:new Array(o)}])):void 0,j=r.loadFactor?ap(e):void 0;for(let $=0;$<o;$++){let N=ly(e,j,r,$),{ayTyre:W,axCar:Z}=N,q=W/dn,Y=We(N.car,q,Z/dn,r.v[$]),K=r.mu?Wd(r.mu,$):1;d.mu=K;let ne=e.massTotal*W,U=ne*i/a,Q=ne*s/a,se=Rc(b,U/K,Y.FL,Y.FR,V),de=Rc(g,Q/K,Y.RL,Y.RR,O);V=se,O=de;let ue={FL:K*Math.abs(b.Fy(se,Y.FL,0)),FR:K*Math.abs(b.Fy(se,Y.FR,0)),RL:K*Math.abs(g.Fy(de,Y.RL,0)),RR:K*Math.abs(g.Fy(de,Y.RR,0))},ie=(Z-(r.axDrag?.[$]??0)-(r.axScrub?.[$]??0))/dn,ve=r.wheelMotor,Ie=ve?Object.fromEntries(B.flatMap(Re=>ve[Re]?[[Re,ve[Re][$]*e.massTotal]]:[])):void 0,je=Ie?{total:ie*dn*e.massTotal,caps:Ie}:void 0,te=ie>0&&k.front?CC(k,Y,ue,m,f,R,"own",je,v):0,ae=r.v[$]*r.v[$],Ce=e.driveline?{Fz:Y,alpha:{front:se,rear:de},curvature:ae>1?r.ay[$]/ae:0,seed:M,...K!==1?{grip:K}:{}}:void 0,pe={...g0(e,ie,r.v[$],t,q,te,Ce,K)};ie>0&&(R.front||SC(pe,"FL","FR",m,Y,ue,Ie,y),R.rear||SC(pe,"RL","RR",f,Y,ue,Ie,x));let me=!1,xe=!1;for(let Re of["FL","FR","RL","RR"]){let ye=(Re==="FL"||Re==="FR"?m:f).muX(Y[Re])*Y[Re];Math.abs(pe[Re])>ye&&(me=!0),Y[Re]>(Re==="FL"||Re==="FR"?P:L)&&(xe=!0)}xe&&(C+=r.ds?.[$]??1);let ge=Dn(h,{FL:{Fz:Y.FL,Fy:ue.FL,Fx:pe.FL},FR:{Fz:Y.FR,Fy:ue.FR,Fx:pe.FR},RL:{Fz:Y.RL,Fy:ue.RL,Fx:pe.RL},RR:{Fz:Y.RR,Fy:ue.RR,Fx:pe.RR}},{lf:s,lr:i});if(S[$]=ge.stabil,w[$]=ge.agil,F[$]=ge.rel,z){let Re=.5*(Y.FL+Y.FR),ye=.5*(Y.RL+Y.RR),Me=m.muX(Re)*Re,fe=f.muX(ye)*ye;for(let be of B){let Te=Y[be],Fe=be==="FL"||be==="FR",Gt=Fe?m:f,mt=Gt.muY(Te)*Te,Kt=Gt.muX(Te)*Te,De=z[be],Be=Fe?se:de;De.Fz[$]=Te,De.alpha[$]=Be,De.Fy[$]=ue[be],De.Fx[$]=pe[be],De.Mz[$]=Te>0?K*(Fe?b:g).Mz(Be,Te,0):0,De.FxCap[$]=Kt,De.FyCap[$]=mt;let gt=mt>0?Math.min(1,Math.abs(ue[be])/mt):0,_e=f3(pe[be],Kt,Fe?Me:fe),Ze=Fe?y:x,Tr=Ze&&Te>0?Ze.reach(Te,Math.sign(pe[be])*_e,gt):1;De.used[$]=Math.hypot(gt,_e)/Tr}}ge.stabil<T&&(T=ge.stabil,A=$);let ke=r.ds?.[$]??1;I+=ke,ge.diff>0&&(E+=ke),me&&(_+=ke),Nb(N.car,r.v[$],Z/dn,q)&&(D+=ke)}return{stabil:S,agil:w,rel:F,minStabil:Number.isFinite(T)?T:0,minStabilAt:A,pastTurnoverFrac:I>0?C/I:0,understeerFrac:I>0?E/I:0,beyondFrac:I>0?_/I:0,aeroOutsideFrac:I>0?D/I:0,wheels:z}}function ap(e){return Object.create(e,{loadFactor:{value:1,writable:!0,enumerable:!0}})}function PC(e,t){return e.loadFactor=t,e}var uy=9.81;function my(e,t,r,n={}){let o=r.v.length,a=e.massTotal,s=Gn(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],d=r.ax[l]-(r.axGrade?.[l]??0),p=d-(r.axDrag?.[l]??0)-(r.axScrub?.[l]??0),m=-a*p;if(!(m>0))continue;let f=lt(r.ay[l],r.bank?.[l]??0)/uy,h=Math.min(.99,Math.max(.01,Bs(e,p/uy,u,t,f)));c.front[l]=m*h,c.rear[l]=m*(1-h);let b=i?ad(e,t,m,u,f):void 0;if(c.regen&&n.regen&&(c.regen[l]=b?Math.min(m,b.regenFront+b.regenRear):n.regen(m,u,d/uy)),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(m,u),u);c.pFront[l]=g.pFront,c.pRear[l]=g.pRear,c.pedalN[l]=g.pedalN}}return c}var Xoe=Math.PI/180;var qoe=ey.map(qc);var Qoe=[ce.zFL,ce.zFR,ce.zRL,ce.zRR];var T3=9.81,P3=.001,L3=.6,D3=2,IC=4;function _C(e,t,r,n=IC){let o=Math.min(e.v.length,t.npts),{ds:a,closed:s}=t,i=r.massTotal*T3*r.wheelbase,c=E3(e.ay.slice(0,o).map((d,p)=>d/Math.max(P3,e.v[p])),a,s,n),l=new Array(o).fill(0),u=new Array(o).fill(0);if(!(i>0))return{demand:l,rdot:u};for(let d=0;d<o;d++){let p=d===0?s?o-1:-1:d-1,m=d===o-1?s?0:-1:d+1;if(p<0||m<0)continue;let f=a[p]+a[d];if(!(f>0))continue;u[d]=e.v[d]*(c[m]-c[p])/f;let h=Math.sign(c[d]);l[d]=h===0?0:h*r.yawInertia*u[d]/i}return{demand:l,rdot:u}}function E3(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],d=1,p=0;for(let m=1;m<=s&&!(!r&&c+m>=o||(p+=t[(c+m-1)%o],!(p<l)));m++){let f=1-p/l;u+=f*e[(c+m)%o],d+=f}p=0;for(let m=1;m<=s&&!(!r&&c-m<0);m++){let f=(c-m+o)%o;if(p+=t[f],!(p<l))break;let h=1-p/l;u+=h*e[f],d+=h}i[c]=u/d}return i}function NC(e,t,r,n,o={}){let a=o.maxIter??20,s=o.tol??.001,i=Math.min(1,Math.max(.001,o.relax??L3)),c=o.smoothM??IC,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=er(e.steady,t,n,l),d=[u.laptime],p=new Array(t.npts).fill(0),m=p.slice(),f=u,h=0,b=!1,g=0;for(let v=0;v<a;v++){h=v+1;let k=_C(f,t,r,c);p=k.demand.map((S,w)=>p[w]+i*(S-p[w])),m=k.rdot;let R=er(e.steady,t,n,{...l,envelope:S=>e.at(p[S]??0)});d.push(R.laptime);let M=Math.abs(R.laptime-f.laptime);if(f=R,g=M<=s?g+1:0,g>=D3){b=!0;break}}let y=0,x=0;for(let v=0;v<t.npts;v++)x+=t.ds[v],e.clamps(p[v]??0)&&(y+=t.ds[v]);return{...f,steady:u,demand:p,rdot:m,history:d,iterations:h,converged:b,clampedFrac:x>0?y/x:0}}var sae=Math.PI/180;var Wae=180/Math.PI;function VC(e,t,r){let n=e.length-1;if(!(r<e[n]))return t[n];let o=0,a=n;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function q3(e,t,r,n,o){let a=e.grip(o),s=t.atLock?n*n/t.ayMax:e.lockRadius,i=a*r.ayMax,c=s>0&&Number.isFinite(s)?o*o/s:1/0,l=c<i,u=l?c:i,d=l&&i>0?c/i:1,{norm:p}=e,m=h=>p.map(b=>a*VC(p,h,b*d)),f=h=>d===1?h:p.map(b=>VC(p,h,b*d));return{ayMax:u,axAccelN:m(r.axAccelN),axDecelN:m(r.axDecelN),axScrubN:m(r.axScrubN),...r.motorTyreN?{motorTyreN:r.motorTyreN.map(f)}:{},...r.motorLoss?{motorLoss:f(r.motorLoss)}:{},...r.motorGain?{motorGain:r.motorGain.map(f)}:{},atLock:l}}var Q3=5,dy=1;function Zn(e,t,r){let n=e.length;if(n===1||r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0;for(;o<n-2&&e[o+1]<=r;)o++;let a=e[o],s=e[o+1],i=t[o],c=t[o+1];if(n===2)return i+(r-a)/(s-a)*(c-i);let l=p=>{let m=e[p];return i*(r-s)*(r-m)/((a-s)*(a-m))+c*(r-a)*(r-m)/((s-a)*(s-m))+t[p]*(r-a)*(r-s)/((m-a)*(m-s))},u=(r-a)/(s-a),d=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),d))}function BC(e,t,r){let n=Z3(e,t);if(!r||!(t>0))return n;let o=n(t);return a=>a<t?q3(r,e[0],o,t,a):n(a)}function Z3(e,t){let r=e.filter(m=>m.atLock),n=e.filter(m=>!m.atLock),o=r.length>0&&n.length>0&&r[r.length-1].v<n[0].v,a=m=>({vs:m.map(h=>h.v),ayMax:m.map(h=>h.ayMax),radius:m.map(h=>Math.max(h.v,t)**2/h.ayMax),accel:m[0].axAccelN.map((h,b)=>m.map(g=>g.axAccelN[b])),decel:m[0].axDecelN.map((h,b)=>m.map(g=>g.axDecelN[b])),scrub:m[0].axScrubN.map((h,b)=>m.map(g=>g.axScrubN[b])),motors:m.every(h=>h.motorTyreN&&h.motorLoss)?{tyreN:m[0].motorTyreN.map((h,b)=>h.map((g,y)=>m.map(x=>x.motorTyreN[b][y]))),loss:m[0].motorLoss.map((h,b)=>m.map(g=>g.motorLoss[b])),gain:m.every(h=>h.motorGain)?m[0].motorGain.map((h,b)=>h.map((g,y)=>m.map(x=>x.motorGain[b][y]))):void 0}:void 0}),s=(m,f)=>({axAccelN:m.accel.map(h=>Zn(m.vs,h,f)),axDecelN:m.decel.map(h=>Zn(m.vs,h,f)),axScrubN:m.scrub.map(h=>Zn(m.vs,h,f)),...m.motors?{motorTyreN:m.motors.tyreN.map(h=>h.map(b=>Zn(m.vs,b,f))),motorLoss:m.motors.loss.map(h=>Zn(m.vs,h,f)),...m.motors.gain?{motorGain:m.motors.gain.map(h=>h.map(b=>Zn(m.vs,b,f)))}:{}}:{}});if(!o){let m=a(e);return f=>({ayMax:Zn(m.vs,m.ayMax,f),...s(m,f),atLock:!1})}let i=a(r),c=a(n),l=i.vs[i.vs.length-1],u=c.vs[0],d=m=>Math.max(m,t)**2/Zn(i.vs,i.radius,m),p=m=>m>=u||c.vs.length<2?Zn(c.vs,c.ayMax,m):c.ayMax[0]+(c.ayMax[1]-c.ayMax[0])/(c.vs[1]-c.vs[0])*(m-u);return m=>{if(m<=l)return{ayMax:d(m),...s(i,m),atLock:!0};if(m>=u)return{ayMax:p(m),...s(c,m),atLock:!1};let f=d(m),h=p(m);return f<h?{ayMax:f,...s(i,m),atLock:!0}:{ayMax:h,...s(c,m),atLock:!1}}}function J3(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 $C(e,t,r,n,o,a){let s=r>t?Math.max(2,Math.min(Q3,Math.floor(n))):1,i=[];for(let m=0;m<s;m++)i.push(e(s===1?t:t+(r-t)*m/(s-1)));let c=BC(i,t,a),l=[],u=s,d=(m,f)=>{let h=.5*(m+f),b=e(h);u++;let g=J3(c(h),b);i.splice(i.findIndex(y=>y.v>h),0,b),c=BC(i,t,a),g>o&&l.push({lo:m,hi:h,misfit:g},{lo:h,hi:f,misfit:g})},p=i.map(m=>m.v);for(let m=0;m+1<p.length&&u<n;m++)p[m+1]-p[m]>=dy&&d(p[m],p[m+1]);if(p.length>1){let m=.5*(p[0]+p[1]);if(i.some(f=>f.v===m))for(let[f,h]of[[p[0],m],[m,p[1]]]){if(u>=n||h-f<dy)break;let b=l.findIndex(g=>g.lo===f&&g.hi===h);b>=0&&l.splice(b,1),d(f,h)}}for(;u<n&&l.length>0;){let m=0;for(let g=1;g<l.length;g++)l[g].misfit>l[m].misfit&&(m=g);let{lo:f,hi:h,misfit:b}=l.splice(m,1)[0];if(b<=o)break;h-f<dy||d(f,h)}return{anchors:i,at:c}}function GC(e,t){let r=Math.abs(t);return!(r>0)||!(e>0)?1/0:e/Math.tan(Math.min(r,1.5))}function KC(e){if(!e?.meanDeg?.length)return 0;let t=0;for(let r of e.meanDeg)t=Math.max(t,Math.abs(r));return t*Math.PI/180}var eB=2,tB=.5,vl=Math.PI/180,HC=21,rB={nCoarse:11,nSteer:13,nNorm:41,nAngle:45},nB={nCoarse:11,nSteer:13,nNorm:41,nAngle:61},oB=.005,aB=.05,sB=.5,py=e=>e<0?0:e>1?1:e;function zC(e,t,r,n){let o=e.massTotal,a=n.nSteer??7,s=(n.drivenFront?2:0)+(n.drivenRear?2:0),i=We(e,0,0,r),c=Math.max(1,(i.FL+i.FR+i.RL+i.RR)/4),l=8*vl,u=0,d=(b,g,y)=>{for(let x=b;x<=g;x+=y){let v=Math.abs(t.Fy(x*vl,c,0));v>u&&(u=v,l=x*vl)}};d(1,45,1),d(Math.max(.1,l/vl-1),l/vl+1,.1);let p=[],m=[],f=[],h=[];for(let b=0;b<a;b++){let g=b/(a-1),y=l*(g+Math.sin(Math.PI/2*g))/2,x=Math.abs(t.Fy(y,c,0));p.push(4*x/o),m.push(s*cr(t,c,x,!1)/o),f.push(4*cr(t,c,x,!0)/o),h.push(-4*x*Math.sin(y)/o)}return p[0]=0,{ayMax:4*u/o,ay:p,axAccel:m,axDecel:f,axScrub:h,rollover:!1}}function iB(e,t,r){if(e.engine)return;let n=fa(e.params),o=Br(e.params),a=[];for(let s of["front","rear"]){if(!(s==="front"?t:r))continue;let[i,c]=s==="front"?["FL","FR"]:["RL","RR"];if(n[s]==="independent")a.push({wheels:[i],axle:s,motors:o[s]/2},{wheels:[c],axle:s,motors:o[s]/2});else if(n[s]==="diff")a.push({wheels:[i,c],axle:s,motors:o[s]});else return}return a.length>1?a:void 0}var cB=.001;function YC(e,t){let r=e.flatMap((n,o)=>n===void 0?[]:[o]);return r.length===0?e.map(()=>t):e.map((n,o)=>{if(n!==void 0)return n;let a=r[0];for(let s of r)Math.abs(s-o)<Math.abs(a-o)&&(a=s);return e[a]})}var lB=.01,uB=.05;function WC(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 kl(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}=WC(e,t,r,a);if(!(i>0))return s;let l=e.motorLoss?.[t]??1;if(r===1&&n>=1||!o.every(f=>f.gain)){let f=r>=1?l:l/(r+l*(1-r));return Math.max(c,s-f*i)}let u=Math.min(s,jC(e,t,r,a)),d=WC(e,t,1,e.axDrive);if(!(d.short>0))return Math.max(c,u);let m=Math.max(d.theirs,e.axAccelN[t]-l*d.short)-Math.min(e.axAccelN[t],jC(e,t,1,e.axDrive));return Math.max(c,Math.min(s,u+m*(i/d.short)))}function jC(e,t,r,n){let o=e.motors,a=r*e.axAccelN[t],s=a;for(let i=0;i<=o.length+1;i++){let c=0,l=0,u=0;for(let p of o){let m=r*p.gain[t],f=r*p.tyreN[t]*e.axAccelN[t],h=p.share>0?p.share*n:0,b=f+m*(s-a);u+=Math.min(h,b),(m>0?b<=h:b<h)?(l+=m,c+=f-m*a):c+=h}if(!(u<s))return s;if(!(l<1))return 0;let d=c/(1-l);if(!(d<s))return s;s=d}return s}function fy(e,t,r,n,o){if(!e.motors)return 1/0;let a=t.length-1;if(!(r<t[a]))return kl(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=kl(e,s,n,o);return c===0?l:l+c*(kl(e,i,n,o)-l)}function pn(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?nB:rB),{nCoarse:c,nSteer:l,nAngle:u}=i,d=$n(0,1,i.nNorm).map(K=>Math.sin(Math.PI/2*K)),p=e.params,m=p.m.value,f=p.rho.value,h=p.fr_0.value,b=p.driven_wheels.value,g=p.power_scale.value,y=e.FG,x=jt(p);s!==1&&(x.loadFactor=s);let v=un(p),k=_S(0,n?.vRes??(e.engine?tB:eB),e.vMax);k[k.length-1]<e.vMax&&k.push(e.vMax);let R=e.fRad.map(K=>K*b),M=e.fAxle,{drivenFront:S,drivenRear:w}=ya(e),F=ga(p,S,w),T=(K,ne,U)=>{let Q=Ct(K,ne,Math.max(U,K[0]));return Number.isFinite(Q)?Q:1/0},A=(K,ne)=>M?T(M.vVehicle,K,ne):1/0,C=r==="fast"?void 0:iB(e,S,w),P=Br(p),L=(K,ne)=>{if(M){let Q=A(M.fFront,ne),se=A(M.fRear,ne),de=K.map(ie=>(ie.axle==="front"?Q:se)*(ie.motors/P[ie.axle])),ue=de.reduce((ie,ve)=>ie+ve,0);if(Number.isFinite(ue)&&ue>0)return de.map(ie=>ie/ue)}let U=K.reduce((Q,se)=>Q+se.motors,0);return K.map(Q=>Q.motors/U)},E=K=>{let ne=K*K,{cl:U,cw:Q,A:se}=Gd(p,K,0,x),de=.5*f*-Q*se*ne,ue=.5*f*-U*se*ne,ie=h*(-ue+y);return de+ie},_=K=>{let ne=E(K)/m*F.powerFactor,U=E(K)/m*F.tractionFactor,Q;if(e.engine){let de=E(K);Q=Os(e.engine,K,F.effective,de,g).accel-ne}else if(M){let de=0;S&&(de+=A(M.fFront,K)),w&&(de+=A(M.fRear,K)),Q=g*de/m*F.powerFactor}else{let de=T(e.vVehicle,R,K),ue=g*de/m*F.powerFactor;Q=Number.isFinite(ue)?ue:1/0}let se=Ud(p,K,o)/m*F.powerFactor;return{axDrag:ne,axDragTyre:U,axDrive:Q,axPackCap:se,axPower:Math.min(Q,se)}},D=k.map(_),I=e.vMax;for(let K=1;K<k.length;K++){let ne=D[K].axDrive+D[K].axDrag;if(ne>0)continue;let U=D[K-1].axDrive+D[K-1].axDrag;I=U>0?k[K-1]+(k[K]-k[K-1])*U/(U-ne):k[K-1];break}let V=Math.min(e.vMax,(1+aB)*I),O=r==="fast"?zC:S0,B=K=>{let ne=C?_(K).axDrive:1/0,U=C&&Number.isFinite(ne)?L(C,K).map((pe,me)=>({wheels:C[me].wheels,cap:pe*ne*m/F.tractionFactor})):void 0,Q=O(x,v,K,{drivenFront:S,drivenRear:w,nSteer:l,yawDemandCn:a,axDrag:E(K)/m,...p.diffYaw?{diffYaw:!0}:{},...U?{motorCaps:U}:{}}),se=Q.ay[0],de=Q.ay[Q.ay.length-1],ue=pe=>Math.min(Math.max(pe*Q.ayMax,se),de),ie=d.map(pe=>Xm(Q.ay,Q.axAccel,ue(pe))*F.tractionFactor),ve=d.map(pe=>Xm(Q.ay,Q.axDecel,ue(pe))),Ie=d.map(pe=>Xm(Q.ay,Q.axScrub,ue(pe))*F.tractionFactor),je=Q.axAccelWheels,te=Q.axAccelHeld,ae=Q.axAccelWheelsHeld,Ce=C&&U&&je&&te?(()=>{let pe=C.map(Re=>Q.ay.map((ye,Me)=>Re.wheels.reduce((fe,be)=>fe+je[Me][be],0))),me=pe.map(Re=>{let ye=Re.map((Me,fe)=>Me/Math.max(Q.axAccel[fe],cB));return d.map(Me=>Ct(Q.ay,ye,ue(Me)))}),xe=Q.ay.map((Re,ye)=>{let Me=pe.reduce((fe,be,Te)=>fe+Math.max(0,be[ye]-U[Te].cap/m),0);return Me>lB?Math.max(0,Q.axAccel[ye]-te[ye])/Me:void 0}),ge=d.map(Re=>Ct(Q.ay,YC(xe,1),ue(Re))),ke=ae?C.map((Re,ye)=>{let Me=Q.ay.map((fe,be)=>{let Te=ae[be],Fe=Q.axAccel[be]-te[be];if(!(!Te||!(Fe>uB)))return(pe[ye][be]-Re.wheels.reduce((Gt,mt)=>Gt+Te[mt],0))/Fe});return d.map(fe=>Ct(Q.ay,YC(Me,0),ue(fe)))}):void 0;return{motorTyreN:me,motorLoss:ge,...ke?{motorGain:ke}:{}}})():void 0;return{v:K,ayMax:Q.ayMax,axAccelN:ie,axDecelN:ve,axScrubN:Ie,...Ce??{},atLock:Q.atLock===!0}},z=new Map,j=K=>{let ne=z.get(K);return ne||z.set(K,ne=B(K)),ne},$=r==="fast"?0:Math.min(hd,V),N=$;if(r!=="fast"){for(let K=$;K<V;K=Math.min(V,K+sB))if(j(K).ayMax>0){N=K;break}}let W=(()=>{if(r==="fast"||!(N>0))return;let K=U=>zC(x,v,U,{drivenFront:S,drivenRear:w,nSteer:2}).ayMax,ne=K(N);return{norm:d,grip:U=>ne>0?K(U)/ne:1,lockRadius:GC(x.wheelbase/1e3,KC(x.steerFront))}})(),Z=$C(j,N,V,c,i.anchorTol??oB,W),q=[],Y=[];for(let K=0;K<k.length;K++){let ne=k[K],{axDrag:U,axDragTyre:Q,axDrive:se,axPackCap:de,axPower:ue}=D[K],{ayMax:ie,axAccelN:ve,axDecelN:Ie,axScrubN:je,motorTyreN:te,motorLoss:ae,motorGain:Ce,atLock:pe}=Z.at(ne),me=C&&te&&ae?L(C,ne):void 0,xe=C&&te&&me?C.map((Me,fe)=>({wheels:Me.wheels,share:me[fe],tyreN:te[fe],...Ce?{gain:Ce[fe]}:{}})):void 0,ge={v:ne,ayMax:ie,...pe?{atLock:pe}:{},axTyreAcc:ve[0],axTyreDec:Ie[0],axDrive:se,axPackCap:de,axPower:ue,axDrag:U,axDragTyre:Q,axAccelN:ve,axDecelN:Ie,axScrubN:je,...xe&&ae?{motors:xe,motorLoss:ae}:{}};q.push(ge);let ke=[],Re=[];for(let Me=0;Me<u;Me++){let fe=Math.PI*Me/(u-1),be=ie*Math.cos(fe),Te=py(Math.abs(Math.cos(fe))),Fe=Math.min(Ct(d,ve,Te)+Q,ue+U,fy(ge,d,Te,1,1)+U);ke.push({ax:Fe+Ct(d,je,Te),ay:be,v:ne})}for(let Me=u-1;Me>=0;Me--){let fe=Math.PI*Me/(u-1),be=ie*Math.cos(fe),Te=py(Math.abs(Math.cos(fe)));Re.push({ax:Ct(d,Ie,Te)+U+Ct(d,je,Te),ay:be,v:ne})}let ye=(Me,fe,be)=>Array.from({length:HC},(Te,Fe)=>({ax:fe+(be-fe)*(Fe+1)/(HC+1),ay:Me,v:ne}));Y.push([...ke,...ye(-ie,ke[ke.length-1].ax,Re[0].ax),...Re,...ye(ie,Re[Re.length-1].ax,ke[0].ax)])}return{...QC(q,d),rows:q,norm:d,surf:Y}}function ii(e,t){return e?.length?t.map(r=>ip(e,r)):t.map(()=>0)}function XC(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=>qC(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 ip(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 qC(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 QC(e,t){let r=e[e.length-1].v,n=0;for(let b of e)b.atLock&&b.v>0&&b.ayMax>0&&(n=Math.max(n,b.ayMax/(b.v*b.v)));let o=b=>{if(b<=e[0].v)return{i0:0,i1:0,t:0};if(b>=r)return{i0:e.length-1,i1:e.length-1,t:0};let g=0,y=e.length-1;for(;y-g>1;){let x=g+y>>1;e[x].v<=b?g=x:y=x}return{i0:g,i1:y,t:(b-e[g].v)/(e[y].v-e[g].v)}},a=b=>{let{i0:g,i1:y,t:x}=o(b);return{a:e[g],b:e[y],t:g===y?0:x}},s=(b,g,y)=>b===0||g===y?g:g+b*(y-g),i=(b,g,y,x)=>b===0?Ct(t,g,x):s(b,Ct(t,g,x),Ct(t,y,x)),c=(b,g)=>g>=1?b.axPower:Math.min(g*b.axDrive,b.axPackCap),l=({a:b,b:g,t:y},x,v)=>b.axScrubN?v*i(y,b.axScrubN,g.axScrubN,x):0,u=b=>b.axDragTyre??b.axDrag,d=({a:b,b:g,t:y},x,v)=>{let k=v*s(y,b.ayMax,g.ayMax);return k>0?py(x/k):1},p=({a:b,b:g,t:y},x,v,k)=>s(y,fy(b,t,x,v,k),y===0?0:fy(g,t,x,v,k))+s(y,b.axDrag,g.axDrag),m=(b,g,y=1,x=1)=>{let{a:v,b:k,t:R}=b,M=d(b,g,y),S=y*i(R,v.axAccelN,k.axAccelN,M)+s(R,u(v),u(k)),w=s(R,c(v,x),R===0?0:c(k,x))+s(R,v.axDrag,k.axDrag);return v.motors?Math.min(S,w,p(b,M,y,x))+l(b,M,y):Math.min(S,w)+l(b,M,y)},f=(b,g,y=1,x=1)=>{let{a:v,b:k,t:R}=b,M=d(b,g,y),S=i(R,v.axDecelN,k.axDecelN,M);return(x===1||S>0?y*S:x*y*S)+s(R,v.axDrag,k.axDrag)+l(b,M,y)},h=({a:b,b:g,t:y},x,v=1)=>{let k=t.length-1,R=b.axAccelN,M=g.axAccelN,S=b.axDecelN,w=g.axDecelN,F=b.axScrubN,T=g.axScrubN,A=V=>R[V]+y*(M[V]-R[V]),C=V=>S[V]+y*(w[V]-S[V]),P=V=>F?v*(F[V]+y*(T[V]-F[V])):0,L=s(y,b.ayMax,g.ayMax),E=s(y,b.axDrag,g.axDrag),_=s(y,u(b),u(g)),D=s(y,b.axPower,g.axPower),I=b.motors?V=>s(y,kl(b,V,v,1),y===0?0:kl(g,V,v,1)):null;for(let V=k;V>=0;V--){let O=I?Math.min(v*A(V)+_,D+E,I(V)+E)+P(V):Math.min(v*A(V)+_,D+E)+P(V),B=v*C(V)+E+P(V);if(!(x<=O+1e-6&&x>=B-1e-6))continue;if(V===k)return t[V]*v*L;let z=(W,Z,q)=>{if(q(Z))return 1;let Y=(W-x)/(W-Z);return Y>0?Math.min(Y,1):0},j=W=>x<=W+1e-6,$=W=>x>=W-1e-6,N=Math.min(z(v*A(V)+_+P(V),v*A(V+1)+_+P(V+1),j),z(D+E+P(V),D+E+P(V+1),j),z(v*C(V)+E+P(V),v*C(V+1)+E+P(V+1),$),I?z(I(V)+E+P(V),I(V+1)+E+P(V+1),j):1);return(t[V]+N*(t[V+1]-t[V]))*v*L}return 0};return{vMax:r,...n>0?{kappaMax:n}:{},axAccel:(b,g,y=1,x=1)=>m(a(b),g,y,x),axDecel:(b,g,y=1,x=1)=>f(a(b),g,y,x),ay:(b,g,y=1)=>h(a(b),g,y),scrub:(b,g,y=1)=>{let x=a(b);return l(x,d(x,g,y),y)},power:(b,g,y=1)=>{let x=a(b),{a:v,b:k,t:R}=x,S=(Number.isFinite(v.axPower)&&Number.isFinite(k.axPower)?s(R,v.axPower,k.axPower):Math.max(v.axPower,k.axPower))+s(R,v.axDrag,k.axDrag);return v.motors?Math.min(S,p(x,d(x,g,y),y,1)):S}}}function mB(e,t,r){let n=e.params,o=n.m.value,{drivenFront:a,drivenRear:s}=ya(e),i=ga(n,a,s);return c=>Ud(n,c,t,r)/o*i.powerFactor}function Ml(e,t,r,n){let o=mB(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{...QC(a,e.norm),rows:a,norm:e.norm}}var dB=[-.2,-.08,0,.06,.12,.2,.3];function ZC(e,t=!1,r="twoTrack",n,o,a=dB){let s=[...new Set([...a,0])].sort((f,h)=>f-h),i=s.map(f=>pn(e,t,r,n,o,f)),c=i[s.indexOf(0)],l=s[0],u=s[s.length-1],d=f=>{if(f<=l)return{i:0,t:0};if(f>=u)return{i:s.length-1,t:0};let h=0;for(;h<s.length-2&&s[h+1]<=f;)h++;return{i:h,t:(f-s[h])/(s[h+1]-s[h])}},p=f=>{let h=b=>{let{i:g,t:y}=d(b);return{a:f[g],b:f[Math.min(f.length-1,g+1)],t:y}};return b=>{let{a:g,b:y,t:x}=h(b);if(x===0)return g;let v=(R,M)=>R+x*(M-R),k=JC(g.kappaMax,y.kappaMax);return{vMax:g.vMax,...k!==void 0?{kappaMax:k}:{},axAccel:(R,M,S=1,w=1)=>v(g.axAccel(R,M,S,w),y.axAccel(R,M,S,w)),axDecel:(R,M,S=1,w=1)=>v(g.axDecel(R,M,S,w),y.axDecel(R,M,S,w)),ay:(R,M,S=1)=>v(g.ay(R,M,S),y.ay(R,M,S)),scrub:(R,M,S=1)=>v(g.scrub?.(R,M,S)??0,y.scrub?.(R,M,S)??0)}}},m=f=>f<l||f>u;return{anchors:s,steady:c,clamps:m,at:p(i),atSoc(f,h,b){let g=i.map(y=>Ml(y,f,h,b));return{anchors:s,steady:g[s.indexOf(0)],clamps:m,at:p(g)}}}}function JC(e,t){return e===void 0?t:t===void 0?e:Math.min(e,t)}function eF(e,t,r,n="twoTrack",o){let a=[...new Set([...t,1])].sort((i,c)=>i-c),s=a.map(i=>i===1?r:pn(e,!1,n,o,void 0,0,i));return{...UC(a,s),atSoc:(i,c,l)=>UC(a,s.map(u=>Ml(u,i,c,l)))}}function UC(e,t){let r=e.length-1,n=1,o=0,a=0,s=0,i=1,c=0,l=0,u=f=>{if(n=1,!(f>e[0]))return void(o=0);if(f>=e[r])return void(o=r);let h=0;for(;h<r-1&&e[h+1]<=f;)h++;if(o=h,f===e[h])return;a=h+1;let b=e[h],g=e[h+1];if(r<2){n=2,c=(f-b)/(g-b),i=1-c;return}s=h===0?2:h+1===r||f-e[h-1]<e[h+2]-f?h-1:h+2;let y=e[s];n=3,i=(f-g)*(f-y)/((b-g)*(b-y)),c=(f-b)*(f-y)/((g-b)*(g-y)),l=(f-b)*(f-g)/((y-b)*(y-g))},d=f=>{let h=f(t[o]);if(n===1)return h;let b=f(t[a]);if(n===2)return i*h+c*b;let g=i*h+c*b+l*f(t[s]);return Math.min(Math.max(h,b),Math.max(Math.min(h,b),g))},p=(f,h,b,g,y)=>{if(u(f),n===1||b===0)return d(k=>y(k,b));let x=d(k=>k.ay(h,0,g));if(!(x>0))return d(k=>y(k,b));let v=b/x;return d(k=>y(k,v*k.ay(h,0,g)))},m=t.reduce((f,h)=>JC(f,h.kappaMax),void 0);return{anchors:e,...m!==void 0?{kappaMax:m}:{},axAccel:(f,h,b,g=1,y=1)=>p(f,h,b,g,(x,v)=>x.axAccel(h,v,g,y)),axDecel:(f,h,b,g=1,y=1)=>{let x=v=>p(f,h,b,g,(k,R)=>k.axDecel(h,R,g,v));return y===1?x(1):Y0(x(y),x(1),y)},scrub:(f,h,b,g=1)=>p(f,h,b,g,(y,x)=>y.scrub?.(h,x,g)??0),ay:(f,h,b,g=1)=>{if(u(f),n===1||b===0)return d(k=>k.ay(h,b,g));let y=k=>b>0?k.axAccel(h,0,g):-k.axDecel(h,0,g),x=d(y);if(!(x>0))return d(k=>k.ay(h,b,g));let v=b/x;return d(k=>k.ay(h,v*y(k),g))}}}var tF=new WeakMap;function hy(e,t){let r=tF.get(e);if(!r){let n=Bn(e).regen?Q0(t??ur(e)):void 0;r={inp:jt(e),ev:un(e),...n?{regen:n}:{}},tF.set(e,r)}return r}function by(e,t,r){let n=hy(e,r);return my(n.inp,n.ev,t,n.regen?{regen:n.regen}:{})}function gy(e){let t=Yt(e);if(t.mode!=="hydraulic")return null;let r=a=>a.heat?{heat:Ag(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 pB(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 yy(e,t,r,n,o,a=lr){if(!e)return null;let s=pB(t);return{...e.front?{front:Hm(e.front.heat,e.front.discs,s.front,r,n,o.front,a)}:{},...e.rear?{rear:Hm(e.rear.heat,e.rear.discs,s.rear,r,n,o.rear,a)}:{}}}var fB=.5,hB=.02,bB=6,cp=9,rF=1e-9,gB={FL:0,FR:0,RL:0,RR:0};function xy(e){return e?[...new Set([...e.padCurve.factor,1])].sort((t,r)=>t-r):[1]}function yB(e,t,r){let n=sn(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 nF(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 oF(e,t,r,n,o=()=>0){let a=Array.from({length:cp},(d,p)=>r*p/(cp-1)),s=Wc(),{front:i,rear:c}=n,l=a.map(d=>{let p=o(d),m=h=>Kn(h,t,d,s).limitAt(0,0,gB,p).ax,f=m(e);return i.map(h=>c.map(b=>{if(h===1&&b===1)return 1;let g=f<0?m(yB(e,h,b))/f:1;return Math.abs(g-1)<rF?1:g}))}),u=a[1]-a[0];return{share(d,p,m){if(p===1&&m===1)return 1;let f=u>0?Math.min(cp-2,Math.max(0,Math.floor(d/u))):0,h=u>0?Math.min(1,Math.max(0,(d-a[f])/u)):0,b=nF(i,p),g=nF(c,m),y=v=>{let k=l[v],R=Math.min(i.length-1,b.i+1),M=Math.min(c.length-1,g.i+1),S=k[b.i][g.i]+g.t*(k[b.i][M]-k[b.i][g.i]),w=k[R][g.i]+g.t*(k[R][M]-k[R][g.i]);return S+b.t*(w-S)},x=y(f)+h*(y(Math.min(cp-1,f+1))-y(f));return Math.abs(x-1)<rF?1:x}}}function xB(e,t){let{front:r,rear:n}=t;return(o,a)=>e.share(a,r?.[o]??1,n?.[o]??1)}var RB=e=>(e.front??[]).every(t=>t===1)&&(e.rear??[]).every(t=>t===1);function aF(e,t,r){let n=e(),o=1,a=t(n);if(RB(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<bB;c++){let l=e(xB(r,s));o++;let u=Math.abs(l.laptime-n.laptime);if(n=l,u<hB){i=!0;break}a=t(n);let d=(f,h)=>f&&h?f.map((b,g)=>b+fB*((h[g]??1)-b)):f,p=d(s.front,a.front),m=d(s.rear,a.rear);s={...p?{front:p}:{},...m?{rear:m}:{}}}return{lap:n,pads:s,solves:o,converged:i}}function wo(e,t){let r=e.engine;if(!r||r.gears.length===0||t.length===0)return;let n=e.params,{drivenFront:o,drivenRear:a}=ya(e),s=ga(n,o,a).effective,i=n.power_scale.value,{up:c,down:l}=Gg(r.engine.gearbox),u=r.engine.idleRpm,d=(p,m,f)=>(i*r.force(p,m)+f)/(s+r.inertiaMass(p,m));return{count:r.gears.length,up:c,down:l,kept:Kg(r.engine.gearbox),limitRpm:r.engine.limitRpm,best:p=>Os(r,p,s,ip(t,p)*s,i).gear,share:(p,m)=>{let f=ip(t,p),h=f*s,b=Os(r,p,s,h,i);if(m===b.gear)return 1;let g=b.accel-f;return g>0?Math.min(1,Math.max(0,(d(p,m,h)-f)/g)):0},rpm:(p,m)=>r.slipping(p,m)?u:r.rpm(p,m),vIdle:p=>r.gears[p]?.vIdle??0}}var sF=new WeakMap;function vy(e){let t=sF.get(e.ggv);return t===void 0&&(t=wo(e.vehicle,e.ggv.rows)??null,sF.set(e.ggv,t)),t??void 0}function vB(e){return e.gear&&e.engineRpm&&e.shifting?{gear:e.gear,rpm:e.engineRpm,shifting:e.shifting}:{}}function kB(e,t){return{v:t.v,ax:t.ax,ay:t.ay,s:e.s,x:e.x,y:e.y,...e.gradient.some(r=>r!==0)?{gradient:e.gradient}:{},...e.bank.some(r=>r!==0)?{bank:e.bank}:{},...e.z.some(r=>r!==0)?{z:e.z}:{},...e.mu.some(r=>r!==1)?{mu:e.mu}:{},...t.loadFactor?{loadFactor:t.loadFactor}:{},...t.axScrub?{axScrub:t.axScrub}:{},...vB(t)}}var up=class extends Error{constructor(t){super(t),this.name="EventError"}};function MB(e,t){let{ggv:r}=t,n=Nt(t.numerics),o=n.accelStep,a=Math.max(1,Math.round(e.distance/o)),s=ri(r,new Array(a+1).fill(0),n);s[0].v=e.vStart??0;for(let f=0;f<s.length-1;f++){let h=s[f],b=s[f+1];h.v>=b.v||(h.ax=r.axAccel(h.v,0),b.v=Math.min(r.vMax,Math.sqrt(Math.max(0,h.v*h.v+2*h.ax*o))))}let i=vy(t),c=i?zd(s.map(f=>f.v),new Array(a).fill(o),!1,i,(f,h,b)=>r.axAccel(h,0,1,b)):void 0;if(c){for(let f=0;f<=a;f++)s[f].v=c.v[f];for(let f=0;f<a;f++)s[f].ax=(s[f+1].v*s[f+1].v-s[f].v*s[f].v)/(2*o)}let l=0;for(let f=0;f<a;f++){let h=s[f].v+s[f+1].v;h>0&&(l+=2*o/h)}let u=s.slice(0,a).map(f=>f.v),d=s.slice(0,a).map(f=>f.ax),p=new Array(a).fill(o),m=p.map((f,h)=>h*o);return{id:e.id,label:e.label,kind:e.kind,time:l,distance:a*o,laps:1,lapTime:l,trace:{v:u,ax:d,ay:new Array(a).fill(0),s:m,x:m,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:hF(t,p,[...u,s[a].v],d,1)}}function SB(e,t){let r=Math.max(1,Math.round(e.laps??1)),[n]=ri(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=hF(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 mp(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 AB(e,t){let r=e.distance!=null?t.v_limit_endurance?.value??0:0;return r>0?r/3.6:void 0}function wB(e,t){if(e.distance==null||kt(t.motorModel))return 0;let r=t.endurance_reserve?.value??0;return r>0?Math.min(r,95)/100:0}var iF=1;function dF(e,t,r,n){return{v:r.v,ax:r.ax,ay:r.ay,ds:t.ds,axDrag:ii(e.ggv.rows,r.v),...r.axScrub?{axScrub:r.axScrub}:{},axGrade:n,...t.bank?{bank:t.bank}:{}}}var cF=new WeakMap;function pF(e){let t=e.vehicle.params;if(!t.brakeFade)return null;let r=cF.get(t);if(r===void 0){let n=gy(t),o=n?Yt(t):null;if(!n||!o||o.mode!=="hydraulic")r=null;else{let a=hy(t,e.vehicle),s=e.ggv.rows,i=oF(a.inp,a.ev,e.vehicle.vMax,{front:xy(o.hydraulic.front.heat),rear:xy(o.hydraulic.rear.heat)},c=>ii(s,[c])[0]);r={discs:n,table:i}}cF.set(t,r)}return r}function CB(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=vy(e),u=(g,y)=>e.yaw?NC(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}:{}}):er(Ml(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}:{}}),d=ti(t.gradient,t.npts),p=g=>n.motorThermal?Zw(e.vehicle,t.ds,e.energyOpts??Vn,y=>u(y,g),o,a,d,t.bank).lap:u(void 0,g),m=pF(e);if(!m)return p();let f=gl(n),h=r.discC??{front:f,rear:f};return aF(p,g=>{let y=yy(m.discs,by(n,dF(e,t,g,d),e.vehicle),g.v,t.ds,h,f);return{...y?.front?{front:y.front.padFactor}:{},...y?.rear?{rear:y.rear.padFactor}:{}}},m.table).lap}function FB(e,t){let r=AB(e,t.vehicle.params),n=wB(e,t.vehicle.params);return n>0?LB(e,t,n,r):Sl(e,t,r)}function lp(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 lF=5,TB=.1,PB=.005,uF=12;function LB(e,t,r,n){let o=Sl(e,t,n),a=1,s=(f,h,b)=>({...f,energyTarget:{reserve:r,capKmh:h===void 0?null:h*3.6,met:b,solves:a}}),i=lp(o,r);if(i>=0)return s(o,n,!0);let c=Math.min(n??1/0,t.ggv.vMax),l=c/2,u=Sl(e,t,l);a++;let d=lp(u,r);for(;d<0&&l>lF&&a<uF;)c=l,i=d,l=Math.max(lF,l/2),u=Sl(e,t,l),a++,d=lp(u,r);if(d<0)return s(u,l,!1);let m=DB(f=>{let h=Sl(e,t,f);return{run:h,margin:lp(h,r)}},{lo:l,hi:c,atLo:{run:u,margin:d},fHi:i},uF-a);return a+=m.solves,s(m.run,m.cap,!0)}function DB(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>TB&&a.margin>PB;){let u=o-n,d=Math.min(o-.05*u,Math.max(n+.05*u,n+s*u/(s-i))),p=e(d);l++,p.margin>=0?(n=d,a=p,s=p.margin,c===1&&(i/=2),c=1):(o=d,i=p.margin,c===-1&&(s/=2),c=-1)}return{cap:n,run:a.run,solves:l}}function fF(e,t,r){return r===0?e:e&&!t}function Sl(e,t,r){let n=t.track;if(!n)throw new up(`Event "${e.id}" needs a track.`);let o=mp(e,n),a=e.standingStart??t.standingStart??!1,s=N=>fF(a,n.closed,N),i=t.vehicle.params,c=An(ni(i)),l=c.capacityAh,u=kt(i.motorModel)?1:i.soc.value,d=gl(i),p=jd(c,d),m=0,f=0,h=0,b=0,g=[],y=!1,x=-1/0,v=0,k=0,R=!1,M=-1/0,S=0,w=0,F=-1/0,T=(N,W,Z=1)=>{N.tempMaxC>F&&(F=N.tempMaxC),N.motorTempMaxC!==void 0&&(y=!0,R=!0,N.motorTempMaxC>x&&(x=N.motorTempMaxC),N.motorTempMaxC>M&&(M=N.motorTempMaxC),v+=(N.motorDerateTimeFrac??0)*W,S+=(N.motorDerateTimeFrac??0)*W,k+=(N.motorLossKwh??0)/Z,w+=(N.motorLossKwh??0)/Z)},A=null,C,P=gy(i),L={front:d,rear:d},E=null,_=pF(t)!==null,D=(N,W)=>_&&(Math.abs(N.front-W.front)>iF||Math.abs(N.rear-W.rear)>iF),I=(N,W,Z)=>{let q=Z0(i,N,W);if(E&&E.launch===Z&&!_B(q,E.pw)&&!D(L,E.discC))return E.lap;let Y=CB(t,n,{soc:N,packTempC:W,launched:Z,...r?{vCeiling:r}:{},..._?{discC:L}:{}});return E={pw:q,launch:Z,discC:L,lap:Y},Y},V=ti(n.gradient,n.npts),O=(N,W,Z)=>oi(t.vehicle,n.ds,N.v,N.ax,t.energyOpts,W,Z,void 0,V,void 0,{ay:N.ay,bank:n.bank,...N.axScrub?{scrub:N.axScrub}:{}}),B=new WeakMap,z=(N,W)=>{let Z=B.get(N);return Z||(Z=by(i,dF(t,n,N,V),t.vehicle),B.set(N,Z)),yy(P,Z,N.v,n.ds,W,d)},j=(N,W,Z)=>{let q=`${(100*Z/n.npts).toFixed(0)} % of the way through lap ${N+1}`,Y=W.cutoffAt>=0&&W.cutoffAt<=W.emptyAt;return{lapsCompleted:N,lapsAsked:o,why:Y?`the pack reached its ${c.voltageFloor.toFixed(0)} V cut-off ${q}`:`the pack ran out ${q}`}};for(let N=0;N<o;N++){if(u<=0){C={lapsCompleted:N,lapsAsked:o,why:"the pack was empty"};break}let W=s(N),Z=u,q=p;R=!1,M=-1/0,S=0,w=0,F=-1/0;let Y=I(u,p,W),K=O(Y,u,p);if(K.emptyAt>=0){C=j(N,K,K.emptyAt);break}let U=I(K.socEnd,K.tempEndC,W).laptime-Y.laptime,Q,se,de,ue,ie=p,ve=-1,Ie=null,je=1;if(U<=Ry)Q=Y.laptime,se=K.net,de=K.loss,ue=K.chargeAh,ie=K.tempEndC,T(K,Q),je=1;else{let ae=Math.min(EB,Math.max(2,Math.ceil(U/(2*Ry))));je=ae;let Ce=u,pe=p;Q=0,se=0,de=0,ue=0;for(let me=0;me<ae;me++){let xe=I(Ce,pe,W),ge=O(xe,Ce,pe),ke=ge.emptyAt>=0?ge.emptyAt/n.npts:1;if(ke*ae<1){ve=Math.round(n.npts*(me/ae+ke)),Ie=ge;break}if(Q+=xe.laptime/ae,T(ge,xe.laptime/ae,ae),se+=ge.net/ae/ke,de+=ge.loss/ae/ke,ue+=ge.chargeAh/ae/ke,Ce-=ge.chargeAh/ae/ke/l,pe+=(ge.tempEndC-pe)/ae,Ce<=0){ve=Math.round(n.npts*(me+1)/ae),Ie=ge;break}}if(ie=pe,ve>=0&&Ie){C=j(N,Ie,ve);break}u=Ce}m+=Q,f+=se,h+=de,b+=ue,U<=Ry&&(u=K.socEnd),p=ie;let te=P?z(Y,L):null;te&&(L={front:te.front?.endC??L.front,rear:te.rear?.endC??L.rear}),g.push({lap:N+1,time:Q,elapsed:m,entryTime:Y.laptime,socStart:Z,socEnd:u,packTempStartC:q,packTempEndC:p,packTempMaxC:Number.isFinite(F)?F:q,energyKwh:se,lossKwh:de,chargeAh:ue,launched:W,substeps:je,...r?{vCeiling:r}:{},...R?{motor:{peakWindingC:M,derateTimeFrac:Q>0?S/Q:0,lossKwh:w}}:{},...te?{brakes:{...te.front?{front:mF(te.front)}:{},...te.rear?{rear:mF(te.rear)}:{}}}:{}}),A=Y}if(!A){let N=vy(t);A=er(Ml(t.ggv,t.vehicle,u),n,t.numerics,{standingStart:a,...t.load?{load:t.load.atSoc(t.vehicle,u)}:{},...N?{shifts:N}:{}}),C=C??{lapsCompleted:0,lapsAsked:o,why:"the pack was empty"}}let $=g.length;return{id:e.id,label:e.label,kind:e.kind,time:m,distance:n.length*$,laps:$,lapTime:A.laptime,trace:kB(n,A),energy:{consumed:f,loss:h,...kt(i.motorModel)?{}:{native:{value:b,unit:"Ah"}},remainingFraction:kt(i.motorModel)?1:u,...y?{motor:{peakWindingC:x,derateTimeFrac:m>0?v/m:0,lossKwh:k}}:{}},lapLog:g,...C?{incomplete:C}:{}}}var Ry=.05;function mF(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 EB=4,IB=.001;function _B(e,t){return e===t?!1:!Number.isFinite(e)||!Number.isFinite(t)?!0:Math.abs(e-t)>IB*Math.max(1,Math.abs(t))}function hF(e,t,r,n,o,a){return NB(e,t,o,()=>({v:r,ax:n,...a?{lateral:a}:{}}))}function NB(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),d=oi(e.vehicle,t,u.v,u.ax,o,a,void 0,void 0,void 0,void 0,u.lateral);s+=d.net,i+=d.loss,c+=d.chargeAh,a=d.socEnd}return kt(e.vehicle.params.motorModel)?{consumed:s,loss:i,remainingFraction:1}:{consumed:s,loss:i,native:{value:c,unit:"Ah"},remainingFraction:a}}function bF(e,t){switch(e.kind){case"straightLineAccel":return MB(e,t);case"constantRadius":return SB(e,t);case"trackLap":return FB(e,t)}}function ky(e,t){let r={};for(let n of e)r[n.id]=bF(n,t);return r}function gF(e,t){if(e.kind!=="trackLap")return e;let{distance:r,...n}=e;return{...n,laps:Math.max(1,Math.round(t))}}function Ra(e,t,r,n,o="twoTrack",a){let s=1/0,i=-1/0;for(let p of r){let m=fl(p);if(!m)continue;let f=Ow(m,er(t,p,n).v);f&&(s=Math.min(s,f.lo),i=Math.max(i,f.hi))}if(!(i>=s))return;let c=Vw({lo:s,hi:i}),l=c.join(","),u=a?.get(l);if(u)return u;let d=eF(e,c,t,o);return a?.set(l,d),d}var Al=e=>e.distance/Math.max(1,e.laps);function wl(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 OB=e=>e.v.map(t=>t*3.6),VB=e=>e.ax.map(t=>t/9.81),BB=e=>e.ay.map(t=>t/9.81),$B=e=>e.ay.map((t,r)=>e.v[r]>1e-6?t/(e.v[r]*e.v[r]):0),dp=(e,t,r)=>e?.slice()??new Array(t.s.length).fill(r),GB=e=>dp(e.z,e,0),KB=e=>e.gradient?e.gradient.map(t=>100*Math.tan(t*Math.PI/180)):dp(void 0,e,0),HB=e=>dp(e.bank,e,0),zB=e=>dp(e.mu,e,1);function YB(e){let t=e.s.length,r=wl(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 My=[{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 yF(e){let t=wl(e);return{ds:t,vars:{s:e.s,ds:t,t:YB(e),v:e.v,speed:OB(e),ax:e.ax,ay:e.ay,axg:VB(e),ayg:BB(e),curv:$B(e),z:GB(e),grade:KB(e),bank:HB(e),grip:zB(e)}}}function pp(e){let t=e.rows?XC(e.rows,e.v):void 0;return{v:e.v,ax:e.ax,ay:e.ay,ds:e.ds,...e.rows?{axDrag:ii(e.rows,e.v)}:{},...e.axScrub?{axScrub:e.axScrub}:{},axGrade:ti(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 xF(e,t){return pp({v:e.v,ax:e.ax,ay:e.ay,ds:wl({s:e.s,length:t}),gradient:e.gradient,bank:e.bank,loadFactor:e.loadFactor})}function RF(e,t){let r=jt(e);return{pastTurnover:TC(r,un(e),t),...e.aeroModel?{aeroOutside:FC(r,t)}:{}}}var fp="Flying lap";function Sy(e,t){return e.kind!=="trackLap"||e.label!==fp?e.label:e.standingStart??t?"Run":e.label}function WB(e){let t=jt(e);return{yawInertia:t.yawInertia??0,massTotal:t.massTotal,wheelbase:t.wheelbase/1e3}}function jB(e,t,r){let n=e.params,o=n.ggvMode??"twoTrack",a=n.quasiTransient?ZC(e,!1,o):null,s=a?a.steady:pn(e,!1,o),i=t?Ra(e,s,[t],r,o):void 0;return{ggv:s,...a?{yaw:{family:a,car:WB(n)}}:{},...i?{load:i}:{}}}function UB(e,t){let r=t.lapCounts,n=t.standingStart??!1,o=!1,a=e.events.map(s=>{let i=r?.[s.id]!=null?gF(s,r[s.id]):s,c=Sy(i,n),l=c===i.label?i:{...i,label:c};return l!==s&&(o=!0),l});return o?a:e.events}function XB(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=mp(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 qB(e,t){for(let[r,n]of Object.entries(e))n.trace&&(e[r]={...n,...RF(t,xF(n.trace,Al(n)))})}function Cl(e,t,r={}){let n=ur(e),o=jB(n,r.track,r.numerics),{ggv:a}=o,s=ky(UB(t,r),{vehicle:n,...o,track:r.track,energyOpts:Bn(e,r.energyOpts),numerics:r.numerics,standingStart:r.standingStart});return XB(s,t,r),qB(s,n.params),{name:e.name,rulesetId:t.id,events:s,ggv:a}}function Ay(e){return{...e,ggv:{rows:e.ggv.rows,vMax:e.ggv.vMax,surf:e.ggv.surf}}}var wy=["<","<=",">",">=","==","!="],ot=class extends Error{at;constructor(t,r){super(t),this.name="ExprError",this.at=r}},Fl=e=>e>="0"&&e<="9",vF=e=>/[A-Za-z_]/.test(e),QB=e=>/[A-Za-z0-9_]/.test(e);function ZB(e){let t=[],r=0;for(;r<e.length;){let n=e[r];if(n===" "||n===" "||n===`
|
|
224
|
+
`||n==="\r"){r++;continue}if(Fl(n)||n==="."&&Fl(e[r+1]??"")){let o=r;for(;r<e.length&&(Fl(e[r])||e[r]===".");)r++;if(e[r]==="e"||e[r]==="E"){let i=r;if(r++,(e[r]==="+"||e[r]==="-")&&r++,Fl(e[r]??""))for(;r<e.length&&Fl(e[r]);)r++;else r=i}let a=e.slice(o,r),s=Number(a);if(!Number.isFinite(s))throw new ot(`"${a}" is not a number`,o);t.push({t:"num",value:s,at:o});continue}if(vF(n)){let o=r;for(;;){for(;r<e.length&&QB(e[r]);)r++;if(e[r]==="."&&vF(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(wy.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 ot(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 ot(`"${n}" is not something this expression can contain`,r)}return t.push({t:"end",at:e.length}),t}function Cy(e){let t=ZB(e),r=0,n=()=>t[r],o=h=>{let b=n();return b.t==="op"&&b.value===h},a=h=>o(h)?(r++,!0):!1,s=(h,b)=>{if(!a(h))throw new ot(`Expected ${b} here`,n().at)};function i(){let h=c(),b=n();if(b.t!=="op"||!wy.includes(b.value))return h;r++;let g={kind:"binary",op:b.value,left:h,right:c(),at:b.at},y=n();if(y.t==="op"&&wy.includes(y.value))throw new ot("Comparisons do not chain \u2014 write and(a < b, b < c)",y.at);return g}function c(){let h=l();for(;;){let b=n().at;if(a("+"))h={kind:"binary",op:"+",left:h,right:l(),at:b};else if(a("-"))h={kind:"binary",op:"-",left:h,right:l(),at:b};else return h}}function l(){let h=u();for(;;){let b=n().at;if(a("*"))h={kind:"binary",op:"*",left:h,right:u(),at:b};else if(a("/"))h={kind:"binary",op:"/",left:h,right:u(),at:b};else return h}}function u(){return a("-")?{kind:"unary",op:"-",arg:u()}:a("+")?u():d()}function d(){let h=p(),b=n().at;return a("^")?{kind:"binary",op:"^",left:h,right:u(),at:b}:h}function p(){let h=n();if(h.t==="num")return r++,{kind:"num",value:h.value};if(h.t==="name"){if(r++,a("(")){let b=[];if(!o(")"))do b.push(i());while(a(","));return s(")","a closing bracket"),{kind:"call",name:h.value,args:b,at:h.at}}return{kind:"var",name:h.value,at:h.at}}if(a("(")){let b=i();return s(")","a closing bracket"),b}throw h.t==="end"?new ot("The expression ends before it is finished",h.at):new ot(`"${h.value}" cannot start a value`,h.at)}let m=i(),f=n();if(f.t!=="end")throw new ot(`"${f.value}" is left over \u2014 check for a missing operator`,f.at);return m}function Fy(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 Tl=(e,t)=>typeof e=="number"?new Array(t).fill(e):e;function JB(e){let t=1;for(let r of e)Array.isArray(r)&&(t=Math.max(t,r.length));return t}function fr(e,t){if(e.every(a=>typeof a=="number"))return t(...e);let r=JB(e),n=e.map(a=>Tl(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 at=(e,t)=>({arity:e,call:r=>fr(r,t)}),va=e=>e!==0&&!Number.isNaN(e),fn=e=>e?1:0;function kF(e,t,r){let n=MF(t,r,"integrate"),o=n.length,a=Tl(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 MF(e,t,r){if(!e.ds||e.ds.length===0)throw new ot(`${r}() needs to know the sample spacing, and this context has none`,t);return e.ds}var hp={abs:at(1,Math.abs),sqrt:at(1,Math.sqrt),sign:at(1,Math.sign),floor:at(1,Math.floor),ceil:at(1,Math.ceil),round:at(1,Math.round),exp:at(1,Math.exp),log:at(1,Math.log),sin:at(1,Math.sin),cos:at(1,Math.cos),tan:at(1,Math.tan),atan:at(1,Math.atan),atan2:at(2,Math.atan2),hypot:at(2,Math.hypot),min:at(2,Math.min),max:at(2,Math.max),clamp:at(3,(e,t,r)=>Math.min(r,Math.max(t,e))),if:at(3,(e,t,r)=>va(e)?t:r),and:at(2,(e,t)=>fn(va(e)&&va(t))),or:at(2,(e,t)=>fn(va(e)||va(t))),not:at(1,e=>fn(!va(e))),finite:at(1,e=>fn(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=kF(e,t,0),n=t.ds,o=Tl(e,n.length),a=n.length-1;return r[a]+(o[a]+o[0])/2*n[a]}},integrate:{arity:1,call:([e],t)=>kF(e,t,0)},cum:{arity:1,call:([e],t)=>{let r=t.ds?.length??(Array.isArray(e)?e.length:1),n=Tl(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=MF(t,0,"deriv"),n=r.length,o=Tl(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}}},ci={g:9.81,pi:Math.PI,e:Math.E,nan:NaN,inf:1/0},Pl={fleetmin:"min",fleetmax:"max"};function ka(e){switch(e.kind){case"call":return Object.hasOwn(Pl,e.name)||e.args.some(ka);case"unary":return ka(e.arg);case"binary":return ka(e.left)||ka(e.right);default:return!1}}var e5=e=>typeof e=="number"?`${e}`:`between ${e[0]} and ${e[1]}`;function t5(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 r5(e,t){let r=t.map(c=>({k:c,d:t5(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 hn(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(ci,e.name))return ci[e.name];let r=[...Object.keys(t.vars),...Object.keys(ci)].sort();throw new ot(r5(e.name,r),e.at)}case"unary":return fr([hn(e.arg,t)],r=>-r);case"binary":{let r=hn(e.left,t),n=hn(e.right,t);switch(e.op){case"+":return fr([r,n],(o,a)=>o+a);case"-":return fr([r,n],(o,a)=>o-a);case"*":return fr([r,n],(o,a)=>o*a);case"/":return fr([r,n],(o,a)=>a===0?0:o/a);case"^":return fr([r,n],(o,a)=>o**a);case"<":return fr([r,n],(o,a)=>fn(o<a));case"<=":return fr([r,n],(o,a)=>fn(o<=a));case">":return fr([r,n],(o,a)=>fn(o>a));case">=":return fr([r,n],(o,a)=>fn(o>=a));case"==":return fr([r,n],(o,a)=>fn(o===a));case"!=":return fr([r,n],(o,a)=>fn(o!==a))}break}case"call":{let r=Object.hasOwn(Pl,e.name)?Pl[e.name]:void 0;if(r){if(!t.fleet)throw new ot(`${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 ot(`${e.name}() takes 1 argument, not ${e.args.length}`,e.at);return t.fleet(e.args[0],r,e.at)}let n=Object.hasOwn(hp,e.name)?hp[e.name]:void 0;if(!n){let s=[...Object.keys(hp),...t.fleet?Object.keys(Pl):[]];throw new ot(`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 ot(`${e.name}() takes ${e5(n.arity)} argument${o===1&&a===1?"":"s"}, not ${e.args.length}`,e.at);return n.call(e.args.map(s=>hn(s,t)),t)}}throw new ot("Unreachable node",0)}var li=e=>Number.isFinite(e)?e:NaN,Ty=[{name:"time",unit:"s",what:"the whole event, every lap",read:e=>li(e?.time)},{name:"lapTime",unit:"s",what:"one lap \u2014 the last one completed",read:e=>li(e?.lapTime)},{name:"distance",unit:"m",what:"distance covered",read:e=>li(e?.distance)},{name:"laps",unit:"-",what:"laps completed",read:e=>li(e?.laps)},{name:"energy",unit:"kWh",what:"energy drawn over the event",read:e=>li(e?.energy?.consumed)},{name:"remaining",unit:"-",what:"share of the pack or tank left afterwards",read:e=>li(e?.energy?.remainingFraction)},{name:"finished",unit:"-",what:"1 when the car ran the whole event, else 0",read:e=>e&&!e.incomplete?1:0}],SF=/^[A-Za-z_][A-Za-z0-9_]*$/,n5=new Set([...Object.keys(ci),...My.map(e=>e.name)]);function bp(e,t,r=[]){let n=[],o=new Set(r),a=t.map(b=>b.id),s=new Set;for(let b of a)SF.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(!SF.test(b.key)){n.push({key:b.key,message:`"${b.key}" must be one word \u2014 letters, digits and _`});continue}if(n5.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,Cy(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,[...Fy(g)].filter(y=>i.has(y)));let u=new Set,d=[];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),d.push(b)}for(let b of c.keys()){if(u.has(b))continue;let g=o5(b,l);n.push({key:b,message:g?`"${b}" depends on itself, through ${g.join(" \u2192 ")}`:`"${b}" reads a KPI that depends on itself`})}let p=(b,g,y)=>{throw new ot("fleetmin() and fleetmax() cannot sit inside one another",y)},m=new Set,f={};for(let b of a)for(let g of Ty)f[`${b}.${g.name}`]=1;for(let b of o)f[b]=1;for(let b of i.keys())f[b]=1;let h={};for(let b of My)h[b.name]=[1,1];for(let b of d){let g=i.get(b),y=c.get(b);(ka(y)||l.get(b).some(R=>m.has(R)))&&m.add(b);let x=g.over!=null?{...f,...h}:f,v=g.over!=null?[1,1]:void 0,k=(R,M,S)=>{let w=hn(R,{vars:x,ds:v,fleet:p});if(Array.isArray(w))throw new ot("fleetmin() and fleetmax() compare one number per car \u2014 reduce the channel first, e.g. peak(v)",S);return w};try{let R=hn(y,{vars:x,ds:v,fleet:k});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:d.map(b=>({def:i.get(b),node:c.get(b)})),field:m,eventIds:a},problems:n}}function o5(e,t){let r=[e],n=o=>{for(let a of t.get(o)??[]){if(a===e)return!0;if(!r.includes(a)){if(r.push(a),n(a))return!0;r.pop()}}return!1};return n(e)?[...r,e]:null}function a5(e,t,r={}){let n={...r};for(let o of e.eventIds){let a=t.events[o];for(let s of Ty)n[`${o}.${s.name}`]=s.read(a)}return{vars:n,laps:new Map,events:t.events}}function AF(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?yF({...n.trace,length:Al(n)}):null,e.laps.set(t.over,r)}return r?{vars:{...e.vars,...r.vars},ds:r.ds}:null}var wF=e=>Array.isArray(e)?NaN:e;function CF(e,t,r,n={}){let o=Object.keys(t),a=o.map(i=>a5(e,t[i],n[i]));for(let{def:i,node:c}of e.order){let l=e.field.has(i.key);if(l&&!r){for(let p of a)p.vars[i.key]=NaN;continue}let u=new Map,d=(p,m)=>{let f=u.get(p);if(f!==void 0)return f;let h=NaN;for(let b of a){let g=AF(b,i);if(!g)continue;let y=wF(hn(p,g));Number.isFinite(y)&&(Number.isNaN(h)||(m==="min"?y<h:y>h))&&(h=y)}return u.set(p,h),h};for(let p of a){let m=AF(p,i);p.vars[i.key]=m?wF(hn(c,l?{...m,fleet:d}:m)):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 Ll(e,t,r){return CF(e,t,!0,r)}function Py(e,t,r){return CF(e,{car:t},!1,r?{car:r}:void 0).car}var gp=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}},Ll=e=>typeof e=="number"&&Number.isFinite(e),Pl=e=>Ll(e)&&e>0,hr=(e,t)=>e===void 0||t(e);function JB(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":Pl(a.distance)||r(`${s} needs a distance above zero, in metres`),hr(a.vStart,i=>Ll(i)&&i>=0)||r(`${s}'s entry speed must be zero or more`);break;case"constantRadius":Pl(a.radius)||r(`${s} needs a radius above zero, in metres`),hr(a.laps,i=>Ll(i)&&i>=1)||r(`${s} runs at least one lap`);break;case"trackLap":hr(a.laps,i=>Ll(i)&&i>=1)||r(`${s} runs at least one lap`),hr(a.distance,Pl)||r(`${s}'s distance must be above zero, in metres`),hr(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),hr(a.unit,i=>typeof i=="string")||r("Its unit is text",s),hr(a.over,i=>typeof i=="string")||r("Names its event by id",s),hr(a.format,i=>i==="time"||i==="points")||r("Is shown as a time, as points, or as a number",s),hr(a.max,Ll)||r("Its maximum is a number",s),hr(a.lowerBetter,i=>typeof i=="boolean")||r("Lower is better, or it is not",s),hr(a.hidden,i=>typeof i=="boolean")||r("Is hidden, or it is not",s)}hr(e.track?.minTurnRadius,Pl)||r("The tightest turn the rules allow is a radius above zero");let n=e.battery;for(let o of["packVoltageMax","segmentVoltageMax","powerLimitKw"])hr(n?.[o],Pl)||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 MF(e){let t=JB(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}=fp(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 bp(e){return MF(e).problems}var Ty=e=>Number.isFinite(e)?e:NaN;function e5(e){return e.unit&&e.format!=="time"?`${e.label} (${e.unit})`:e.label}function wo(e){let t=structuredClone(e),{plan:r,problems:n}=MF(t);if(!r)throw new hp(t.id,n);let o=new WeakMap,a=m=>{let f=o.get(m);return f||(f=Fy(r,m),o.set(m,f)),f},s=new Map(t.kpis.map(m=>[m.key,m])),i=new Map;for(let[m,f]of Object.entries(t.score?.parts??{}))i.has(f)||i.set(f,m);let c=m=>(f,h)=>{if(!h)return NaN;let b=h.kpis?.[m];if(b!==void 0)return Ty(b);let g=h,y=i.get(m);return y!==void 0?Ty(g.parts?.[y]):m===t.score?.total?Ty(g.total):NaN},l=t.kpis.filter(m=>!m.hidden).map(m=>{let f=r.field.has(m.key);return{key:m.key,label:e5(m),lowerBetter:m.lowerBetter??!1,...m.format?{format:m.format}:{},...f?{field:!0}:{},value:f?c(m.key):h=>a(h)[m.key]}}),u=t.score,d=u?m=>{let f=Tl(r,m),h={};for(let[b,g]of Object.entries(f)){let y={},x={};for(let[v,k]of Object.entries(u.parts)){y[v]=g[k];let R=s.get(k)?.max;R!=null&&(x[v]=R)}h[b]={total:g[u.total],parts:y,...Object.keys(x).length?{maxima:x}:{},kpis:Object.fromEntries(t.kpis.map(v=>[v.key,g[v.key]]))}}return h}:void 0,p=d||(r.field.size>0?m=>{let f=Tl(r,m),h={};for(let[b,g]of Object.entries(f))h[b]={kpis:Object.fromEntries(t.kpis.map(y=>[y.key,g[y.key]]))};return h}:void 0);return{id:t.id,label:t.label,description:t.description,events:t.events,metrics:l,...t.track?{track:t.track}:{},...t.battery?{battery:t.battery}:{},...t.traceEventId?{traceEventId:t.traceEventId}:{},...d?{score:d}:{},...p?{field:p}:{},definition:t}}var Gr={accel:"accel",skidpad:"skidpad",autocross:"autocross",endurance:"endurance"},SF=[{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}],AF=[{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"}],wF={total:"overall",parts:{[Gr.accel]:"accelPts",[Gr.skidpad]:"skidpadPts",[Gr.autocross]:"autocrossPts",[Gr.endurance]:"endurancePts",efficiency:"efficiencyPts"}},CF={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:SF,kpis:AF,score:wF,track:{minTurnRadius:4.5},battery:lv,traceEventId:Gr.autocross},FF={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:SF,kpis:AF,score:wF,track:{minTurnRadius:4.5},traceEventId:Gr.autocross},Dl=wo(CF),Py=wo(FF);var Ly="lap",t5=[{kind:"trackLap",id:Ly,label:dp,laps:1}],TF={id:"trackday",label:"Track day",description:"One flying lap of the selected track. Times and traces only \u2014 no scoring.",events:t5,kpis:[{key:"lap",label:"Lap time",format:"time",lowerBetter:!0,expr:"lap.time"},{key:"topSpeed",label:"Top speed",unit:"km/h",over:Ly,expr:"peak(speed)"},{key:"energy",label:"Energy / lap",unit:"kWh",lowerBetter:!0,expr:"lap.energy"}],traceEventId:Ly},Dy=wo(TF);function Co(e){if(e===null||typeof e!="object")return JSON.stringify(e)??"null";if(Array.isArray(e))return`[${e.map(Co).join(",")}]`;let t=e,r=Object.keys(t).sort(),n=[];for(let o of r)t[o]!==void 0&&n.push(`${JSON.stringify(o)}:${Co(t[o])}`);return`{${n.join(",")}}`}function Sa(e){let t=Co(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 li=[Dl,Py,Dy],Aa=Dl.id,ui=e=>li.some(t=>t.id===e),PF=new WeakMap,El=new Map,r5=64;function gp(e){let t=PF.get(e);if(t!==void 0)return t;let r=Co(e),n=El.get(r);return n===void 0&&(n=bp(e).length?null:wo(e),El.size>=r5&&El.delete(El.keys().next().value),El.set(r,n)),PF.set(e,n),n}function yp(e,t=[]){if(e==null)return;if(typeof e!="string")return gp(e)??void 0;let r=li.find(o=>o.id===e);if(r)return r;let n=t.find(o=>o.id===e);return n?gp(n)??void 0:void 0}function wa(e,t=[]){return yp(e,t)??Dl}function Ey(e=[]){let t=e.filter(r=>!ui(r.id)).map(r=>gp(r)).filter(r=>r!==null);return[...li,...t]}var Il=e=>e.definition??e.id;function xp(e,t,r){let n=e.length,o=new Array(n);for(let f=0;f<n;f++){let h=f+1<n?e[f+1]:r;o[f]=h-e[f]}let a=new Array(n).fill(0),s=new Array(n).fill(0),i=new Array(n).fill(0),c=new Array(n).fill(0);for(let f=0;f<n;f++){let h=o[(f-1+n)%n],b=o[f];a[f]=h,s[f]=2*(h+b),i[f]=b;let g=t[(f+1)%n],y=t[(f-1+n)%n];c[f]=6*((g-t[f])/b-(t[f]-y)/h)}let l=n5(a,s,i,c),u=new Array(n),d=new Array(n),p=new Array(n),m=new Array(n);for(let f=0;f<n;f++){let h=o[f],b=l[f],g=l[(f+1)%n],y=t[f],x=t[(f+1)%n];u[f]=y,p[f]=b/2,m[f]=(g-b)/(6*h),d[f]=(x-y)/h-h*(2*b+g)/6}return{n,eval:(f,h)=>u[f]+h*(d[f]+h*(p[f]+h*m[f])),d1:(f,h)=>d[f]+h*(2*p[f]+h*3*m[f]),d2:(f,h)=>2*p[f]+h*6*m[f]}}function _y(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,d=new Array(u).fill(0),p=new Array(u).fill(0),m=new Array(u).fill(0),f=new Array(u).fill(0);for(let g=0;g<u;g++){let y=g+1;d[g]=o[y-1],p[g]=2*(o[y-1]+o[y]),m[g]=o[y],f[g]=6*((t[y+1]-t[y])/o[y]-(t[y]-t[y-1])/o[y-1])}let h=n>=3;if(h){let g=o[0]/o[1];p[0]+=o[0]*(1+g),m[0]-=o[0]*g;let y=o[n-1]/o[n-2];p[u-1]+=o[n-1]*(1+y),d[u-1]-=o[n-1]*y}let b=Iy(d,p,m,f);for(let g=0;g<u;g++)a[g+1]=b[g];h&&(a[0]=(1+o[0]/o[1])*a[1]-o[0]/o[1]*a[2],a[r-1]=(1+o[n-1]/o[n-2])*a[r-2]-o[n-1]/o[n-2]*a[r-3])}let s=new Array(n),i=new Array(n),c=new Array(n),l=new Array(n);for(let u=0;u<n;u++)s[u]=t[u],c[u]=a[u]/2,l[u]=(a[u+1]-a[u])/(6*o[u]),i[u]=(t[u+1]-t[u])/o[u]-o[u]*(2*a[u]+a[u+1])/6;return{n,eval:(u,d)=>s[u]+d*(i[u]+d*(c[u]+d*l[u])),d1:(u,d)=>i[u]+d*(2*c[u]+d*3*l[u]),d2:(u,d)=>2*c[u]+d*6*l[u]}}function n5(e,t,r,n){let o=t.length;if(o===1)return[n[0]/(t[0]+e[0]+r[0])];if(o===2){let f=t[0],h=r[0]+e[0],b=e[1]+r[1],g=t[1],y=f*g-h*b;return[(n[0]*g-h*n[1])/y,(f*n[1]-n[0]*b)/y]}let a=e[0],s=r[o-1],i=-t[0]||1e-30,c=t.slice();c[0]=t[0]-i,c[o-1]=t[o-1]-a*s/i;let l=Iy(e,c,r,n),u=new Array(o).fill(0);u[0]=i,u[o-1]=s;let d=Iy(e,c,r,u),p=(l[0]+a*l[o-1]/i)/(1+d[0]+a*d[o-1]/i),m=new Array(o);for(let f=0;f<o;f++)m[f]=l[f]-p*d[f];return m}function Iy(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 _l(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 LF(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 DF(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,d=r*c+n*l+o*u;if(!(Math.abs(d)>1e-12*Math.max(1,Math.abs(r*a*i))))return null;let p=r*i-o*o,m=n*o-r*s,f=r*a-n*n;return[(c*t[0]+l*t[1]+u*t[2])/d,(l*t[0]+p*t[1]+m*t[2])/d,(u*t[0]+m*t[1]+f*t[2])/d]}function EF(e){let t=e.z.length;if(t<5)return 0;let r=[];for(let a=0;a<t;a++){let s=[a-2,a-1,a+1,a+2].map(h=>e.closed?(h+t)%t:h);if(s.some(h=>h<0||h>=t))continue;let i=s.map(h=>LF(e,a,h)),c=Math.max(...i.map(Math.abs));if(!(c>0))continue;let l=i.map(h=>h/c),u=[0,0,0,0,0];for(let h of l)for(let b=0;b<5;b++)u[b]+=h**b;let d=DF([u[0],u[1],u[2],u[2],u[3],u[4]],[1,0,0]);if(!d)continue;let p=l.map(h=>d[0]+d[1]*h+d[2]*h*h),m=0,f=1;p.forEach((h,b)=>{m+=h*e.z[s[b]],f+=h*h}),r.push(Math.abs(e.z[a]-m)/Math.sqrt(f))}if(!r.length)return 0;r.sort((a,s)=>a-s);let n=r.length>>1;return 1.4826*(r.length%2?r[n]:(r[n-1]+r[n])/2)}function o5(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=LF(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 a5(e,t,r){let{j:n,t:o}=o5(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 d=a[u];for(let p=0;p<5;p++)i[p]+=d,d*=l});let c=DF([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 Ny(e,t){return t>0?e.z.map((r,n)=>{let o=a5(e,n,t/2);return o?o.value.reduce((a,s,i)=>a+s*e.z[o.j[i]],0):r}):[...e.z]}function s5(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 Rp(e){let t=_l(e);if(!t)return 0;let r=EF(t);return r>1e-6?Math.max(10,s5(r,i5(t))):0}function i5(e){let t=[];for(let r=1;r<e.pos.length;r++)t.push(e.pos[r]-e.pos[r-1]);return e.closed&&e.pos.length&&t.push(e.length-e.pos[e.pos.length-1]+e.pos[0]),t.sort((r,n)=>r-n),t.length?t[t.length>>1]:0}function bn(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 kp(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 IF(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 vp(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 c5(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 Oy(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=IF(r,(y,x)=>bn(e,y,x));if(!b)return null;let g=vp(b,t);return g.every(Number.isFinite)?g:null}let n=r-2,a=IF(n,(b,g)=>bn(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]=bn(e,b,r-2),i[b]=bn(e,b,r-1);let c=vp(a,t.slice(0,n)),l=vp(a,s),u=vp(a,i),d=(b,g)=>{let y=0;for(let x=0;x<b.length;x++)y+=b[x]*g[x];return y},p=[[bn(e,r-2,r-2)-d(s,l),bn(e,r-2,r-1)-d(s,u)],[bn(e,r-1,r-2)-d(i,l),bn(e,r-1,r-1)-d(i,u)]],m=[t[r-2]-d(s,c),t[r-1]-d(i,c)],f=c5(p,m);if(!f)return null;let h=new Array(r).fill(0);for(let b=0;b<n;b++)h[b]=c[b]-l[b]*f[0]-u[b]*f[1];return h[r-2]=f[0],h[r-1]=f[1],h.every(Number.isFinite)?h:null}function _F(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=Oy(i,t);if(c){let l=kp(i,c).map((d,p)=>d-t[p]);if(Math.sqrt(l.reduce((d,p)=>d+p*p,0))<=1e-6*Math.max(a,1e-12))return c}o=o===0?n*1e-12:o*10}return null}var NF=4,l5=8,Vy=.001;function u5(e,t,r){let n=[];for(let c=1;c<e.length;c++){let l=e[c]-e[c-1];l>=Vy&&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/Fw(r,s,i)))}function m5(e,t){let r=e.closed!==!1,n=[],o=[],a=(S,w)=>{let F=n.length-1;F>=0&&Math.hypot(S-n[F],w-o[F])<Vy||(n.push(S),o.push(w))},s=e.x.length,i=r?s:s-1,c=new Array(i+1);c[0]=0;for(let S=0;S<i;S++){let w=(S+1)%s;c[S+1]=c[S]+Math.hypot(e.x[w]-e.x[S],e.y[w]-e.y[S])}let l=c[i],u=e.fit==="interpolate",d=u?s:u5(c,r,t),p=r?d:d-1,m=0;for(let S=0;S<=p&&!(r&&S===p);S++){if(u){a(e.x[S],e.y[S]);continue}let w=S*l/p;for(;m<i-1&&c[m+1]<w;)m++;let F=c[m+1]-c[m],T=F>0?(w-c[m])/F:0,A=(m+1)%s;a(e.x[m]+T*(e.x[A]-e.x[m]),e.y[m]+T*(e.y[A]-e.y[m]))}if(r)for(;n.length>2&&Math.hypot(n[n.length-1]-n[0],o[o.length-1]-o[0])<Vy;)n.pop(),o.pop();let f=n.length,h=r?f:f-1,b=new Array(h+1);b[0]=0;for(let S=1;S<=h;S++){let w=S%f,F=n[w]-n[S-1],T=o[w]-o[S-1],A=Math.sqrt(Math.hypot(F,T))||1e-9;b[S]=b[S-1]+A}let g=r?xp(b.slice(0,f),n,b[f]):_y(b,n),y=r?xp(b.slice(0,f),o,b[f]):_y(b,o),x=new Array(h);for(let S=0;S<h;S++)x[S]=b[S+1]-b[S];let v=[0],k=[0],R=[0],M=0;for(let S=0;S<h;S++){let w=x[S]/NF;for(let F=0;F<NF;F++){let T=F*w;M+=Og(A=>Math.hypot(g.d1(S,A),y.d1(S,A)),T,T+w),v.push(M),k.push(S),R.push(T+w)}}return{closed:r,sx:g,sy:y,h:x,sTable:v,segTable:k,uTable:R,length:M,rawCum:c,rawLength:l}}function Nl(e,t,r,n){if(e===void 0)return r.map(()=>t);if(typeof e=="number")return r.map(()=>e);let o=e.length;if(o===0)return r.map(()=>t);if(o===1)return r.map(()=>e[0]);let a=n.rawCum.length-1,s=o===(n.closed?a:a+1);return r.map(i=>{let c;if(s){let p=i*n.rawLength,m=0,f=a;for(;m<f;){let b=m+f+1>>1;n.rawCum[b]<=p?m=b:f=b-1}let h=m<a?n.rawCum[m+1]-n.rawCum[m]:0;c=m+(h>0?(p-n.rawCum[m])/h:0)}else c=n.closed?i*o:i*(o-1);let l=Math.min(Math.floor(c),o-1)%o,u=c-Math.floor(c),d=n.closed?(l+1)%o:Math.min(l+1,o-1);return e[l]+u*(e[d]-e[l])})}var d5=.01,p5=3,OF=10;function f5(e,t,r,n=OF){let o={step:0,uncertainty:1/0},a=e.length;if(a<8||!(r>0))return o;let s=Math.max(OF,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 d=[],p=[],m=(x,v,k)=>{let R=x/s;d.push([1,R,R*R,R*R*R,v]),p.push(k)};for(let x=0;x<u;x++)m(t[x]+i,1,e[x]);for(let x=0;x<u;x++)m(t[a-1-x]-r+i,0,e[a-1-x]);let f=Array.from({length:5},()=>new Array(5).fill(0)),h=new Array(5).fill(0);d.forEach((x,v)=>{for(let k=0;k<5;k++){h[k]+=x[k]*p[v];for(let R=0;R<5;R++)f[k][R]+=x[k]*x[R]}});let b=Qr(f,h),g=Qr(f,[0,0,0,0,1]);if(b.singular||g.singular)return o;let y=0;return d.forEach((x,v)=>{let k=0;for(let R=0;R<5;R++)k+=x[R]*b.x[R];y+=(p[v]-k)**2}),{step:b.x[4],uncertainty:Math.sqrt(y/(d.length-5)*g.x[4])}}function h5(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 b5(e,t,r){let{pos:n,loop:o}=h5(e.length,t),{step:a,uncertainty:s}=f5(e,n,o,r);return Math.abs(a)>Math.max(d5,p5*s)?{z:e.map((i,c)=>i+a*n[c]/o),drift:-a}:{z:e,drift:0}}function g5(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),d=r[u],p=r[u+1],m=n[u+1],f=o[u+1],h=n[u]===m?o[u]:0,b=p-d,g=b>0?h+(t-d)/b*(f-h):h;for(let y=0;y<2;y++){let x=d+Og(k=>Math.hypot(s.d1(m,k),i.d1(m,k)),h,g),v=Math.hypot(s.d1(m,g),i.d1(m,g));if(v<1e-12)break;g-=(x-t)/v}return{seg:m,du:Math.min(Math.max(g,0),a[m])}}var y5=3,By=5;function x5(e,t,r,n=By){return Sp(e,t,r,n)}function Sp(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 d=1e9*(1+s);for(let p of[0,a-1])i[p]+=d,u[p]*=1+d}return Oy({n:a,diag:i,off1:c,off2:l,closed:r},u)??[...e]}function Ot(e,t){let r=Nt(t),n=m5(e,r.fitSpacing),o=n.length,a=Math.max(l5,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),d=new Array(s).fill(i);n.closed||(d[s-1]=0);let p=new Array(s),m=new Array(s),f=new Array(s);for(let F=0;F<s;F++){let T=F*i,{seg:A,du:C}=g5(n,T);c[F]=n.sx.eval(A,C),l[F]=n.sy.eval(A,C),u[F]=T;let P=n.sx.d1(A,C),L=n.sy.d1(A,C),E=n.sx.d2(A,C),_=n.sy.d2(A,C),D=Math.hypot(P,L),I=Math.pow(P*P+L*L,1.5);p[F]=I>0?(P*_-L*E)/I:0,m[F]=D>0?-L/D:0,f[F]=D>0?P/D:0}let h=u.map(F=>o>0?Math.min(1,F/o):0),b=Array.isArray(e.z)&&e.z.length>1,g=b&&(e.zSmoothing??0)>0?e.zSmoothing:0,y=b&&n.closed?b5(e.z,n.rawCum,g):null,x=y?y.z:e.z,v=g>0?_l(e):null,k=v?Ny({...v,z:x},g):x,R=Nl(k,0,h,n),M=new Array(s).fill(0);if(b){for(let T=0;T<s;T++){let A=n.closed?(T+1)%s:Math.min(T+1,s-1),C=n.closed?(T-1+s)%s:Math.max(T-1,0),P=n.closed?2:A-C,L=R[A]-R[C];M[T]=P>0?Math.atan2(L,P*i)*180/Math.PI:0}for(let T=0;T<s;T++){if(d[T]===0)continue;let A=n.closed?(T+1)%s:T+1,C=R[A]-R[T];d[T]=Math.hypot(i,C)}let F=0;for(let T=0;T<s;T++)u[T]=F,F+=d[T]}let S=b?d.reduce((F,T)=>F+T,0):o,w;if(b){w=new Array(s).fill(0);let F=Math.max(y5,e.zReach??Rp(e)),T=Math.max(2,Math.round(F/i));if(n.closed?s>2*T:s>2*T+1){let A=0,C=0;for(let E=-T;E<=T;E++)A+=E*E,C+=E*E*E*E;let P=2*T+1,L=C-A*A/P;for(let E=0;E<s;E++){let _=n.closed?E:Math.min(Math.max(E,T),s-1-T),D=0,I=0;for(let B=-T;B<=T;B++){let z=R[n.closed?(_+B+s)%s:_+B];D+=(B*B-A/P)*z,I+=B*z}let V=2*D/L/(i*i),O=I/A/i;w[E]=V/Math.pow(1+O*O,1.5)}}}return{name:e.name,closed:n.closed,x:c,y:l,s:u,ds:d,curvature:e.turnReach?x5(p,i,n.closed,e.turnReach):p,npts:s,length:S,nx:m,ny:f,z:R,gradient:M,...w?{verticalCurvature:w}:{},widthLeft:Nl(e.widthLeft,1.5,h,n),widthRight:Nl(e.widthRight,1.5,h,n),bank:Nl(e.bank,0,h,n),mu:Nl(e.mu,1,h,n),...y?.drift?{elevationDrift:y.drift}:{}}}function VF(e,t,r){let n=kp(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 R5(e,t,r,n){let o=e.n,a=e.closed!==!1,s=(l,u)=>{let d=l+u;return a?(d%o+o)%o:d>=0&&d<o?d:null},i=[...t];for(let l=0;l<o;l++){if(r[l]==="free")continue;let u=n(l);if(u!==0)for(let d of[-2,-1,1,2]){let p=s(l,d);p!=null&&(i[p]-=bn(e,p,l)*u)}}let c={n:o,closed:e.closed,diag:[...e.diag],off1:[...e.off1],off2:[...e.off2]};for(let l=0;l<o;l++){if(r[l]==="free")continue;c.diag[l]=1,c.off1[l]=0,c.off2[l]=0;let u=s(l,-1),d=s(l,-2);u!=null&&(c.off1[u]=0),d!=null&&(c.off2[d]=0),i[l]=n(l)}return _F(c,i)}var v5=1e-4;function BF(e,t,r,n,o={}){let a=e.n,s=o.maxIter??60,i=o.tol??1e-9,c=o.bounds,l=(f,h)=>Math.min(n[h],Math.max(r[h],f)),u=r.map((f,h)=>c?.[h]==="hi"?n[h]:c?.[h]==="lo"?r[h]:l(0,h)),d=VF(e,t,u),p=new Array(a).fill("free"),m=!1;for(let f=0;f<s;f++){let h=kp(e,u).map((x,v)=>x-t[v]),b=!1;for(let x=0;x<a;x++){let v=u[x]<=r[x]+i&&h[x]>=-i?"lo":u[x]>=n[x]-i&&h[x]<=i?"hi":"free";v!==p[x]&&(p[x]=v,b=!0)}if(m&&!b)return{x:u,iterations:f+1,converged:!0,bounds:p};let g=R5(e,t,p,x=>u[x]);if(!g)return{x:u,iterations:f+1,converged:!1,bounds:p};let y=!1;for(let x=1;x>1e-12;x*=.5){let v=!1,k=u.map((S,w)=>{if(p[w]!=="free")return S;let F=S+x*(g[w]-S),T=l(F,w);return T!==F&&(v=!0),T}),R=VF(e,t,k),M=0;for(let S=0;S<a;S++)M+=h[S]*(k[S]-u[S]);if(x===1&&!v||R<d&&R<=d+v5*M){u=k,d=R,m=x===1&&!v,y=!0;break}}if(!y)return{x:u,iterations:f+1,converged:!1,bounds:p}}return{x:u,iterations:s,converged:!1,bounds:p}}var $y={lineStep:2,carHalfWidth:.75,margin:.1,foldMargin:.25,referenceReach:5,passes:40,iterations:400},k5=[1,.5,.25,.125,.0625,.03125,.015625,.0078125,.00390625,.001953125,.0009765625],M5=e=>Math.sqrt(e.reduce((t,r)=>t+r*r,0)/(e.length||1));function Ol(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],d=t[i]-t[a],p=e[i]-e[s],m=t[i]-t[s],f=Math.hypot(c,l),h=Math.hypot(u,d),b=Math.hypot(p,m),g=f*h*b;o[a]=g>1e-12?2*(c*d-l*u)/g:0}return o}var S5=Math.PI/180,$F=20;function A5(e,t){let r=e.npts,n=e.closed,o=e.x.map((m,f)=>m+t[f]*e.nx[f]),a=e.y.map((m,f)=>m+t[f]*e.ny[f]),s=[0];for(let m=1;m<r;m++)s.push(s[m-1]+Math.hypot(o[m]-o[m-1],a[m]-a[m-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 m of c)for(let f=0;f<r;f++)l.push(s[f]+m*i),u.push(f+m*r);n&&(l.push(2*i),u.push(2*r));let d=[0];for(let m=1;m<l.length;m++)d.push(d[m-1]+.5*(u[m]+u[m-1])*(l[m]-l[m-1]));let p=m=>{let f=0,h=l.length-1;for(;h-f>1;){let g=f+h>>1;l[g]<=m?f=g:h=g}let b=l[h]>l[f]?(m-l[f])/(l[h]-l[f]):0;return d[f]+(l[h]-l[f])*b*(u[f]+.5*b*(u[h]-u[f]))};return s.map((m,f)=>{let h=n?$F:Math.min($F,m,i-m);if(!(h>0))return e.z[f];let b=(p(m+h)-p(m-h))/(2*h),g=n?(b%r+r)%r:Math.min(Math.max(b,0),r-1),y=Math.min(Math.floor(g),r-1),x=n?(y+1)%r:Math.min(y+1,r-1);return e.z[y]+(g-y)*(e.z[x]-e.z[y])})}function w5(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?A5(t,r):t.z;return{...n||o?{z:s.map((i,c)=>i+r[c]*Math.tan(t.bank[c]*S5))}:{},...n?{zReach:e.zReach??Rp(e)}:{},...o?{bank:[...t.bank]}:{},...a?{mu:[...t.mu]}:{}}}function GF(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 C5(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,d,p)=>l*p-u*d;for(let l=0;l<a;l++){if(!o&&(l===0||l===a-1))continue;let u=(l-1+a)%a,d=(l+1)%a,p=e[l]-e[u],m=t[l]-t[u],f=e[d]-e[l],h=t[d]-t[l],b=e[d]-e[u],g=t[d]-t[u],y=Math.hypot(p,m),x=Math.hypot(f,h),v=Math.hypot(b,g),k=y*x*v;if(!(k>1e-12))continue;let R=2*c(p,m,f,h)/k,M=Math.sqrt(.5*(y+x)),S=R/(2*M),w=(p*r[u]+m*n[u])/y,F=(b*r[u]+g*n[u])/v,T=(p*r[l]+m*n[l])/y,A=(f*r[l]+h*n[l])/x,C=(f*r[d]+h*n[d])/x,P=(b*r[d]+g*n[d])/v,L=-2*c(r[u],n[u],f,h)/k+R*(w/y+F/v),E=2*c(r[l],n[l],b,g)/k-R*(T/y-A/x),_=2*c(p,m,r[d],n[d])/k-R*(C/x+P/v);s[l]=R*M,i.l[l]=M*L-S*.5*w,i.d[l]=M*E+S*.5*(T-A),i.r[l]=M*_+S*.5*C}return{res:s,jac:i}}function F5(e,t,r,n,o){let a=n-r+1,s=e.l.slice(r,n+1),i=e.d.slice(r,n+1),c=e.r.slice(r,n+1),l=t.slice(r,n+1);o||(i[0]+=s[0],s[0]=0,i[a-1]+=c[a-1],c[a-1]=0);let u=(h,b)=>o?h[(b+a)%a]:b>=0&&b<a?h[b]:0,d=new Array(a),p=new Array(a),m=new Array(a),f=new Array(a);for(let h=0;h<a;h++){let b=u(c,h-1),g=u(s,h+1);d[h]=b*b+i[h]*i[h]+g*g,p[h]=i[h]*c[h]+g*u(i,h+1),m[h]=g*u(c,h+1),f[h]=-(b*u(l,h-1)+i[h]*l[h]+g*u(l,h+1))}return{M:{n:a,closed:o,diag:d,off1:p,off2:m},b:f}}function T5(e,t){let r=e.npts,n=e.closed;if(!(t>0)||r<7)return e;let o=n?r:r-1,a=0;for(let p=0;p<o;p++){let m=(p+1)%r;a+=Math.hypot(e.x[m]-e.x[p],e.y[m]-e.y[p])}let s=a/o,i=Sp(e.x,s,n,t,!0),c=Sp(e.y,s,n,t,!0),l=new Array(r),u=new Array(r);for(let p=0;p<r;p++){let m=n?(p-1+r)%r:Math.max(p-1,0),f=n?(p+1)%r:Math.min(p+1,r-1),h=i[f]-i[m],b=c[f]-c[m],g=Math.hypot(h,b)||1;l[p]=-b/g,u[p]=h/g}let d=Ol(i,c,n);return n||(d[0]=d[1],d[r-1]=d[r-2]),{...e,x:i,y:c,nx:l,ny:u,curvature:d}}var P5=6;function L5(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,d=Math.atan2(e.nx[l]*e.ny[u]-e.ny[l]*e.nx[u],e.nx[l]*e.nx[u]+e.ny[l]*e.ny[u]),p=Math.hypot(e.x[u]-e.x[l],e.y[u]-e.y[l]);s[l]=p>1e-9?d/p:0}let i=Math.max(0,Math.round(P5/(e.ds[0]||1))),c=1-n;for(let l=0;l<o;l++){let u=0,d=0;for(let p=-i-1;p<=i;p++){let m=e.closed?((l+p)%o+o)%o:l+p;m<0||m>=a||(u=Math.max(u,s[m]),d=Math.max(d,-s[m]))}u>0&&(t[l]=Math.max(r[l],Math.min(t[l],c/u))),d>0&&(r[l]=Math.min(t[l],Math.max(r[l],-c/d)))}}function Gy(e,t={}){let r={...$y,...t},n=Ot(e,{dsTarget:r.lineStep}),o=T5(n,r.referenceReach),a=o.npts,s=T=>({x:o.x.map((A,C)=>A+o.nx[C]*T[C]),y:o.y.map((A,C)=>A+o.ny[C]*T[C])}),i=T=>{let A=Ol(T.x,T.y,o.closed),C=GF(T.x,T.y,o.closed),P=0;for(let L=0;L<A.length;L++)P+=A[L]*A[L]*C[L];return P},c=M5(n.curvature),l=GF(n.x,n.y,n.closed).reduce((T,A)=>T+A,0),u=new Array(a).fill(0),d=r.carHalfWidth+r.margin,p=new Array(a),m=new Array(a),f=0;for(let T=0;T<a;T++){let A=o.widthLeft[T]-d,C=-(o.widthRight[T]-d);if(A<C){f++;let P=(o.widthLeft[T]-o.widthRight[T])/2;p[T]=P,m[T]=P}else p[T]=A,m[T]=C}let h=[...p],b=[...m];L5(o,p,m,r.foldMargin);let g=T=>{let A=s(T),C=w5(e,o,T),P={name:`${e.name} \u2014 racing line`,x:A.x,y:A.y,closed:o.closed,widthLeft:h.map((O,B)=>Math.max(0,O-T[B])),widthRight:b.map((O,B)=>Math.max(0,T[B]-O)),...C,fit:"interpolate",turnReach:By},L=1e-6,E=T.filter((O,B)=>O>=p[B]-L||O<=m[B]+L).length,_=Ol(A.x,A.y,o.closed),D=O=>1/Math.max(...O.map(Math.abs),1e-9),I=0,V=o.closed?A.x.length:A.x.length-1;for(let O=0;O<V;O++){let B=(O+1)%A.x.length,z=A.x[B]-A.x[O],j=A.y[B]-A.y[O];I+=C.z?Math.hypot(z,j,C.z[B]-C.z[O]):Math.hypot(z,j)}return{offset:T,s:[...o.s],asset:P,curvatureRms:{centreLine:c,racingLine:Math.sqrt(i(A)/(l||1))},infeasibleSamples:f,atBoundary:a?E/a:0,length:{centreLine:n.length,racingLine:I},worstRadius:{centreLine:D(n.curvature),racingLine:D(_)}}},y=o.closed?0:1,x=o.closed?a-1:a-2,v=x-y+1,k=new Array(v),R=new Array(v);for(let T=0;T<v;T++)k[T]=m[y+T],R[T]=p[y+T];if(!o.closed&&v>0){let T=(A,C)=>{if(k[A]=Math.max(k[A],m[C]),R[A]=Math.min(R[A],p[C]),k[A]>R[A]){let P=.5*(k[A]+R[A]);k[A]=P,R[A]=P}};T(0,0),T(v-1,a-1),k[0]=R[0]=Math.min(R[0],Math.max(k[0],0))}if(v<7)return g(u);let M=T=>{let A=s(T),P=[...Ol(A.x,A.y,o.closed).map(Math.abs)].sort((L,E)=>L-E);return{integral:i(A),tail:P[Math.floor(.99*(P.length-1))]}},S=[...u],w=M(u),F;for(let T=0;T<r.passes;T++){let A=s(S),{res:C,jac:P}=C5(A.x,A.y,o.nx,o.ny,o.closed),{M:L,b:E}=F5(P,C,y,x,o.closed),_=BF(L,E,k.map((V,O)=>V-S[y+O]),R.map((V,O)=>V-S[y+O]),{maxIter:r.iterations,bounds:F});F=_.bounds;let D=new Array(a).fill(0);for(let V=0;V<v;V++)D[y+V]=_.x[V];o.closed||(D[0]=D[1],D[a-1]=D[a-2]);let I=!1;for(let V of k5){let O=S.map((z,j)=>z+V*D[j]),B=M(O);if(B.integral<w.integral*(1-1e-6)){S=O,w=B,I=!0;break}}if(!I)break}return g(S)}function Ky(e){let t=Math.max(re(e,"track_front"),re(e,"track_rear"));return(t>0?t/2e3:.6)+.1}function Ap(e,t,r={}){if(!r.racingLine)return{asset:e,numerics:t,line:null};let n=r.params?Ky(r.params):void 0,o=Gy(e,{...r.line,...n?{carHalfWidth:n}:{}});return{asset:o.asset,numerics:{...t,fitSpacing:0},line:o}}function Vl(e,t,r={}){let n=Ap(e,t,r);return{track:Ot(n.asset,n.numerics),line:n.line}}function Hy(e=4,t=Vl){let r=new WeakMap;return(n,o,a={})=>{let s=a.racingLine===!0,i=s?[a.params?Ky(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 d=t(n,o,a);return l.set(c,d),l.size>e&&l.delete(l.keys().next().value),d}}var KF={racingLine:!1,standingStart:!1},wp=256;function Bl(e,t,r,n,o=KF,a=Vl){let s=wa(n),{racingLine:i,standingStart:c,lapCounts:l}=o;return e.map(u=>{let{track:d}=a(t,r,{racingLine:i,params:u});return My(Al(u,s,{track:d,numerics:r,standingStart:c,lapCounts:l}))})}function zy(e,t){let r=wa(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 Yy(e,t,r){let n={};for(let o of wa(e).metrics)n[o.key]=o.value(t,r);return n}var Cp=37;var Uy=287.05287,E5=461.495,Fp=9.80665/(Uy*.0065),I5=101325/(Uy*288.15),_5=273.15,N5=-500,O5=6e3,V5=400,B5=1100,Tp={source:"car",altitudeM:0,pressure:{kind:"standard"},humidityPct:0};function $5(e){return 101325*Math.pow(1-.0065*e/288.15,Fp)}function G5(e){return 288.15/.0065*(1-Math.pow(e/I5,1/(Fp-1)))}function K5(e){return 288.15/.0065*(1-Math.pow(e/101325,1/Fp))}function H5(e,t){return e*Math.pow(1-.0065*t/288.15,Fp)}function z5(e){return 611.21*Math.exp((18.678-e/234.5)*(e/(257.14+e)))}function Y5(e,t){switch(e.kind){case"standard":return $5(t);case"qnh":return H5(e.hPa*100,t);case"station":return e.hPa*100}}function $l(e,t,r=0,n=K5(e)){let o=t+_5,a=Math.min(.5*e,Math.max(0,Math.min(100,r))/100*z5(t)),s=e-a,i=s/(Uy*o)+a/(E5*o);return{altitudeM:n,p:e,pDry:s,T:o,rho:i,densityAltitudeM:G5(i)}}function HF(e,t){return $l(Y5(e.pressure,e.altitudeM),t,e.humidityPct,e.altitudeM)}var Wy=(e,t,r)=>Math.min(r,Math.max(t,e)),jy=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function Pp(e){if(!e||typeof e!="object")return structuredClone(Tp);let t=e,r=t.pressure??{},n=Wy(jy(r.hPa,1013.25),V5,B5),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:Wy(jy(t.altitudeM,0),N5,O5),pressure:o,humidityPct:Wy(jy(t.humidityPct,0),0,100)}}var Fa=e=>e?.source==="venue",Lp="the air the session states, at its venue";var W5=Math.PI/180;function j5(){return{ucaFront:[110,245,330],ucaRear:[-110,258,335],lcaFront:[130,185,112],lcaRear:[-130,205,116],tieInner:[-92,210,132],uprightUpper:[-6,542,352],uprightLower:[4,560,120],tieOuter:[-78,556,146],wheelCenter:[0,600,230],pushrodOuter:[8,520,128],rockerPivotA:[70,380,440],rockerPivotB:[-50,383,442],rockerToPushrod:[65,478.6,419.1],rockerToDamper:[10,280,440],damperChassis:[10,275,245]}}function U5(){return{ucaFront:[120,250,340],ucaRear:[-120,262,345],lcaFront:[140,190,118],lcaRear:[-140,210,122],tieInner:[120,215,150],uprightUpper:[-4,548,360],uprightLower:[6,566,126],tieOuter:[108,560,158],wheelCenter:[0,610,232],pushrodOuter:[10,526,132],rockerPivotA:[70,385,450],rockerPivotB:[-50,388,452],rockerToPushrod:[67,484.6,429.1],rockerToDamper:[12,286,450],damperChassis:[12,281,255]}}function Xy(e){let t=-e*W5;return te([0,Math.cos(t),Math.sin(t)])}function Dp(){let e={rodType:"push",pushrodAttach:"lowerArm",steerMode:"rack",spinAxis:Xy(-1),loadedRadius:230,springRate:35,rackAxis:[0,1,0]};return{hardpoints:j5(),config:e}}function Gl(){let e={rodType:"pull",pushrodAttach:"lowerArm",steerMode:"fixed",spinAxis:Xy(-1.5),loadedRadius:232,springRate:40,rackAxis:[0,1,0]};return{hardpoints:U5(),config:e}}function Ep(){let e=[-25,635,460],t=[-40,600,710],r={layout:"mcpherson",actuation:"direct",rodType:"push",pushrodAttach:"upright",steerMode:"rack",spinAxis:Xy(-.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 qy(){return{front:Dp(),rear:Gl(),config:{wheelbase:1600,trackFront:1200,trackRear:1220,frontAxleX:800}}}var X5=Math.PI/180;function zF(e){let t=-e*X5;return te([0,Math.cos(t),Math.sin(t)])}function Qy(e,t){let r=([l,u,d])=>[l*t.kx,u*t.ky,d*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:zF(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]=q5(o[l]);return{hardpoints:o,config:c}}function q5(e){return e.map(t=>Math.round(t*10)/10+0)}function Ta(e){return{name:e.name,front:Qy(Dp(),e.front),rear:Qy(Gl(),e.rear),config:{wheelbase:e.wheelbase,trackFront:e.trackFront,trackRear:e.trackRear,frontAxleX:e.wheelbase/2}}}function mi(e,t,r){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:t}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:r}}}}var di=600,Pa=610,pi=230,La=232;function Da(){let e=qy();return{...e,name:"Formula Student",front:{...e.front,config:{...e.front.config,actuation:"rocker"}},rear:{...e.rear,config:{...e.rear.config,actuation:"rocker"}}}}function Zy(){return Ta({name:"Formula 1",wheelbase:3600,trackFront:1600,trackRear:1600,front:{kx:1.3,ky:800/di,kz:355/pi,lowerInnerDz:-5,upperInnerDz:0,camberDeg:-3,loadedRadius:355,springRate:200},rear:{kx:1.3,ky:800/Pa,kz:355/La,lowerInnerDz:35,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:220}})}function Kl(){return mi(Ta({name:"GT car",wheelbase:2700,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/di,kz:325/pi,lowerInnerDz:18,upperInnerDz:5,camberDeg:-3.5,loadedRadius:325,springRate:110,actuation:"direct"},rear:{kx:1.2,ky:825/Pa,kz:325/La,lowerInnerDz:36,upperInnerDz:15,camberDeg:-2,loadedRadius:325,springRate:120,actuation:"direct"}}),318.6,318.6)}function Hl(){return mi(Ta({name:"Sports car",wheelbase:2750,trackFront:1550,trackRear:1550,front:{kx:1.15,ky:775/di,kz:320/pi,lowerInnerDz:36,upperInnerDz:15,camberDeg:-.5,loadedRadius:320,springRate:55,actuation:"direct"},rear:{kx:1.15,ky:775/Pa,kz:320/La,lowerInnerDz:57,upperInnerDz:25,camberDeg:-1,loadedRadius:320,springRate:60,actuation:"direct"}}),305.4,309)}function Q5(e,t,r,n,o,a){let s=Ep(),i=Object.fromEntries(Object.entries(s.hardpoints).map(([l,[u,d,p]])=>[l,[u,d+e,p]])),c=(l,u)=>{i[l]=[i[l][0],i[l][1],i[l][2]+u]};return c("lcaFront",t),c("lcaRear",t),c("tieInner",r),{hardpoints:i,config:{...s.config,spinAxis:zF(n),springRate:o,rackTravel:a}}}function YF(){return mi({name:"Cup car",front:Q5(55,-25,-23,-3.5,150,55),rear:Qy(Gl(),{kx:1.15,ky:820/Pa,kz:320/La,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 WF(){return{...mi(Ta({name:"Stock car",wheelbase:2794,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/di,kz:355/pi,lowerInnerDz:20,upperInnerDz:5,camberDeg:-2.5,loadedRadius:355,springRate:175,actuation:"direct"},rear:{kx:1.2,ky:825/Pa,kz:355/La,lowerInnerDz:40,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:150,actuation:"direct"}}),343.8,345.3),chassis:{boxes:[],body:"nascar"}}}function jF(){let e=mi(Ta({name:"Hill-climb prototype",wheelbase:2550,trackFront:1580,trackRear:1540,front:{kx:1.1,ky:790/di,kz:300/pi,lowerInnerDz:10,upperInnerDz:5,camberDeg:-2.5,loadedRadius:300,springRate:90},rear:{kx:1.1,ky:770/Pa,kz:300/La,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 UF(){let e=mi(Ta({name:"Race truck",wheelbase:3700,trackFront:2050,trackRear:1950,front:{kx:1.5,ky:1025/di,kz:506/pi,lowerInnerDz:40,upperInnerDz:10,camberDeg:-.5,loadedRadius:506,springRate:200,actuation:"direct"},rear:{kx:1.5,ky:975/Pa,kz:506/La,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 Ft=(e,t,r)=>({value:e,label:t,unit:r}),XF=(e,t)=>({...cn[e],value:t});function qF(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 Ea(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 Jn(e){let t={name:e.name,m:Ft(e.m,"vehicle mass (with driver)","kg"),A:Ft(e.A,"frontal area","m^2"),c_l:Ft(e.cl,"downforce coefficient","-"),c_w:Ft(e.cw,"drag coefficient","-"),l_to_d_ratio:Ft(e.cw>0?e.cl/e.cw:0,"lift-to-drag ratio","-"),driven_wheels:Ft(e.drivenWheels,"driven wheels","-"),fr_0:Ft(-.012,"rolling-resistance coefficient","-"),front_aero_diss:Ft(e.frontAero,"front aero distribution","-"),front_mass_diss:Ft(e.frontMass,"front mass distribution","-"),r_dyn:Ft(e.rDyn,"dynamic tyre radius","m"),rho:Ft(1.2,"air density","kg/m^3"),gear_ratio:Ft(e.gearRatio,"gear ratio","-"),effi_pgb:Ft(e.drivetrainEfficiency,"drivetrain efficiency","-"),capacity:Ft(e.capacityAh,"pack capacity","Ah"),soc:Ft(1,"state of charge","-"),ocv:Ft(e.ocv,"pack open-circuit voltage","V"),power_scale:Ft(1,"power scaling factor","-"),power_limit_kw:XF("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]=XF(r,n);return t}var fi={name:"Formula Student",m:300,A:1,cl:3,cw:1.3,frontMass:.47,frontAero:.45,rDyn:.222,drivenWheels:2,gearRatio:11.5,motor:qF(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}},ex={name:"Formula 1",m:798,A:1.5,cl:3,cw:.9,frontMass:.46,frontAero:.44,rDyn:.35,drivenWheels:2,gearRatio:4.9,motor:Ea(735,2e3,12500,2500,2),motorCount:1,driveline:{rear:Jt.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}},Ip={name:"GT car",m:1300,A:2,cl:1.4,cw:.42,frontMass:.5,frontAero:.42,rDyn:.33,drivenWheels:2,gearRatio:3.43,motor:Ea(410,2e3,8e3,2e3,2),motorCount:1,driveline:{rear:Jt.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}},_p={name:"Sports car",m:1600,A:2.2,cl:-.1,cw:.3,frontMass:.55,frontAero:.5,rDyn:.32,drivenWheels:2,gearRatio:3.14,motor:Ea(220,1500,6500,1400,2),motorCount:1,driveline:{rear:Jt.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}},tx={name:"Cup car",m:1265,A:2.1,cl:.45,cw:.4,frontMass:.62,frontAero:.45,rDyn:.31,drivenWheels:2,gearRatio:3.5,motor:Ea(250,2e3,7e3,1190,2),motorCount:1,motorPlacement:"front",driveline:{front:Jt.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}},rx={name:"Stock car",m:1620,A:2.2,cl:.6,cw:.45,frontMass:.53,frontAero:.45,rDyn:.35,drivenWheels:2,gearRatio:4.1,motor:Ea(500,2500,9e3,1680,2),motorCount:1,driveline:{rear:Jt.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}},nx={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:Ea(330,3e3,8500,1240,2),motorCount:1,driveline:{rear:Jt.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}},ox={name:"Race truck",m:5300,A:6.2,cl:-.1,cw:.65,frontMass:.6,frontAero:.6,rDyn:.502,drivenWheels:2,gearRatio:3.55,motor:Ea(880,100,3e3,88e3,2),motorCount:1,driveline:{rear:Jt.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 Jy(e,t,r){return Jn(r({...structuredClone(e),name:t}))}var Np={[fi.name]:Jn(fi),"Formula Student +15% downforce":Jy(fi,"Formula Student +15% downforce",e=>({...e,cl:e.cl*1.15,cw:e.cw*1.08})),"Formula Student -15 kg":Jy(fi,"Formula Student -15 kg",e=>({...e,m:e.m-15})),"Formula Student +15% power":Jy(fi,"Formula Student +15% power",e=>({...e,motor:qF(25*1.15,15e3,2e4),powerLimitKw:80*1.15})),[ex.name]:Jn(ex),[Ip.name]:Jn(Ip),[_p.name]:Jn(_p),[tx.name]:Jn(tx),[rx.name]:Jn(rx),[nx.name]:Jn(nx),[ox.name]:Jn(ox)},QF=Object.keys(Np),ax=QF.slice(0,4),sx=[fi.name,ex.name,Ip.name,_p.name,tx.name,rx.name,nx.name,ox.name];var jue={"Touring car":Ip.name,"Street car":_p.name};var Z5={bg:"#11141b",panel:"#161b22",panel2:"#202d3a",border:"#334050",borderBright:"#526477",sunken:"#0b1219",ink:"#06090d"},J5={normal:"#eef3fa",dim:"#9baab9",bright:"#ffffff",white:"#ffffff"},e$={label:"#c8d2dc",grid:"#39424e",gridFaint:"#232b35",empty:"#1a2028"},t$={accent:"#6aa8ff",accentInk:"#0d1b30",warn:"#ffb454",good:"#4ec9a0",bad:"#ff6b6b",badSoft:"#ff8f8f"},r$=["#f0e442","#7b68ee","#f7a8b8","#d55e00","#d8b4fe","#b5e48c"],Op={front:"#a6e22e",rear:"#00b4d8"},ZF=["#5b4bd6","#4aa3ff","#4ec9a0","#f0e442"],ix={power:"#ffb454",traction:"#f0845c",front:Op.front,rear:Op.rear,grip:"#73c9b3",braking:"#b48aff",crest:"#e88fd0",below:"rgba(214, 221, 230, 0.32)"},n$={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"},o$={x:"#ff6b6b",y:"#57c75a",z:"#4aa3ff"},a$={line:"#b4bfcb"},s$={compression:"#b48aff",tension:"#ff6b6b"},i$={fz:"#e7ecf3",fx:"#7ad7f0",fy:"#ff54c8"},c$={drivenLine:"#4d7cff",axis:"#eef3fa",slip:"#ffe81a",drive:ix.power,brake:ix.braking},l$={ground:"#101920",grid:"#1a2630",gridMajor:"#26343f",horizon:"#1d2833",bridge:"#6f7a86",coneLeft:"#2f63c9",coneRight:"#d9b51f",coneStart:"#ee7a2c"},u$={chassis:"#435160",volume:"#303b47",tyre:"#435160",tyreLine:"#39424e",tyreFace:"#1c232d"},m$={centreLine:"#4aa3ff",corridorFill:"rgba(74,163,255,0.10)",boundary:"#3d4956",racingLine:"#ffb454",start:"#e7ecf3",finish:"#ff6b6b",direction:"#8b96a3"},d$={SURFACE:Z5,TEXT:J5,CHART:e$,ROLE:t$,SERIES:r$,AXLE:Op,LAP_SPEED:ZF,LIMITER:ix,RIG:n$,AXIS:o$,CONSTRUCTION:a$,FORCE:s$,TYRE_FORCE:i$,REPLAY:c$,SCENERY:l$,BODY:u$,TRACK:m$},JF=e=>Object.fromEntries(Object.entries(e).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):Object.freeze({...r})])),Vp=JF(d$),tr=Vp.SERIES,eT=(()=>{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 JF({SURFACE:{bg:"#f5f6f6",panel:"#fcfcfd",panel2:"#ffffff",border:"#d8dfe6",borderBright:"#b7c3ce",sunken:"#e8edf2",ink:"#ffffff"},TEXT:{normal:"#17212c",dim:"#606c79",bright:"#10171f",white:"#000000"},CHART:{label:"#3a424b",grid:"#c2c8cd",gridFaint:"#e2e5e7",empty:"#e8eae7"},ROLE:{accent:"#2162bd",accentInk:"#ffffff",warn:e,good:"#0f8a66",bad:t,badSoft:"#e2696d"},SERIES:["#b5a11a","#2844e3","#f47ec1","#9b3a1b","#764299","#58b977"],AXLE:r,LAP_SPEED:["#4b3bc4","#1a64c2","#0f8a66","#a87e00"],LIMITER:n,RIG:{chassis:"#1a64c2",ballJoint:"#c27200",arm:"#56616d",tie:"#24907b",pushrod:"#a3820f",rocker:"#6656b8",kingpin:"#8f7f10",arbBar:"#b04d77",arbArm:"#9a4767",arbLink:"#c27200",heaveSpring:"#1688ad",wheelCentre:"#15181c",contactPatch:t,ground:"#e2e6e8",groundFaint:"#edf0f1"},AXIS:{x:"#d93a3a",y:"#2f9d34",z:"#1a64c2"},CONSTRUCTION:{line:"#5a6570"},FORCE:{compression:"#7b55d0",tension:t},TYRE_FORCE:{fz:"#ffe600",fx:"#0f8fb0",fy:"#c8198f"},REPLAY:{drivenLine:"#2f5be0",axis:"#15181c",slip:"#c79a00",drive:n.power,brake:n.braking},SCENERY:{ground:"#dde3e1",grid:"#ccd3d1",gridMajor:"#b5bfbc",horizon:"#e8edf0",bridge:"#9aa3ab",coneLeft:"#2f63c9",coneRight:"#d9b51f",coneStart:"#ee7a2c"},BODY:{chassis:"#a9b3bd",volume:"#c7ced5",tyre:"#24282c",tyreLine:"#2c333a",tyreFace:"#c3cad0"},TRACK:{centreLine:"#1a64c2",corridorFill:"rgba(26,100,194,0.10)",boundary:"#a3acb4",racingLine:e,start:"#15181c",finish:t,direction:"#5c6570"}})})();var tT=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},Xue=(()=>{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=eT[r];for(let a of Object.keys(n)){let s=tT(n[a]);s&&!e.has(s)&&e.set(s,o[a])}}return e})();var rT=(e,t)=>new Set(t.flatMap(r=>{let n=e[r];return Array.isArray(n)?[...n]:Object.values(n)}).map(tT).filter(r=>r!==null)),que=rT(eT,["SERIES","AXLE","LAP_SPEED","LIMITER","ROLE","RIG","FORCE","TYRE_FORCE","REPLAY","AXIS","TRACK","CONSTRUCTION"]),Que=rT(Vp,Object.keys(Vp).filter(e=>e!=="SURFACE"));function cx(){return{kind:"simple",name:"Simple motor",rpm:[0,16e3,2e4],torque:[21,21,14],efficiency:.95}}function lx(){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 ux(){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 mx(){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 dx(){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 nT(){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 oT(){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 aT(){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 sT(){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 iT(){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 cT(){return{kind:"ice",name:"Race truck diesel six, 13 l (example)",rpm:[800,1e3,1200,1400,1600,1800,2e3,2200,2400,2600,2800,3e3],torque:[3e3,4e3,4900,5500,5250,4670,4200,3820,3500,3230,3e3,2700],idleRpm:800,limitRpm:3e3,inertia:1.5,gearbox:{primary:1,ratios:[16,12.44,9.67,7.51,5.84,4.54,3.53,2.74,2.13,1.66,1.29,1],efficiency:.92,upshiftTime:.35,downshiftTime:.35},breathing:{induction:{kind:"boosted",boostKPa:350,maxPressureRatio:4.3}}}}function lT(e){return Sa(p$(e))}function p$(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;let t={...e};return delete t.name,delete t.parts,Array.isArray(t.vehicles)&&(t.vehicles=t.vehicles.map(r=>{if(r===null||typeof r!="object"||Array.isArray(r))return r;let n={...r};return delete n.name,n})),t}function zl(e,t){return{...t,fingerprint:lT(e)}}var uT="CC-BY-4.0",f$={title:"PaceDynamics built-in library",url:"https://pacedyn.dev/",licence:uT},mT={fidelity:"generic",licence:uT,sources:[f$]};var Bp=e=>zl(e,mT);var dT=["raw.githubusercontent.com"],pT=["tum-csv"],b$=/^[0-9a-f]{64}$/;function Wl(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"||!b$.test(r)||!pT.includes(n))return!1;try{let o=new URL(t);return o.protocol==="https:"&&dT.includes(o.hostname)&&!o.username&&!o.password&&!o.port}catch{return!1}}var $p=e=>new URL(e.url).hostname;async function fT(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 g$(e){let t=new URL(e).pathname.split("/").pop()??"";return decodeURIComponent(t).replace(/\.[^.]*$/,"")||"Linked track"}function y$(e,t){let r=[],n=[],o=[],a=[];for(let[s,i]of e.split(/\r?\n/).entries()){let c=i.trim();if(!c||c.startsWith("#"))continue;let l=c.split(",").map(u=>Number(u.trim()));if(l.length!==4||!l.every(Number.isFinite))throw new Error(`Line ${s+1} of ${t} is not four numbers.`);r.push(l[0]),n.push(l[1]),o.push(l[2]),a.push(l[3])}if(r.length<3)throw new Error(`${t} has ${r.length} points; a track needs at least 3.`);return{name:t,x:r,y:n,widthLeft:a,widthRight:o,closed:!0,fit:"interpolate"}}var x$={"tum-csv":y$};function hT(e,t){return x$[t.format](e,g$(t.url))}async function px(e,t,r){let n=await fT(e);if(n!==t.sha256)throw new Error(`${$p(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=hT(new TextDecoder().decode(e),t),a=await Gp(o);if(a!==r)throw new Error(`Linked track ${r} does not convert to its name (it is ${a}).`);return o}var fx=20,v$=new RegExp(`^[0-9a-f]{${fx}}$`),jl=e=>typeof e=="string"&&v$.test(e);async function Gp(e){let t=new TextEncoder().encode(Co(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,fx)}var hx=e=>`tracks/${e}.json`;var k$=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function bx(e){return{model:{name:e.name,source:e.source},...e.provenance?{provenance:e.provenance}:{}}}async function gx(e,t){if(!k$(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 Gp(e);if(r!==t)throw new Error(`Catalogue track ${t} does not match its name (it is ${r}).`);return e}var Ia=(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}),Fo=[Ia("suspensions","suspensionId","suspension"),Ia("tires","tireModelId","tyre",[{key:"tiresRear",ref:"tireModelIdRear",label:"rear tyre"}]),Ia("motors","motorModelId","motor"),Ia("aeros","aeroModelId","aero map"),Ia("batteries","batteryModelId","battery"),Ia("brakes","brakeModelId","brakes"),Ia("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 Kp(e){let t={...e};for(let r of Fo)for(let n of r.refs)delete t[n];return t}var Hp=tr,Ul=Hp,yx=Hp,To=[...tr.slice(3),...tr.slice(0,3)],vx=[...tr.slice(1),tr[0]],xx=[...tr.slice(2),...tr.slice(0,2)],Rx=[...tr.slice(4),...tr.slice(0,4)],kx=[...tr.slice(5),...tr.slice(0,5)],Xl=[...tr.slice(2),...tr.slice(0,2)];function Mx(){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 Sx(e,t,r){let n=Np[e];if(!n)throw new Error(`no preset vehicle named "${e}"`);return{id:t,params:{...qc(structuredClone(n)),energy:{...Vn},suspensionId:"sus1"},visible:!0,color:Ul[r%Ul.length]}}function A$(){return ax.map((e,t)=>Sx(e,`v${t+1}`,t))}function w$(){return[Ac(),eg(),tg(),rg(),ng(),og(),ag(),sg(),ig(),cg()].map((t,r)=>({id:`t${r+1}`,color:yx[r%yx.length],model:t}))}function C$(){return[_h(),Nh(),Oh(),Vh(),Bh(),$h(),Gh(),Kh()].map((t,r)=>({id:`a${r+1}`,color:xx[r%xx.length],model:t}))}function F$(){return[Rh(),vh(),kh()].map((t,r)=>({id:`b${r+1}`,color:Rx[r%Rx.length],model:t}))}function T$(){return[{id:"brk1",color:kx[0],model:structuredClone(Fg)}]}function P$(){return[{id:"dmp1",color:Xl[0],model:structuredClone(hd)}]}function L$(){return[cx(),lx()].map((t,r)=>({id:`m${r+1}`,color:To[r%To.length],model:t}))}function Ax(e){let t=r=>({...r,provenance:Bp(r.model)});return{...e,suspensions:e.suspensions.map(t),vehicles:e.vehicles.map(r=>({...r,provenance:Bp(Kp(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 ql(e="Untitled project"){let t=new Date().toISOString(),r=A$();return Ax({schemaVersion:Cp,meta:{id:Mx(),name:e,domain:"racecar",rulesetId:Aa,createdAt:t,updatedAt:t},suspensions:[{id:"sus1",color:vx[0],model:Da()}],activeSuspensionId:"sus1",vehicles:r,activeVehicleId:r[0]?.id??null,tires:w$(),motors:L$(),aeros:C$(),batteries:F$(),brakes:T$(),dampers:P$(),tracks:[],activeTrackId:null,mathChannels:[],rulesets:[],studies:[],activeStudyId:null,loadCases:[],reportLayouts:[],tyreSheets:[],kinSheets:[],lapSheets:[],plans:[],results:[],settings:{numerics:{...ml},ggvMode:"twoTrack",quasiTransient:!1,motorThermal:!1,brakeFade:!1,airTempC:lr,air:structuredClone(Tp),diffYaw:!1,lapCounts:{},pathPlanId:null,useRacingLine:!0,standingStart:!1}})}var D$=["front","rear"],wx=9.81,E$=Math.PI/180;var gn="*",Cx=40,bT=.8;function Fx(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 gT(e,t,r){let n=t.rows.map(c=>c.v),o=c=>Ct(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/wx*100)/100+0,axG:Math.round(u/wx*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(Cx/3.6,o(Cx/3.6),0);let c=10;for(let l=0;l<30;l++)c=Math.min(s,Math.sqrt(r*o(c)));return a(c,o(c),0)}case"fastCorner":return a(bT*s,o(bT*s),0);case"braking":{let c=i.reduce((l,u)=>t.axDecel(u,0)<t.axDecel(l,0)?u:l);return a(c,0,t.axDecel(c,0))}case"traction":{let c=i.reduce((l,u)=>t.axAccel(u,0)>t.axAccel(l,0)?u:l);return a(c,0,t.axAccel(c,0))}case"topSpeed":return a(s,0,0)}}function Tx(e,t,r){let n=!1,o=e.map(a=>{if(!a.follows)return a;let s=gT(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 Px(e,t){let r=e.speedKmh/3.6,n=e.ayG*wx;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)/E$}var yT=e=>e.ayG<0?"L":"R";function Lx(e,t=D$){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 Dx=(e,t)=>e.travelMin===t.travelMin&&e.travelMax===t.travelMax&&e.rollMaxDeg===t.rollMaxDeg&&e.rollAtLimitDeg===t.rollAtLimitDeg;var eo=Math.PI/180,I$=9.81,Ql=.1,Ex=20,xT=6,MT=50;function RT(e,t,r){let n=e(0),o=0;for(let p=t;p<=r+1e-9;p+=t){let m=e(p);if(m>n)n=m,o=p;else if(p>o+3*t)break}let a=Math.max(0,o-t),s=Math.min(r,o+t),i=.6180339887498949,c=s-i*(s-a),l=a+i*(s-a),u=e(c),d=e(l);for(let p=0;p<14;p++)u>d?(s=l,l=c,d=u,c=s-i*(s-a),u=e(c)):(a=c,c=l,u=d,l=a+i*(s-a),d=e(l));return u>n?u>=d?{force:u,at:c}:{force:d,at:l}:d>n?{force:d,at:l}:{force:n,at:o}}function Ix(e,t,r,n,o){let a=o*eo;if(t==="side")return RT(i=>r*e.Fy(r*i*eo,n,a),1,45);let s=t==="drive"?1:-1;return RT(i=>s*e.Fx(s*i,n,a),.02,.6)}function Yp(e){let t=e?Tm(e)?.gamma:void 0,r=[t?.min,t?.max].filter(o=>o!==void 0&&Number.isFinite(o));if(!r.length)return{lo:-xT,hi:xT,stated:!1};let n=Math.max(...r.map(Math.abs))/eo;return{lo:-n,hi:n,stated:!0}}function _$(e,t,r){if(!(r>t))return t;let n=Math.max(2,Math.ceil(r-t)+1),o=(r-t)/(n-1),a=t,s=-1/0;for(let h=0;h<n;h++){let b=t+h*o,g=e(b);g>s&&(s=g,a=b)}let i=Math.max(t,a-o),c=Math.min(r,a+o),l=.6180339887498949,u=c-l*(c-i),d=i+l*(c-i),p=e(u),m=e(d);for(let h=0;h<12;h++)p>m?(c=d,d=u,m=p,u=c-l*(c-i),p=e(u)):(i=u,u=d,p=m,d=i+l*(c-i),m=e(d));let f=p>=m?{g:u,v:p}:{g:d,v:m};return f.v>s?f.g:a}var vT=250,kT=new WeakMap;function N$(e,t,r,n,o,a,s){let i=kT.get(e);i||kT.set(e,i=new Map);let c=`${t}|${n}|${o}|${s.lo}|${s.hi}`,l=i.get(c);l||i.set(c,l=new Map);let u=f=>{let h=l.get(f);if(h===void 0){let b=Math.max(50,f*vT);h=_$(g=>Ix(r,n,o,b,g).force,s.lo,s.hi),l.set(f,h)}return h},d=Math.max(0,a)/vT,p=Math.floor(d),m=d-p;return m<1e-9?u(p):u(p)*(1-m)+u(p+1)*m}function hi(e,t){return t==="front"?e.tireModel:e.tireModelRear??e.tireModel}var O$=new WeakMap,V$=new WeakMap,B$=new WeakMap,_x=(e,t,r)=>{let n=e.get(t);return n===void 0&&e.set(t,n=r()),n};function Wp(e,t){let r=hi(e,t);return r?_x(O$,r,()=>yc(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 Nx(e,t){let r=hi(e,t);return r?_x(B$,r,()=>Pm(r).none)?"This tyre file has no drive or brake grip.":_x(V$,r,()=>{let n=Ke(r),o=r.kind==="magic"?r.fnomin:r.nominalLoad,a=n.Fx(.1,o,0),s=n.Fx(.1,o,3*eo);return Number.isFinite(a)&&Number.isFinite(s)&&Math.abs(s-a)>1})?null:"This tyre\u2019s drive and brake grip does not change with camber.":"The car runs the built-in simple tyre, which has no camber term."}function _a(e,t){return e==="side"||e==="ackermann"?Math.abs(t.ayG)>=Ql?e==="ackermann"&&!(ST(t)<=Ex)?`is a corner wider than ${Ex} m`:null:"does not corner":(e==="drive"?t.axG:-t.axG)>=Ql?null:e==="drive"?"does not drive":"does not brake"}var $$=e=>e.axG>=Ql?"drive":e.axG<=-Ql?"brake":null;function ST(e){let t=e.speedKmh/3.6,r=Math.abs(e.ayG)*I$;return r>1e-9?t*t/r:1/0}var zp=(e,t)=>`${e==="front"?"F":"R"}${t}`,G$=e=>e==="L"?"R":"L",K$=(e,t,r)=>Math.min(r,Math.max(t,e));function Ox({ev:e,params:t,input:r,state:n,pose:o}){let a=`${re(t,"grip_scale")}|${re(t,"stiffness_scale")}`,s=ST(n),i=r.wheelbase*(1-r.frontMassFrac)/1e3,c=r.wheelbase*r.frontMassFrac/1e3,l=r.wheelbase/1e3,u=v=>(v==="front"?r.trackFront:r.trackRear)/2e3,d=(v,k,R,M,S)=>{let w=we(e,v),F=hi(t,v),T=Math.max(0,o.loads[k]),A=o.camber[k],C=K$(A,S.lo,S.hi),P=Ix(w,R,M,T,C),L=T<MT,E=F&&!L?N$(F,a,w,R,M,T,S):C,_=L?P.force:Ix(w,R,M,T,E).force,D=.05;return{corner:k,Fz:T,lifted:L,camber:A,read:C,outside:C!==A,wants:E,atEdge:!L&&(E-S.lo<D||S.hi-E<D),peak:P.force,slip:P.at,best:_}},p=(v,k,R)=>{let M=k[0].best+k[1].best,S=k[0].peak+k[1].peak;return{kind:v,wheels:k,lossCamber:M>0?Math.max(0,1-S/M):NaN,range:R}},m=new Map,f=v=>{if(m.has(v))return m.get(v)??null;let k=null;if(!_a("side",n)){let R=Yp(hi(t,v));k=[d(v,zp(v,o.outer),"side",1,R),d(v,zp(v,G$(o.outer)),"side",-1,R)]}return m.set(v,k),k},h=new Map,b=new Map,g=new Map,y=(v,k,R)=>{let M=v==="front"?i:-c,S=(k?1:-1)*u(v),w=R*eo;return Math.atan2(M+s*Math.sin(w),s*Math.cos(w)-S)/eo},x=v=>(n.ayG<0?-1:1)*o.steer[v];return{side(v){if(h.has(v))return h.get(v)??null;let k=Wp(t,v)?null:f(v),R=k?p("side",k,Yp(hi(t,v))):null;return h.set(v,R),R},long(v){if(b.has(v))return b.get(v)??null;let k=$$(n),R=null;if(k&&!Nx(t,v)){let M=Yp(hi(t,v));R=p(k,[d(v,zp(v,"L"),k,1,M),d(v,zp(v,"R"),k,1,M)],M)}return b.set(v,R),R},toeLoss(v){let k=g.get(v);if(k!==void 0)return k;let R=f(v),M=NaN;if(R&&R[0].peak+R[1].peak>0){let S=we(e,v),[w,F]=R,T=[{g:w,dt:1,inner:!1,steer:x(w.corner)},{g:F,dt:-1,inner:!0,steer:x(F.corner)}],A=_=>T.reduce((D,I)=>{let V=I.steer-y(v,I.inner,_);return D+I.dt*S.Fy(I.dt*V*eo,I.g.Fz,I.g.read*eo)},0),C=T.map(_=>_.steer-_.g.slip-y(v,_.inner,0)),P=Math.min(...C)-2,L=Math.max(...C)+2,E=H$(A,P,L,.25);M=Math.max(0,1-E/(w.peak+F.peak))}return g.set(v,M),M},ackermann(){if(_a("ackermann",n))return NaN;let v=f("front");if(!v||v[0].lifted||v[1].lifted)return NaN;let[k,R]=v,M=Math.sqrt(Math.max(s*s-c*c,1e-6)),S=u("front"),w=(Math.atan(l/(M-S))-Math.atan(l/(M+S)))/eo;if(!(w>.001))return NaN;let F=x(R.corner)-x(k.corner),T=w+(R.slip-k.slip);return 100*(F-T)/w}}}function H$(e,t,r,n){let o=-1/0,a=t;for(let m=t;m<=r+1e-9;m+=n){let f=e(m);f>o&&(o=f,a=m)}let s=a-n,i=a+n,c=.6180339887498949,l=i-c*(i-s),u=s+c*(i-s),d=e(l),p=e(u);for(let m=0;m<14;m++)d>p?(i=u,u=l,p=d,l=i-c*(i-s),d=e(l)):(s=l,l=u,d=p,u=s+c*(i-s),p=e(u));return Math.max(o,d,p)}var z$=9.81,AT=Math.PI/180,bi={speed:20,ayG:1.2};function Vx(e,t={}){let r=t.operating??bi,n=t.assemble,o,a,s,i=new Map,c=new Map,l=new Map,u=new Map,d=new Map,p=k=>({speed:k?.speed!==void 0&&Number.isFinite(k.speed)&&k.speed>0?k.speed:r.speed,ayG:k?.ayG!==void 0&&Number.isFinite(k.ayG)?k.ayG:r.ayG}),m=()=>{if(o!==void 0)return o;if(!n)return o=null;try{o=n(e)}catch{o=null}return o},f=()=>{if(a!==void 0)return a;try{a=un(e.params)}catch{a=null}return a},h=k=>{let R=p(k),M=`${R.speed}|${R.ayG}`,S=i.get(M);if(S!==void 0)return S;let w=f();if(!w)return i.set(M,null),null;let F={cornerStiffness:T=>w.corneringStiffness(T),ayG:R.ayG,speed:R.speed,fyAxle:(T,A)=>2*w.Fy(T,A/2),tire:w};return i.set(M,F),F},b=()=>{if(s!==void 0)return s;let k=m(),R=f();if(!k||!R)return s=null;try{s=sa(R,k.massTotal*z$*1.2)}catch{s=null}return s},g=k=>{let R=p(k).speed,M=`${R}`,S=c.get(M);if(S!==void 0)return S;let w=m(),F=f(),T=null;if(w&&F)try{T=v0(w,F,R,{steering:!1})}catch{T=null}return c.set(M,T),T},y=k=>{let R=`${k.speedKmh}|${k.ayG}|${k.axG}`,M=d.get(R);if(M!==void 0)return M;let S=null,w=m();try{let F=w?.kinFront,T=w?.kinRear;if(w&&F&&T){let A=Px(k,w.wheelbase),C=k.speedKmh/3.6,P=yo(w,F,T,C)(k.ayG,k.axG,0,A),L={FL:P.FL.travel,FR:P.FR.travel},E=ca(w,A*AT,L),_=A?E.camber:null,D={},I={};for(let O of["FL","FR","RL","RR"]){let B=O[1]==="R"?P[O].camberRoad:0-P[O].camberRoad;D[O]=B+(_?.[O]??0),I[O]=E.steer[O]/AT+(O[1]==="R"?1:-1)*P[O].bumpToe}let V=We(w,k.ayG,k.axG,C,0,A,L,P.steeringJacking);S={corners:P,rollDeg:P.FL.camberRoad-P.FL.camber,steerDeg:A,camber:D,outer:yT(k),loads:V,steer:I}}}catch{S=null}return d.set(R,S),S},x=new Map;return{operating:r,dynAvailable:!!n,poseAt:y,tyreAt:k=>{let R=`${k.speedKmh}|${k.ayG}|${k.axG}`,M=x.get(R);if(M!==void 0)return M;let S=y(k),w=m(),F=f(),T=S&&w&&F?Ox({ev:F,params:e.params,input:w,state:k,pose:S}):null;return x.set(R,T),T},operatingAt:p,dynInput:m,tyre:f,dynCtx:h,grip:b,ymd:g,ymdLimit:k=>{let R=`${p(k).speed}`,M=l.get(R);if(M!==void 0)return M;let S=g(k),w=S?ay(S):null;return l.set(R,w),w},reserves:(k,R)=>{let M=p(R),S=`${k}|${M.speed}|${M.ayG}`,w=u.get(S);if(w!==void 0)return w;let F=m(),T=h(R),A=null;if(F&&T)try{A=yl(F,T,k,b()??void 0)}catch{A=null}return u.set(S,A),A}}}var wT=["widthLeft","widthRight","bank","mu"];function Zl(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 Bx(e){let t=Zl(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 Up(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),d=l.to>=c-1e-9;for(let p of wT){let m=l[p];if(m===void 0)continue;let f=s[p],h=r[p];for(let b=0;b<o&&t[b]<l.from;b++)h=f[b];for(let b=0;b<o;b++){let g=t[b];if(g<l.from||g>=l.to&&!(d&&g>=c-1e-9))continue;let y=g-l.from;f[b]=u>0&&y<u?h+(m-h)*(y/u):m}}}return s}function Xp(e,t,r){if(!t.length)return e;let n=Zl(e),o=n.length,a={widthLeft:jp(e.widthLeft,r.widthLeft),widthRight:jp(e.widthRight,r.widthRight),bank:jp(e.bank,r.bank),mu:jp(e.mu,r.mu)},s={};for(let c of wT){let l=e[c];Array.isArray(l)&&l.length===o&&(s[c]=l)}let i=Up(t,n,a,s);return{...e,...i}}function jp(e,t){return typeof e=="number"?e:t}var TT=1,CT=4,Qp=Math.PI/180,$x=e=>e===null||!Number.isFinite(e)||e===0?0:1/e;function Gx(e){return e.kind==="arc"?Math.abs(e.radius)*Math.abs(e.angle)*Qp:e.length}function qp(e,t){return e.kind==="straight"?0:e.kind==="arc"?$x(e.radius):t}function FT(e){return e.kind==="straight"?0:e.kind==="arc"?$x(e.radius):$x(e.endRadius)}var Jl=(e,t,r,n,o)=>e+t*o+(n>0?(r-t)*o*o/(2*n):0);function eu(e,t={}){let r=Math.max(.05,t.spacing??TT),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((A,C)=>A+Gx(C),0),d=Math.max(n?3:2,Math.round(u/r)),p=u>0?u/d:r,m=o.x,f=o.y,h=o.heading*Qp,b=e.length?qp(e[0],0):0,g=0,y=p,x=(A,C,P)=>{s.push(A),i.push(C),c.push(P)};x(m,f,0);let v=(A,C,P,L,E)=>{let _=E-L;if(_<=0)return;if(Math.abs(C-A)<1e-12){let I=Jl(h,A,A,P,L);if(Math.abs(A)<1e-12)m+=_*Math.cos(I),f+=_*Math.sin(I);else{let V=I+A*_;m+=(Math.sin(V)-Math.sin(I))/A,f+=-(Math.cos(V)-Math.cos(I))/A}return}let D=_/CT;for(let I=0;I<CT;I++){let V=L+I*D,O=Jl(h,A,C,P,V),B=Jl(h,A,C,P,V+D/2),z=Jl(h,A,C,P,V+D);m+=D/6*(Math.cos(O)+4*Math.cos(B)+Math.cos(z)),f+=D/6*(Math.sin(O)+4*Math.sin(B)+Math.sin(z))}};for(let A of e){let C=Gx(A),P=qp(A,b),L=FT(A);if(l.push({from:g,to:g+C,...A.widthLeft!==void 0?{widthLeft:A.widthLeft}:{},...A.widthRight!==void 0?{widthRight:A.widthRight}:{},...A.bank!==void 0?{bank:A.bank}:{},...A.mu!==void 0?{mu:A.mu}:{},...A.ramp!==void 0?{ramp:A.ramp}:{}}),C<=0){b=L;continue}let E=0;for(;y<=g+C+1e-9;){let _=Math.min(C,y-g);v(P,L,C,E,_),E=_,x(m,f,g+_),y+=p}v(P,L,C,E,C),h=Jl(h,P,L,C,C),b=L,g+=C}let k=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?qp(e[0],b):0,S={gap:k,headingError:Y$((h-o.heading*Qp)/Qp),curvatureError:b-M},w=[];for(let A=0;A<e.length;A++){let C=FT(e[A]),P=A+1<e.length?e[A+1]:n?e[0]:null;if(!P)continue;let L=qp(P,C);w.push({index:A,before:C,after:L,jump:Math.abs(L-C)})}let F=Up(l,c,a);return{asset:{name:t.name??"Track",x:s,y:i,fit:"interpolate",...n?{}:{closed:!1},...F},sections:l,joints:w,closure:S,length:R}}function Y$(e){let t=e%360;return t>180&&(t-=360),t<-180&&(t+=360),t}var W$={halfWidthM:1.5,spacingM:.5};function tu(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 ${LT(e).toFixed(0)} m`}}}function LT(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 DT=e=>e.kind==="skidpad"||e.kind==="curves"&&e.closed===!0,ET=e=>e.kind==="acceleration",IT=1.5,_T=3;function j$(e,t){let r=e.offsetM,n=e.pitchM,o=Math.max(1,e.gates)*n,a=Math.max(0,e.leadInM),s=IT*n,i=h=>{let b=Math.min(1,Math.max(0,h));return b*b*b*(b*(b*6-15)+10)},c=h=>Math.min(i(h/s),i((o-h)/s)),l=r*(Math.PI/n)**2,u=l>0?Math.max(.05,Math.min(t.spacingM,1/l*(_T*Math.PI/180))):t.spacingM,d=[],p=[],m=Math.max(1,Math.round(a/u));for(let h=0;h<m;h++)d.push(-a+a*h/m),p.push(0);let f=Math.max(8,Math.round(o/u));for(let h=0;h<=f;h++){let b=o*h/f;d.push(b),p.push(r*c(b)*Math.sin(Math.PI*b/n))}return{name:tu(e),x:d,y:p,closed:!1,widthLeft:t.halfWidthM,widthRight:t.halfWidthM,fit:"interpolate"}}function U$(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 Kx(e,t={}){let r={...W$,...t},n=ET(e),o=U$(e);if(!o){let u=j$(e,r);return{asset:u,peakCurvature:PT(u),worstJoint:0,standingStart:n}}let a=DT(e),s=o.reduce((u,d)=>d.kind==="arc"?Math.min(u,Math.abs(d.radius)):u,1/0),i=Number.isFinite(s)?Math.max(.05,Math.min(r.spacingM,s*(_T*Math.PI/180))):r.spacingM,c=eu(o,{name:tu(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:PT(c.asset),worstJoint:l.reduce((u,d)=>Math.max(u,d.jump),0),standingStart:n}}function PT(e){try{return Math.max(...Ot(e).curvature.map(Math.abs))}catch{return NaN}}var gi={courses:[{id:"c1",course:{kind:"manoeuvre",spec:{kind:"skidpad",radiusM:8.375}}}],ggvMode:"twoTrack"};function Hx(e){return e.course.kind==="project"?"the project\u2019s track":e.course.kind==="track"?e.course.name:tu(e.course.spec)}var Jp=()=>({courses:gi.courses.map(e=>({...e})),ggvMode:gi.ggvMode}),NT=new WeakMap,Zp=new Map;function OT(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=Zp.get(n);if(o)return{...o,numerics:r};let a=Kx(e.spec),s={asset:a.asset,standingStart:a.standingStart};return Zp.size>64&&Zp.clear(),Zp.set(n,s),{...s,numerics:r}}function zx(e,t,r={}){let n=r.lap??gi,o=r.simParams,a=r.numerics??{},s=n.courses.length?n.courses:gi.courses,i,c,l,u=new Map,d=new Map,p=new Map,m=new Map,f=v=>(v?.courseId?s.find(k=>k.id===v.courseId):void 0)??s[0],h=()=>{if(i!==void 0)return i;if(!o)return i=null;try{i={...o(e),ggvMode:n.ggvMode}}catch{i=null}return i},b=v=>{let k=f(v);if(!k)return null;let R=d.get(k.id);if(R!==void 0)return R;let M=OT(k.course,r,a),S=null;if(M)try{let w=JSON.stringify(M.numerics),F=NT.get(M.asset);F||(F=new Map,NT.set(M.asset,F));let T=F.get(w);T||(T=Ot(M.asset,M.numerics),F.set(w,T)),S={id:k.id,track:T,standingStart:M.standingStart,numerics:M.numerics,name:M.asset.name}}catch{S=null}return d.set(k.id,S),S},g=()=>{if(c!==void 0)return c;let v=h();if(!v)return c=null;try{l=ur(v),c=pn(l,!1,n.ggvMode)}catch{c=null}return c},y=v=>{let k=b(v);if(!k)return null;let R=p.get(k.id);if(R!==void 0)return R;let M=g(),S=null;if(M)try{let w=l?va(l,M,[k.track],k.numerics,n.ggvMode,u):void 0,F=l?Ao(l,M.rows):void 0;S=er(M,k.track,k.numerics,{standingStart:k.standingStart,...w?{load:w}:{},...F?{shifts:F}:{}})}catch{S=null}return p.set(k.id,S),S};return{lapSettings:n,get lapAvailable(){return!!o&&s.some(v=>!!OT(v.course,r,a))},lapParams:h,courses:()=>s,course:b,ggv:g,lap:y,lapReserve:v=>{let k=b(v);if(!k)return null;let R=m.get(k.id);if(R!==void 0)return R;let M=y(v),S=t.dynInput(),w=t.tyre(),F=null;if(M&&S&&w)try{let T=h();F=rp(S,w,mp({...M,ds:k.track.ds,rows:g()?.rows,gradient:k.track.gradient,bank:k.track.bank,mu:k.track.mu}),T?{driven:Hg(T)}:{})}catch{F=null}return m.set(k.id,F),F}}}var VT=180/Math.PI,Yx={rise:0,sinPitch:0,sinRoll:0};function BT(e){let t=e.kc;return t?$T(e.vehicle,r=>t.ground0[r]):Yx}function $T(e,t){let r=e.config,n=fo(r),o=0,a=0,s=0,i=0,c=0,l=0,u=0,d=0,p=0;for(let g of Zr){let y=ze(g,r),x=y.axleX-n,v=y.sideSign*ir(e,y.isFront)/2,k=t(g);if(!Number.isFinite(k))return Yx;o++,a+=x,s+=v,i+=k,c+=x*x,l+=v*v,u+=x*v,d+=x*k,p+=v*k}let m=o*(c*l-u*u)-a*(a*l-u*s)+s*(a*u-c*s);if(!(Math.abs(m)>1e-9))return{rise:i/o,sinPitch:0,sinRoll:0};let f=(i*(c*l-u*u)-a*(d*l-u*p)+s*(d*u-c*p))/m,h=(o*(d*l-u*p)-i*(a*l-u*s)+s*(a*p-d*s))/m,b=(o*(c*p-d*u)-a*(a*p-d*s)+i*(a*u-c*s))/m;return{rise:f,sinPitch:h,sinRoll:-b}}function ru(e,t){let r=e.kc,n=$T(e.vehicle,o=>(r?r.ground0[o]:0)+t[o]);return te([-n.sinPitch,n.sinRoll,1])}function Wx(e,t,r,n){let o=te(Tn(e,ze(t,r)));return-Math.asin(Math.max(-1,Math.min(1,J(o,n))))*VT}function ef(e,t,r,n,o){let a=te(Tn(n,ze(t,r))),s=te([1-a[0]*a[0],-a[0]*a[1],-a[0]*a[2]]),i=le(a,s),c=m=>[J(m,s),J(m,i),J(m,a)],l=m=>oe(oe(X(s,m[0]),X(i,m[1])),X(a,m[2])),u=e.points,d=c(u.spinAxis),p=Xi({uprightUpper:c(u.uprightUpper),uprightLower:c(u.uprightLower),wheelCenter:c(u.wheelCenter),spinAxis:d,tieOuter:c(u.tieOuter),loadedRadius:o.loadedRadius,patchShift:o.patchShift&&X$(o.patchShift,e.metrics.toe/VT,Math.atan2(d[0],d[1]))});return{caster:p.caster,kpi:p.kpi,scrubRadius:p.scrubRadius,mechanicalTrail:p.mechanicalTrail,scrubAtWheel:p.scrubAtWheel,trailAtWheel:p.trailAtWheel,kingpinOffset:p.kingpinOffset,casterOffset:p.casterOffset,kingpinGround:l(p.kingpinGround),contactPatch:l(p.contactPatch),elbow:l([p.contactPatch[0],p.kingpinGround[1],p.kingpinGround[2]]),kingpinAtHub:l(p.kingpinAtHub)}}function X$(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 tf(e,t){let r=BT(t);if(r===Yx)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 Kr(e,t,r){let n=tf({heave:0,pitch:0,roll:0,steer:0},r);return e-rb(n,[t,0,0],fo(r.vehicle.config))}var q$=180/Math.PI;function jx(e,t){return!e.valid||!e.ic?!1:Math.hypot(e.ic[0]-e.cp[0],e.ic[1]-e.cp[1])<=t}function Tt(e,t,r){let n=ze(t,e.vehicle.config),o=Qt(e,r),a=kd(e,t,o[t]),s=a.at("uprightUpper"),i=a.at("uprightLower"),c=a.at("contactPatch"),l=a.at("wheelCenter"),u=C=>{let P=a.velocity(C);return[P[0],P[2]]},d=u(c),p=u(l),m=[c[0],c[2]],f=[l[0],l[2]];if(!a.solved)return{ic:null,line:null,cp:m,wc:f,road:[1,0],swingArmAngleDeg:NaN,tanTheta:NaN,tanThetaHub:NaN,valid:!1,unsolved:!0,sinAngle:0};let h=ru(e,{FL:o.FL.ground,FR:o.FR.ground,RL:o.RL.ground,RR:o.RR.ground}),b=Math.hypot(h[0],h[2]),g=[h[0]/b,h[2]/b],y=[g[1],-g[0]],x=C=>{let P=C[0]*g[0]+C[1]*g[1];return Math.abs(P)>1e-9?-(C[0]*y[0]+C[1]*y[1])/P:0},v=a.omega[1],k=Math.hypot(d[0],d[1]),R=Math.abs(v)*1e9>k?[m[0]+d[1]/v,m[1]-d[0]/v]:null,S=R?(C=>{let P=[s[0]-C[0],s[2]-C[1]],L=[i[0]-C[0],i[2]-C[1]];return Math.abs(P[0]*L[1]-P[1]*L[0])/(Math.hypot(...P)*Math.hypot(...L))})(R):0;if(!(Math.abs(d[0]*g[0]+d[1]*g[1])>1e-9))return{ic:R,line:null,cp:m,wc:f,road:y,swingArmAngleDeg:0,tanTheta:0,tanThetaHub:0,valid:!1,sinAngle:S};let w=[d[1]/k,-d[0]/k],F=R?[R[0]-m[0],R[1]-m[1]]:[n.isFront?-1:1,0],T=w[0]*F[0]+w[1]*F[1]<0?[-w[0],-w[1]]:w,A=x(d);return{ic:R,line:T,cp:m,wc:f,road:y,swingArmAngleDeg:Math.atan(A)*q$,tanTheta:A,tanThetaHub:x(p),valid:!0,sinAngle:S}}function GT(e,t,r,n){let o=r/Math.max(1e-6,n.cgHeight),a=t==="front",s=a?n.drive.front:1-n.drive.front,i=a?n.brakeBalanceFront:1-n.brakeBalanceFront,c=(a?n.drive.inboard.front:n.drive.inboard.rear)?e.tanThetaHub:e.tanTheta,l=(a?n.brakeInboard?.front:n.brakeInboard?.rear)?e.tanThetaHub:e.tanTheta,u=a?-1:1;return{brake:u*100*l*o*i,drive:u*100*c*o*s}}function rf(e){let t=Math.min(1,Math.max(0,e.frontMassFrac)),r=(1-t)*e.wheelbase,n=t*e.wheelbase;return{x:e.frontAxleX-r,z:e.cgHeight,lf:r,lr:n}}function KT(e,t,r,n,o){let a=o(e.front)&&o(e.rear),s=n>1e-9?(r-t.x)/n:0,i=e.front.height+s*(e.rear.height-e.front.height),c=e.front.lateral+s*(e.rear.lateral-e.front.lateral);return{axisHeightAtCg:i,axisLateralAtCg:c,arm:t.z-i,valid:a}}function HT(e,t,r){return r>1e-9?Math.atan2(t-e,r)*180/Math.PI:Number.NaN}function zT(e,t,r){let{left:n,right:o}=e,a=(n.height+o.height)/2,s=(n.x+o.x)/2;return{axisHeight:a,axisX:s,heightAboveGround:(n.heightAboveGround+o.heightAboveGround)/2,ahead:s-t.x,arm:t.z-a,sinAngle:Math.min(n.sinAngle,o.sinAngle),valid:r(n)&&r(o)}}function Ux(e,t){return e.valid?L0([e.x,e.height],e.front.cp,e.rear.cp,e.sinAngle,t):!1}function to(e,t){let r={x:0,height:0,heightAboveGround:0,stationAlongGround:0,valid:!1,sinAngle:0,front:e,rear:t};if(!e.valid||!t.valid||!e.line||!t.line)return r;let n=e.ic?[e.ic[0]-e.cp[0],e.ic[1]-e.cp[1]]:e.line,o=t.ic?[t.ic[0]-t.cp[0],t.ic[1]-t.cp[1]]:t.line,a=Math.hypot(n[0],n[1]),s=Math.hypot(o[0],o[1]),i=a>0&&s>0?Math.abs(n[0]*o[1]-n[1]*o[0])/(a*s):0,c=Md(e.cp,n,t.cp,o);if(!c)return{...r,sinAngle:i};let l=e.cp[0]-t.cp[0],u=e.cp[1]-t.cp[1],d=Math.hypot(l,u)||1,p=l/d,m=u/d,f=(e.cp[0]+t.cp[0])/2,h=(e.cp[1]+t.cp[1])/2;return{x:c[0],height:c[1],heightAboveGround:(c[0]-t.cp[0])*-m+(c[1]-t.cp[1])*p,stationAlongGround:(c[0]-f)*p+(c[1]-h)*m,valid:!0,sinAngle:i,front:e,rear:t}}var Z$=180/Math.PI,J$=Math.PI/180,Xx=.5,nf=2,qx=.25;function XT(e,t,r,n,o){let a=t.frontMassFrac;if(a===void 0||!Number.isFinite(a))return;let s=e.vehicle.config,i=s.wheelbase,c=rf({wheelbase:i,frontAxleX:s.frontAxleX,frontMassFrac:a,cgHeight:t.cgHeight}),l=i>1e-9?(s.frontAxleX-c.x)/i:0,u=(m,f)=>m+l*(f-m),d={left:to(...o.left),right:to(...o.right)},p={...c,z:Kr(t.cgHeight,c.x,e)};return{roll:{height:u(r.rollCentreHeight,n.rollCentreHeight),arm:t.cgHeight-u(r.rollCentreHeightChassis,n.rollCentreHeightChassis),slope:HT(r.rollCentreHeight,n.rollCentreHeight,i),usable:r.rollCentreHeightUsable&&n.rollCentreHeightUsable},pitch:zT(d,p,m=>Ux(m,i))}}var eG=e=>e.frontMassFrac!==void 0&&Number.isFinite(e.frontMassFrac);function tG(e,t,r){return{FL:Tt(e,"FL",t),FR:Tt(e,"FR",t),RL:Tt(e,"RL",r),RR:Tt(e,"RR",r)}}var rG={heave:0,pitch:0,roll:0,steer:0},nG={FL:"FR",FR:"FL",RL:"RR",RR:"RL"},of=e=>e.ok?e.state:{...e.nearest,converged:!1};function Qx(e,t,r){return t.state?t.solved===!1?{...t.state,converged:!1}:t.state:of(Ae(e,t.travel,t.steer,void 0,r))}var YT=new WeakMap;function WT(e,t){let r=e.ctx[t],n=qe(e.vehicle,t).config.loadedRadius,o=vr(n,e.kc,t),a=YT.get(r);a||(a=new Map,YT.set(r,a));let s=a.get(o);if(!s){let i=ho(t,e.vehicle.config,rG,e.vehicle);s=of(Ae(r,i.travel,i.steer,void 0,o===n?void 0:{loadedRadius:o})),a.set(o,s)}return s}var yn=(e,t)=>!e||!e.lo.converged||!e.hi.converged?NaN:(t(e.hi)-t(e.lo))/(2*e.step),jT=(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 qT(e,t,r,n,o,a){let s=e.vehicle.config,i=fs(r),c=qe(e.vehicle,r),l=ze(r,s),u=e.ctx[r],d=Qt(e,t),p=d[r],m={travel:p.travel,steer:p.steer},f=p.rigid?void 0:{loadedRadius:p.loadedRadius},h=Qx(u,p,f),b=WT(e,r),g={lo:of(Ae(u,m.travel-Xx,m.steer,void 0,f)),hi:of(Ae(u,m.travel+Xx,m.steer,void 0,f)),step:Xx},y=l.isFront?{lo:tt(u,h.beta,m.steer-nf,void 0,f),hi:tt(u,h.beta,m.steer+nf,void 0,f),step:nf}:null,x=Y=>{let K=Qt(e,{...t,roll:t.roll+Y*J$})[r];return Qx(u,K,K.rigid?void 0:{loadedRadius:K.loadedRadius})},v={lo:x(-qx),hi:x(qx),step:qx},k=aG(e,t,r,l.isFront,d,y),R=rt(h.points.contactPatch,l),M=rt(b.points.contactPatch,l),S=Math.abs(R[1])-Math.abs(M[1]),w=nG[r],F=d[w],T=Qx(e.ctx[w],F,F.rigid?void 0:{loadedRadius:F.loadedRadius}),A=T.converged?S+Math.abs(T.points.contactPatch[1])-Math.abs(WT(e,w).points.contactPatch[1]):NaN,C=T.converged?Math.abs(R[1])+Math.abs(T.points.contactPatch[1]):NaN,P=o??$r(e,t,i),L=Sd(P,qt(c)),E=L?null:qA(P),_=Us(P),D=l.sideSign>0?P.icRight:P.icLeft,I=D?Math.hypot(D[0]-R[1],D[1]-R[2]):1/0,V=a??Tt(e,r,t),O=V.ic?Math.hypot(V.ic[0]-V.cp[0],V.ic[1]-V.cp[1]):1/0,B=GT(V,i,s.wheelbase,n),z=-yn(g,Y=>Y.points.damperLength),j=c.config.springRate,$=yn(v,Y=>Y.metrics.camber),N=ru(e,{FL:d.FL.ground,FR:d.FR.ground,RL:d.RL.ground,RR:d.RR.ground}),W=e.kc?.loadCase,Z=Y=>W?ef(Y,r,s,N,{loadedRadius:p.loadedRadius,patchShift:W.patchShift[r]}):Y.metrics,q=Z(h);return{id:r,converged:h.converged,travel:h.travel,camber:h.metrics.camber,camberRoad:Wx(h.points.spinAxis,r,s,N),toe:h.metrics.toe,caster:q.caster,kpi:q.kpi,scrubRadius:q.scrubRadius,mechanicalTrail:q.mechanicalTrail,scrubAtWheel:q.scrubAtWheel,trailAtWheel:q.trailAtWheel,kingpinOffset:q.kingpinOffset,casterOffset:q.casterOffset,steeringArm:h.metrics.steeringArm,camberGain:yn(g,Y=>Y.metrics.camber),bumpSteer:yn(g,Y=>Y.metrics.toe),trackScrubRate:yn(g,Y=>Math.abs(rt(Y.points.contactPatch,l)[1])),casterGain:yn(g,Y=>Z(Y).caster),kpiGain:yn(g,Y=>Z(Y).kpi),scrubGain:yn(g,Y=>Z(Y).scrubRadius),trailGain:yn(g,Y=>Z(Y).mechanicalTrail),...l.isFront?{camberPerSteer:jT(y,Y=>Y.metrics.camber,Y=>Y.metrics.toe),steerJacking:-jT(y,Y=>Y.points.contactPatch[2],Y=>Y.metrics.toe),...k!==void 0?{steerLoad:k}:{}}:{},rollCamber:$,camberRecovery:-100*l.sideSign*$,rollSteer:l.sideSign*yn(v,Y=>Y.metrics.toe),halfTrackChange:S,trackChange:A,track:C,patchX:R[0],longitudinal:R[0]-M[0],rollCentreHeight:E?E.heightAboveGround:P.heightAboveGround,rollCentreHeightChassis:(E?E.height:P.height)-Kr(0,l.axleX,e),rollCentreLateral:P.lateralAlongGround,rollCentreValid:P.valid,rollCentreUsable:L,rollCentreHeightUsable:L||E!==null,transferHeight:_?_.heightAboveGround:NaN,transferHeightChassis:_?_.height-Kr(0,l.axleX,e):NaN,rollCentreSinAngle:P.sinAngle,fvsaLength:I,svsaLength:O,swingArmAngle:V.swingArmAngleDeg,svsaUsable:jx(V,s.wheelbase),svsaSinAngle:V.sinAngle,...i==="front"?{antiDive:B.brake,antiLift:B.drive}:{antiSquat:B.drive,antiLift:B.brake},decoupled:c.config.actuation==="decoupled",mcpherson:c.config.layout==="mcpherson",springRate:j,motionRatio:z,wheelRate:j*z*z,damperLength:h.points.damperLength,damperTravel:b.points.damperLength-h.points.damperLength,...oG(c,b.points.damperLength,h.points.damperLength,e.kc?.curve[r].spring?.law),rockerAngle:c.config.actuation==="direct"?0:(h.points.rockerAngle-b.points.rockerAngle)*Z$,groundDisplacement:p.rigid?h.travel:p.ground,tyreDeflection:p.tyreDeflection,wheelLoad:p.load,loadedRadiusAt:p.loadedRadius,rideRate:p.rideRate,wheelRateAtLoad:p.wheelRateAtLoad,lifted:p.lifted,clearance:p.clearance??0,tyreRigid:p.rigid}}function oG(e,t,r,n){if(e.config.actuation==="decoupled")return{};let o=n?{droop:n.droopStated?n.droop:null,bump:n.bump}:bs(t,e.config.coilover),a=t-r;return{...o.droop!==null?{damperToExtended:a-o.droop}:{},...o.bump!==null?{damperToClosed:o.bump-a}:{}}}function aG(e,t,r,n,o,a){if(!a||!n)return;let s=am(e,t,"front"),i=e.kc;if(!s||!i)return;let c=["FL","FR"],l=[0,0],u=[0,0],d={lo:[],hi:[]},p=0;for(let h=0;h<2;h++){let b=c[h],g=o[b],y=e.ctx[b],x=g.rigid?void 0:{loadedRadius:g.loadedRadius},R=(b==="FR"?1:-1)*(r==="FR"?1:-1)*nf,M=g.state?{q:[...g.state.pose.t,...g.state.pose.omega],phi:g.state.points.rockerAngle}:void 0,S=Ht(Ae(y,g.travel,g.steer-R,M,x)),w=Ht(Ae(y,g.travel,g.steer+R,M,x));if(!S||!w)return NaN;l[h]=w.points.contactPatch[2]-S.points.contactPatch[2],u[h]=Pn(i.curve[b],g.travel,w.points.damperLength)-Pn(i.curve[b],g.travel,S.points.damperLength),d.lo.push(S),d.hi.push(w),b===r&&(p=w.metrics.toe-S.metrics.toe)}let m=i.elements?.front;if(m){let h=[o.FL.travel,o.FR.travel],b=ac(m,h,[d.hi[0],d.hi[1]]),g=ac(m,h,[d.lo[0],d.lo[1]]);u[0]+=b[0]-g[0],u[1]+=b[1]-g[1]}return Math.abs(p)>1e-9?s([0,0],l,u)[r==="FL"?0:1]/p:NaN}function nu(e,t,r,n,o,a){return qT(e,t,r==="front"?"FL":"RL",n,o,a)}function Zx(e,t,r){let n=Math.min(Math.abs(e),Math.abs(t));return r>0?Math.atan2(n,r/2)*180/Math.PI:0}function Jx(e,t,r,n){let o=eG(r)?tG(e,t,t):null,a=nu(e,t,"front",r,n?.front,o?.FL),s=nu(e,t,"rear",r,n?.rear,o?.RL),i=o?XT(e,r,a,s,{left:[o.FL,o.RL],right:[o.FR,o.RR]}):void 0;return{front:a,rear:s,wheelbaseChange:a.longitudinal-s.longitudinal,wheelbase:a.patchX-s.patchX,...i?{axes:i}:{}}}function af(e,t,r){let n=e.config.actuation==="decoupled";return{decoupled:n,heave:n&&t?.design.kind==="coil"&&t.linkage&&Ko(t.linkage).kind!=="chassis"?t:void 0,roll:n&&r?.design.kind==="coil"&&r.linkage&&en(e,r.linkage,"coil")?r:void 0}}var QT=16,sG=50,iG=10,cG=4,lG=["upperArm","lowerArm","tieRod","rod","dropLink"],ZT=["ballJoint","rodEnd"],rr=e=>typeof e=="number"&&Number.isFinite(e)&&e>0;function tR(e,t){let r=e?.rim;if(r&&rr(r.diameter)&&rr(r.width)&&Number.isFinite(r.offset)&&Number.isFinite(r.wall)&&r.wall>=0)return{...r,from:"typed"};let n=HM(t);return n?{...n,offset:null,wall:cG,from:"tyre"}:null}function eR(e,t){let r=e?.body;if(!r||!rr(r.bodyDiameter))return null;let n=rr(r.shaftDiameter)?r.shaftDiameter:r.bodyDiameter,o=rr(r.stroke)?Math.max(0,r.extended-r.stroke-t):1/0;return{bodyRadius:r.bodyDiameter/2,shaftRadius:n/2,bodyLength:o}}function uG(e){return e&&e.location==="outboard"&&e.packaging?{...e.packaging,effRadius:e.effRadiusMm}:null}function mG(e){if(!e?.linkage||e.design.kind==="none")return null;let t=e.design,r=Math.max(0,F0(t)??0),n=t.kind==="ubar"||t.kind==="blade"||t.kind==="torsionTube"?t.section.od/2:0,o=t.kind==="ubar"?(t.armSection?.od??t.section.od)/2:t.kind==="blade"?Math.max(t.blade.width,t.blade.thickness)/2:n;return{axle:e,armLength:r,barRadius:n,armRadius:o}}function dG(e,t){if(!rr(t)||!e.config||!e.front)return null;let r=e,n=qe(r,"FL"),o=qe(r,"FR");if(n.config.steerMode!=="rack"||o.config.steerMode!=="rack")return null;let a=rt(n.hardpoints.tieInner,ze("FL",r.config)),s=rt(o.hardpoints.tieInner,ze("FR",r.config)),i=Math.hypot(s[0]-a[0],s[1]-a[1],s[2]-a[2]),c=It(n.config);if(!(i>2*c))return null;let l=c/i,u=(d,p)=>[d[0]+(p[0]-d[0])*l,d[1]+(p[1]-d[1])*l,d[2]+(p[2]-d[2])*l];return{a:u(a,s),b:u(s,a),radius:t/2}}function pG(e,t,r){if(!r||!e.config||!r.inboard.every(Number.isFinite)||!rr(r.diameter)||!rr(r.jointDiameter)||!Number.isFinite(r.outboard))return null;let[n,o]=t==="front"?["FL","FR"]:["RL","RR"];return{inboard:{left:rt(r.inboard,ze(n,e.config)),right:rt(r.inboard,ze(o,e.config))},outboard:r.outboard,radius:r.diameter/2,reach:r.jointDiameter/2,limits:{...rr(r.innerAngle)?{innerAngle:r.innerAngle}:{},...rr(r.outerAngle)?{outerAngle:r.outerAngle}:{},...rr(r.plunge)?{plunge:r.plunge}:{}}}}var rR=e=>typeof e=="number"&&Number.isFinite(e)&&e>0&&e<90;function JT(e,t,r){let n=Object.fromEntries(lG.map(i=>[i,(rr(e?.tubes?.[i])?e.tubes[i]:QT)/2])),o=Object.fromEntries(ZT.map(i=>[i,(rr(e?.housings?.[i])?e.housings[i]:sG)/2])),a=eR(t.damper,o.rodEnd),s=Object.fromEntries(ZT.filter(i=>rR(e?.jointLimits?.[i])).map(i=>[i,e.jointLimits[i]]));return{tube:n,strut:a?a.bodyRadius:QT/2,housing:o,...Object.keys(s).length?{jointLimit:s}:{},uprightWall:typeof e?.uprightWall=="number"&&Number.isFinite(e.uprightWall)&&e.uprightWall>=0?e.uprightWall:iG,rim:tR(e,t.tyre),...rr(e?.tyreGrowth)?{tyreGrowth:e.tyreGrowth}:{},brake:uG(t.brake),damper:a,...fG(t,o.rodEnd,r)}}function fG(e,t,r){let n=!!e.heave?.linkage&&e.heave.design.kind!=="none",o=!!e.arb?.linkage&&e.arb.design.kind==="coil"&&(!r||!!af(r,void 0,e.arb).roll),a=n?eR(e.heaveDamper,t):null,s=o?eR(e.rollDamper,t):null,i=[...n&&!a?["heave"]:[],...o&&!s?["roll"]:[]];return{arb:mG(e.arb),heave:a&&e.heave?{kind:"heave",axle:e.heave,damper:a}:null,roll:s&&e.arb?{kind:"roll",axle:e.arb,damper:s}:null,...i.length?{unsized:i}:{}}}function eP(e){let t=(r,n)=>r?n?"shafts":"hubs":"undriven";return{front:t(e.front>0,e.inboard.front),rear:t(e.front<1,e.inboard.rear)}}function hG(e,t={}){let r={heaveDamper:t.unitDampers?.heave??t.dampers?.front,rollDamper:t.unitDampers?.roll??t.dampers?.front},n=JT(e.parts?.front,{tyre:t.tyres?.front,brake:t.brakes?.front,damper:t.dampers?.front,arb:t.arbs?.front,heave:t.heaves?.front,...r},e.front),o=JT(e.parts?.rear,{tyre:t.tyres?.rear??t.tyres?.front,brake:t.brakes?.rear,damper:t.dampers?.rear??t.dampers?.front,arb:t.arbs?.rear,heave:t.heaves?.rear,...r},e.rear),a=(s,i)=>{let c=e.parts?.[s]?.driveshaft,l=t.drive?.[s]??"shafts",u=c&&l==="shafts"?pG(e,s,c):null;return{...i,driveshaft:u,shaftIdle:c&&l!=="shafts"?l:null}};return{front:{...a("front",n),rackHousing:dG(e,e.parts?.front?.rackHousing)},rear:a("rear",o)}}function tP(e,t,r={}){return{...e,axles:hG(t,r)}}var Na=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],ro=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],ou=(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]],Hr=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]},aP=180/Math.PI,bG=[[1,0,0],[0,1,0],[0,0,1]],rP=(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]],gG=(e,t)=>[ro(e[0],t),ro(e[1],t),ro(e[2],t)];function nP(e,t,r){let n=Hr(Na(t,e)),o=Hr(ou(n,Na(r,e)));return[n,ou(o,n),o]}function yG(e,t){let r=n=>[t[0][0]*e[0][n]+t[1][0]*e[1][n]+t[2][0]*e[2][n],t[0][1]*e[0][n]+t[1][1]*e[1][n]+t[2][1]*e[2][n],t[0][2]*e[0][n]+t[1][2]*e[1][n]+t[2][2]*e[2][n]];return[r(0),r(1),r(2)]}function nR(e,t,r,n){let o=Hr(Na(t,e)),a=b=>{let g=Na(b,e),y=ro(g,o);return[g[0]-y*o[0],g[1]-y*o[1],g[2]-y*o[2]]},s=Hr(a(r)),i=Hr(a(n)),c=ro(ou(s,i),o),u=ro(s,i),d=c,p=1-u,[m,f,h]=o;return[[p*m*m+u,p*m*f+d*h,p*m*h-d*f],[p*m*f-d*h,p*f*f+u,p*f*h+d*m],[p*m*h+d*f,p*f*h-d*m,p*h*h+u]]}var xG=(e,t)=>Math.acos(Math.max(-1,Math.min(1,ro(Hr(e),Hr(t)))))*aP;function RG(e,t){return{upright:yG(nP(e.uprightLower,e.tieOuter,e.wheelCenter),nP(t.uprightLower,t.tieOuter,t.wheelCenter)),uca:t.mcpherson?null:nR(t.ucaFront,t.ucaRear,e.uprightUpper,t.uprightUpper),lca:nR(t.lcaFront,t.lcaRear,e.uprightLower,t.uprightLower),rocker:t.direct?null:nR(t.rockerPivotA,t.rockerPivotB,e.rockerToPushrod,t.rockerToPushrod)}}function vG(e){let t=Hr(e[0]),r=Math.abs(t[0])<.9?[1,0,0]:[0,1,0],n=Hr(ou(t,r)),o=ou(t,n),a=e.map(h=>{let b=Hr(h);return[ro(b,n),ro(b,o)]}),s=h=>{let b=Math.cos(h),g=Math.sin(h),y=0,x=0;for(let v=0;v<a.length;v++){let k=Math.abs(a[v][0]*b+a[v][1]*g);k>y&&([y,x]=[k,v])}return{v:y,at:x}},i=Math.PI/180,c=0,l=1/0;for(let h=0;h<180;h++){let b=s(h*i).v;b<l&&([c,l]=[h*i,b])}let u=c-i,d=c+i,p=(Math.sqrt(5)-1)/2;for(let h=0;h<30;h++){let b=d-p*(d-u),g=u+p*(d-u);s(b).v<s(g).v?d=g:u=b}let m=s((u+d)/2),f=m.v<l?m:s(c);return{angle:Math.asin(Math.min(1,Math.min(l,m.v)))*aP,at:f.at}}function oP(e){let t=null;for(let r of e)Number.isFinite(r.angle)&&(!t||r.angle>t.angle)&&(t={angle:r.angle,joint:r.joint});return t}var kG={upright:"upright",lowerArm:"lca",upperArm:"uca"};function MG(e,t,r,n){let o=t.map(u=>RG(e,u)),a=Hr(Na(e.uprightUpper,e.uprightLower)),s=(u,d,p)=>{let m=0,f=-1;for(let h=0;h<o.length;h++){let b=o[h],g=b[u]?xG(rP(b.upright,a),rP(b[u],a)):0;g>m&&([m,f]=[g,h])}return{joint:d,group:"ballJoint",angle:m,at:f,ends:p}},i=[s("lca","lower ball joint",["uprightLower","uprightUpper"])];e.mcpherson||i.push(s("uca","upper ball joint",["uprightUpper","uprightLower"]));let c=(u,d,p)=>{let m=[Na(e[d],e[u])];for(let f=0;f<t.length;f++){let h=p(o[f]);if(!h)return null;m.push(gG(h,Na(t[f][d],t[f][u])))}return m},l=[["tie rod, inner end",c("tieInner","tieOuter",()=>bG),["tieInner","tieOuter"]],["tie rod, outer end",c("tieInner","tieOuter",u=>u.upright),["tieOuter","tieInner"]]];e.direct||l.push([`${n}, rocker end`,c("rockerToPushrod","pushrodOuter",u=>u.rocker),["rockerToPushrod","pushrodOuter"]],[`${n}, outer end`,c("rockerToPushrod","pushrodOuter",u=>u[kG[r]]),["pushrodOuter","rockerToPushrod"]]);for(let[u,d,p]of l){if(!d)continue;let m=vG(d);i.push({joint:u,group:"rodEnd",angle:m.angle,at:m.angle>0?m.at-1:-1,ends:p})}return i}function sf(e,t,r,n){let o=MG(e,t,r,n);return{ballJoint:oP(o.filter(a=>a.group==="ballJoint")),rodEnd:oP(o.filter(a=>a.group==="rodEnd"))}}function cf(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),Kr(Math.min(n.zMin,n.zMax),i,t)],max:[s,Math.max(n.yMin,n.yMax),Kr(Math.max(n.zMin,n.zMax),i,t)]}})}var Oa=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Sr=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],Pt=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],Ar=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],au=e=>Math.sqrt(Ar(e,e));function oR(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 aR(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=>Ar(r,e)>=Ar(r,t)?e:t,samples:()=>Array.from({length:41},(r,n)=>Sr(e,Pt(Oa(t,e),n/40)))}}function Va(e){let t=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0];for(let n of e)for(let o=0;o<3;o++)t[o]=Math.min(t[o],n[o]),r[o]=Math.max(r[o],n[o]);return{min:t,max:r,support:n=>{let o=e[0],a=-1/0;for(let s of e){let i=Ar(n,s);i>a&&(a=i,o=s)}return o}}}function yi(e,t,r,n){let o=Pt(t,1/(au(t)||1)),a=n/2,s=o.map(i=>r*Math.sqrt(Math.max(0,1-i*i))+a*Math.abs(i));return{min:Oa(e,s),max:Sr(e,s),support:i=>{let c=Ar(i,o),l=Oa(i,Pt(o,c)),u=au(l),d=u>1e-12?Pt(l,r/u):[0,0,0];return Sr(Sr(e,Pt(o,c>=0?a:-a)),d)},samples:()=>{let i=Math.abs(o[0])<.9?[1,0,0]:[0,1,0],c=Oa(i,Pt(o,Ar(i,o))),l=Pt(c,1/au(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]],d=[];for(let p of[-1,-.5,0,.5,1]){let m=Sr(e,Pt(o,p*a));d.push(m);let f=Math.abs(p)===1?[.5,1]:[1];for(let h of f)for(let b=0;b<72;b++){let g=b/72*2*Math.PI;d.push(Sr(m,Sr(Pt(l,h*r*Math.cos(g)),Pt(u,h*r*Math.sin(g)))))}}return d}}}function SG(e){let t=e[0],r=e.slice(1).map(c=>Oa(c,t)),n=r.length;if(n===0)return{v:t,w:[1]};let o=r.map(c=>r.map(l=>Ar(c,l))),a=r.map(c=>-Ar(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 d=o[u][c]/o[c][c];for(let p=c;p<n;p++)o[u][p]-=d*o[c][p];a[u]-=d*a[c]}}let s=a.map((c,l)=>c/o[l][l]),i=t;for(let c=0;c<n;c++)i=Sr(i,Pt(r[c],s[c]));return{v:i,w:[1-s.reduce((c,l)=>c+l,0),...s]}}function AG(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=SG(a.map(c=>c.w));if(!s||s.w.some(c=>c<-1e-9))continue;let i=Ar(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 xi(e,t,r=1e-9){let n=i=>{let c=e.support(i),l=t.support(Pt(i,-1));return{w:Oa(c,l),a:c,b:l}},o=(i,c)=>{let l=[0,0,0],u=[0,0,0];return i.keep.forEach((d,p)=>{l=Sr(l,Pt(d.a,i.weights[p])),u=Sr(u,Pt(d.b,i.weights[p]))}),{distance:c,onA:l,onB:u}},a=n([1,0,0]),s={v:a.w,keep:[a],weights:[1]};for(let i=0;i<64;i++){let c=s.v,l=Ar(c,c);if(l<1e-12)return o(s,0);let u=n(Pt(c,-1));if(l-Ar(c,u.w)<=r*Math.max(1,l))return o(s,Math.sqrt(l));let d=AG([...s.keep,u]);if(d.keep.length===4)return o(d,0);if(Ar(d.v,d.v)>=l-1e-12)return o(s,Math.sqrt(l));s=d}return o(s,au(s.v))}function wG(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 lf(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 cP={linkRadius:8,mountAllowance:15},CG=(e,t,r)=>e.z0+e.dzdx*t+e.dzdy*r;function FG(e,t){let r=Math.sin(e.pitch);return{z0:-e.heave+t*r,dzdx:-r,dzdy:Math.sin(e.roll)}}function lP(e){return FG(tf({heave:0,pitch:0,roll:0,steer:0},e),fo(e.vehicle.config))}var TG=[{name:"upper wishbone, front leg",inboard:"ucaFront",outboard:"uprightUpper",body:"upperArm",ends:["chassis","upright"]},{name:"upper wishbone, rear leg",inboard:"ucaRear",outboard:"uprightUpper",body:"upperArm",ends:["chassis","upright"]},{name:"lower wishbone, front leg",inboard:"lcaFront",outboard:"uprightLower",body:"lowerArm",ends:["chassis","upright"]},{name:"lower wishbone, rear leg",inboard:"lcaRear",outboard:"uprightLower",body:"lowerArm",ends:["chassis","upright"]},{name:"tie rod",inboard:"tieInner",outboard:"tieOuter",body:"tieRod",ends:["chassis","upright"]},{name:"pushrod",inboard:"rockerToPushrod",outboard:"pushrodOuter",body:"rod",ends:["rocker","rodAttach"]},{name:"strut",inboard:"damperChassis",outboard:"pushrodOuter",body:"strut",ends:["chassis","upright"]}];function sR(e){return TG.filter(t=>t.name==="strut"?e.mcpherson:t.name==="pushrod"?!e.direct:!(e.mcpherson&&t.name.startsWith("upper")))}var uP=(e,t,r)=>e.every((n,o)=>n>=t.min[o]-r&&n<=t.max[o]+r);function sP(e,t,r){let n=Oa(t,e),o=au(n);return o>1e-9?Sr(e,Pt(n,r/o)):e}function iR(e,t,r){let n=xi(e,t),o=n.distance>0?null:wG(e,t),a=n.distance>0?n.distance-r:-((o?.depth??0)+r),s=n.distance>0?{part:sP(n.onB,n.onA,r),box:n.onA}:o?{part:sP(o.point,o.face,-r),box:o.face}:{part:n.onB,box:n.onA};return{distance:a,gap:s}}function iP(e,t){let r=null;for(let{shape:n,pad:o,part:a,pose:s}of t){if(r){let c=lf(e,n);if(c>0&&c-o>=r.distance)continue}let i=iR(e,n,o);Number.isFinite(i.distance)&&(!r||i.distance<r.distance)&&(r={distance:i.distance,part:a,corner:s.corner,travel:s.travel,rack:s.rack,gap:i.gap})}return r}function PG(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:Pt(a.reduce((c,l)=>Sr(c,l),[0,0,0]),1/a.length)}}function mP(e,t){return{...PG(e,r=>r[2]-CG(t,r[0],r[1])),road:t}}function dP(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 LG(e,t){let r=e.map(o=>({pose:o,part:`${o.corner} tyre`,pad:0,shape:yi(o.g.wheelCenter,o.g.spinAxis,o.corner[0]==="F"?t.tyreRadius.front:t.tyreRadius.rear,t.tyreWidth)})),n=e.flatMap(o=>sR(o.g).map(a=>{let s=o.g[a.inboard],i=o.g[a.outboard];return{pose:o,part:`${o.corner} ${a.name}`,pad:t.linkRadius,inboard:s,shape:aR(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 DG(e,t,r){let n=oR(e.min,e.max),o=t.links.filter(a=>!uP(a.inboard,e,r.mountAllowance+r.linkRadius));return{tyre:iP(n,t.tyres),link:iP(n,o)}}function pP(e,t,r){let n=LG(t,r);return e.map(o=>({boxId:o.id,...DG(o,n,r)}))}var EG={r:[1,0,0,0,1,0,0,0,1],t:[0,0,0]},hP={r:[1,0,0,0,-1,0,0,0,1],t:[0,0,0]},Vt=(e,t)=>[e.r[0]*t[0]+e.r[1]*t[1]+e.r[2]*t[2]+e.t[0],e.r[3]*t[0]+e.r[4]*t[1]+e.r[5]*t[2]+e.t[1],e.r[6]*t[0]+e.r[7]*t[1]+e.r[8]*t[2]+e.t[2]],uf=(e,t)=>[e.r[0]*t[0]+e.r[1]*t[1]+e.r[2]*t[2],e.r[3]*t[0]+e.r[4]*t[1]+e.r[5]*t[2],e.r[6]*t[0]+e.r[7]*t[1]+e.r[8]*t[2]];function bP(e){let t=[e.r[0],e.r[3],e.r[6],e.r[1],e.r[4],e.r[7],e.r[2],e.r[5],e.r[8]],r=uf({r:t,t:[0,0,0]},e.t);return{r:t,t:[-r[0],-r[1],-r[2]]}}function su(e,t){let r=[];for(let n=0;n<3;n++)for(let o=0;o<3;o++)r.push(e.r[3*n]*t.r[o]+e.r[3*n+1]*t.r[3+o]+e.r[3*n+2]*t.r[6+o]);return{r,t:Vt(e,t.t)}}function cR(e){let t=ds(e,[1,0,0]),r=ds(e,[0,1,0]),n=ds(e,[0,0,1]);return[t[0],r[0],n[0],t[1],r[1],n[1],t[2],r[2],n[2]]}function IG(e){let r=e.map(a=>[...a]),n=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];for(let a=0;a<60;a++){let s=0;for(let i=0;i<4;i++)for(let c=i+1;c<4;c++)s+=r[i][c]*r[i][c];if(s<1e-30)break;for(let i=0;i<4;i++)for(let c=i+1;c<4;c++){if(Math.abs(r[i][c])<1e-300)continue;let l=(r[c][c]-r[i][i])/(2*r[i][c]),u=Math.sign(l||1)/(Math.abs(l)+Math.sqrt(l*l+1)),d=1/Math.sqrt(u*u+1),p=u*d;for(let m=0;m<4;m++){let f=r[m][i],h=r[m][c];r[m][i]=d*f-p*h,r[m][c]=p*f+d*h}for(let m=0;m<4;m++){let f=r[i][m],h=r[c][m];r[i][m]=d*f-p*h,r[c][m]=p*f+d*h}for(let m=0;m<4;m++){let f=n[m][i],h=n[m][c];n[m][i]=d*f-p*h,n[m][c]=p*f+d*h}}}let o=0;for(let a=1;a<4;a++)r[a][a]>r[o][o]&&(o=a);return[n[0][o],n[1][o],n[2][o],n[3][o]]}var fP=e=>{let t=[0,0,0];for(let r of e)for(let n=0;n<3;n++)t[n]+=r[n]/e.length;return t};function gP(e,t){let r=Math.min(e.length,t.length);if(r===0)return{iso:EG,residuals:[]};let n=fP(e.slice(0,r)),o=fP(t.slice(0,r)),a=[0,0,0,0,0,0,0,0,0];for(let R=0;R<r;R++){let M=[e[R][0]-n[0],e[R][1]-n[1],e[R][2]-n[2]],S=[t[R][0]-o[0],t[R][1]-o[1],t[R][2]-o[2]];for(let w=0;w<3;w++)for(let F=0;F<3;F++)a[3*w+F]+=M[w]*S[F]}let[s,i,c,l,u,d,p,m,f]=a,h=[[s+u+f,d-m,p-c,i-l],[d-m,s-u-f,i+l,p+c],[p-c,i+l,-s+u-f,d+m],[i-l,p+c,d+m,-s-u+f]],b=IG(h),g=Math.hypot(b[0],b[1],b[2],b[3])||1,y=cR([b[0]/g,b[1]/g,b[2]/g,b[3]/g]),x=uf({r:y,t:[0,0,0]},n),v={r:y,t:[o[0]-x[0],o[1]-x[1],o[2]-x[2]]},k=[];for(let R=0;R<r;R++){let M=Vt(v,e[R]);k.push(Math.hypot(M[0]-t[R][0],M[1]-t[R][1],M[2]-t[R][2]))}return{iso:v,residuals:k}}var $pe=Math.PI/180;function yP(e,t,r,n){let o=(Math.sqrt(5)-1)/2,a=t,s=r,i=s-o*(s-a),c=a+o*(s-a),l=e(i),u=e(c);for(;s-a>n;)l<=u?(s=c,c=i,u=l,i=s-o*(s-a),l=e(i)):(a=i,i=c,l=u,c=a+o*(s-a),u=e(c));return l<=u?{x:i,v:l}:{x:c,v:u}}var _G=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],xP=e=>Math.hypot(e[0],e[1],e[2]);var NG=(e,t,r)=>[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r,e[2]+(t[2]-e[2])*r],RP=(...e)=>e.every(t=>t.every(Number.isFinite)),OG={rocker:"rocker",lowerArm:"lowerArm",upright:"upright"};function vP(e,t,r,n,o){if(af(t,void 0,e.axle).roll)return[];let a=YA(e.axle,t,r,e.armLength);if(!RP(a.tip,a.outer,a.root))return[];let s=o.housing.rodEnd,i={kind:"link",corner:n},c=[{...i,id:`${n} drop link`,name:"drop link",body:"dropLink",ends:["arb",OG[e.axle.linkage.attach]],a:a.tip,b:a.outer,radius:o.tube.dropLink,housing:[s,s]}];if(e.armLength>0){c.push({...i,id:`${n} anti-roll bar arm`,name:"anti-roll bar arm",body:"arb",ends:["arb","arb"],a:a.root,b:a.tip,radius:e.armRadius,housing:[0,s]});let l=[a.root[0],-a.root[1],a.root[2]];c.push({...i,id:`${n} anti-roll bar`,name:"anti-roll bar",body:"arb",ends:["chassis","chassis"],a:a.root,b:l,radius:e.barRadius,housing:[0,0],shared:!0})}return c}function kP(e,t){return{kind:"link",id:`${t} rack housing`,name:"rack housing",corner:t,body:"rackHousing",ends:["rack","rack"],a:e.a,b:e.b,radius:e.radius,housing:[0,0],shared:!0,flat:!0}}function VG(e){let t=xP(e.spinAxis)||1,r=[e.spinAxis[0]/t,e.spinAxis[1]/t,e.spinAxis[2]/t],n=e.wheelCenter[1]>=0?1:-1;return r[1]*n<0?[-r[0],-r[1],-r[2]]:r}function BG(e,t){let r=VG(e);return[e.wheelCenter[0]-r[0]*t,e.wheelCenter[1]-r[1]*t,e.wheelCenter[2]-r[2]*t]}var $G=(e,t)=>t[1]==="L"?e.inboard.left:e.inboard.right;function MP(e,t,r){let n=$G(e,r),o=BG(t,e.outboard);return RP(n,o)?{kind:"link",id:`${r} driveshaft`,name:"driveshaft",corner:r,body:"driveshaft",ends:["chassis","upright"],a:n,b:o,radius:e.radius,housing:[e.reach,e.reach]}:null}function SP(e,t,r,n,o,a,s,i){let c=xP(_G(a.p,o.p)),l=Math.min(c,s.bodyLength),u=l>=c,d=c>1e-9?NG(o.p,a.p,l/c):o.p,p={kind:"link",corner:n,body:r},m={...p,id:`${e} body`,name:`${t} body`,ends:[o.body,u?a.body:r],endCorners:[o.corner,u?a.corner:n],a:o.p,b:d,radius:s.bodyRadius,housing:[i,u?i:0],flat:!0};return u?[m]:[m,{...p,id:`${e} shaft`,name:`${t} shaft`,ends:[r,a.body],endCorners:[n,a.corner],a:d,b:a.p,radius:s.shaftRadius,housing:[0,i]}]}var Ri=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],df=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],Po=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],lR=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],pf=e=>Math.sqrt(lR(e,e)),uR=(e,t,r)=>df(e,Po(Ri(t,e),r));function AP(e,t,r){let n=e.diameter/2,o=Math.max(n,t),a=r/2,s=Math.min(a,e.width/2),i=(n+o)/2,c=[];for(let l=0;l<3;l++){let u=s+(a-s)*(l+1)/3;c.push({z0:-u,z1:u,r0:n+(i-n)*l/3,r1:n+(i-n)*(l+1)/3})}return c.push({z0:-a,z1:a,r0:i,r1:o}),c}function wP(e){let t=e.diameter/2,r=GG(e),n=e.width/2,o={z0:-n,z1:n,r0:r,r1:t};if(e.offset===null)return[o];let a=Math.min(n,Math.max(-n,e.offset));return[o,{z0:a,z1:n,r0:0,r1:r}]}var GG=e=>Math.max(0,e.diameter/2-e.wall);function KG(e,t){let r=Ri(e,t.centre),n=lR(r,t.axis),o=Ri(r,Po(t.axis,n)),a=pf(o);if(a>1e-9)return{z:n,r:a,out:Po(o,1/a)};let s=Math.abs(t.axis[0])<.9?[1,0,0]:[0,1,0],i=Ri(s,Po(t.axis,lR(s,t.axis)));return{z:n,r:0,out:Po(i,1/pf(i))}}function HG(e,t,r){if(!(t>e.z0&&t<e.z1&&r<e.r1&&(e.r0>0?r>e.r0:r>=0))){let s=Math.min(e.z1,Math.max(e.z0,t)),i=Math.min(e.r1,Math.max(e.r0,r));return{d:Math.hypot(t-s,r-i),z:s,r:i}}let o=[{d:t-e.z0,z:e.z0,r},{d:e.z1-t,z:e.z1,r},{d:e.r1-r,z:t,r:e.r1}];e.r0>0&&o.push({d:r-e.r0,z:t,r:e.r0});let a=o.reduce((s,i)=>i.d<s.d?i:s);return{d:-a.d,z:a.z,r:a.r}}function iu(e,t,r){let n=KG(e,r),o={d:1/0,z:0,r:0};for(let a of t){let s=HG(a,n.z,n.r);s.d<o.d&&(o=s)}return{distance:o.d,on:df(df(r.centre,Po(r.axis,o.z)),Po(n.out,o.r))}}var mf=(Math.sqrt(5)-1)/2;function zG(e,t,r,n){let o=t,a=r,s=a-mf*(a-o),i=o+mf*(a-o),c=e(s),l=e(i);for(;a-o>n;)c<=l?(a=i,i=s,l=c,s=a-mf*(a-o),c=e(s)):(o=s,s=i,c=l,i=o+mf*(a-o),l=e(i));return c<=l?s:i}var YG=24;function CP(e,t,r,n){let o=u=>iu(uR(e,t,u),r,n).distance,a=pf(Ri(t,e))<1e-9?0:YG,s=0,i=o(0);for(let u=1;u<=a;u++){let d=o(u/a);d<i&&(i=d,s=u)}if(a===0)return{t:0,distance:i};let c=zG(o,Math.max(0,(s-1)/a),Math.min(1,(s+1)/a),1e-4),l=o(c);return l<i?{t:c,distance:l}:{t:s/a,distance:i}}function FP(e,t,r,n,o){let{t:a}=CP(e,t,n,o),s=uR(e,t,a),i=iu(s,n,o);return{distance:i.distance-r,onPart:PP(s,i.on,r,i.distance),onWheel:i.on}}function TP(e,t,r,n){let o=null,a=i=>{let c=iu(i,r,n);(!o||c.distance<o.distance)&&(o={p:i,distance:c.distance,on:c.on})};for(let i of e)a(i);for(let i=0;i<e.length;i++)for(let c=i+1;c<e.length;c++){let l=CP(e[i],e[c],r,n);(!o||l.distance<o.distance)&&a(uR(e[i],e[c],l.t))}let s=o;return{distance:s.distance-t,onPart:PP(s.p,s.on,t,s.distance),onWheel:s.on}}function PP(e,t,r,n){let o=Ri(t,e),a=pf(o);return a<1e-9||r===0?e:df(e,Po(o,(n>=0?r:-r)/a))}function gf(e,t,r,n,o){let a=r[0]-t[0],s=r[1]-t[1],i=r[2]-t[2],c=n[0]-t[0],l=n[1]-t[1],u=n[2]-t[2],d=e[0]-t[0],p=e[1]-t[1],m=e[2]-t[2],f=a*d+s*p+i*m,h=c*d+l*p+u*m,b=(_,D,I)=>{o[0]=_,o[1]=D,o[2]=I;let V=e[0]-_,O=e[1]-D,B=e[2]-I;return V*V+O*O+B*B};if(f<=0&&h<=0)return b(t[0],t[1],t[2]);let g=e[0]-r[0],y=e[1]-r[1],x=e[2]-r[2],v=a*g+s*y+i*x,k=c*g+l*y+u*x;if(v>=0&&k<=v)return b(r[0],r[1],r[2]);let R=f*k-v*h;if(R<=0&&f>=0&&v<=0){let _=f/(f-v);return b(t[0]+_*a,t[1]+_*s,t[2]+_*i)}let M=e[0]-n[0],S=e[1]-n[1],w=e[2]-n[2],F=a*M+s*S+i*w,T=c*M+l*S+u*w;if(T>=0&&F<=T)return b(n[0],n[1],n[2]);let A=F*h-f*T;if(A<=0&&h>=0&&T<=0){let _=h/(h-T);return b(t[0]+_*c,t[1]+_*l,t[2]+_*u)}let C=v*T-F*k;if(C<=0&&k-v>=0&&F-T>=0){let _=(k-v)/(k-v+(F-T));return b(r[0]+_*(n[0]-r[0]),r[1]+_*(n[1]-r[1]),r[2]+_*(n[2]-r[2]))}let P=1/(C+A+R),L=A*P,E=R*P;return b(t[0]+a*L+c*E,t[1]+s*L+l*E,t[2]+i*L+u*E)}function mR(e,t,r,n,o,a){let s=t[0]-e[0],i=t[1]-e[1],c=t[2]-e[2],l=n[0]-r[0],u=n[1]-r[1],d=n[2]-r[2],p=e[0]-r[0],m=e[1]-r[1],f=e[2]-r[2],h=s*s+i*i+c*c,b=l*l+u*u+d*d,g=l*p+u*m+d*f,y=S=>S<0?0:S>1?1:S,x=0,v=0;if(h<=1e-12&&b<=1e-12)x=0,v=0;else if(h<=1e-12)v=y(g/b);else{let S=s*p+i*m+c*f;if(b<=1e-12)x=y(-S/h);else{let w=s*l+i*u+c*d,F=h*b-w*w;x=F>1e-12?y((w*g-S*b)/F):0,v=(w*x+g)/b,v<0?(v=0,x=y(-S/h)):v>1&&(v=1,x=y((w-S)/h))}}o[0]=e[0]+x*s,o[1]=e[1]+x*i,o[2]=e[2]+x*c,a[0]=r[0]+v*l,a[1]=r[1]+v*u,a[2]=r[2]+v*d;let k=o[0]-a[0],R=o[1]-a[1],M=o[2]-a[2];return k*k+R*R+M*M}function WG(e,t,r,n,o,a){let s=t[0]-e[0],i=t[1]-e[1],c=t[2]-e[2],l=n[0]-r[0],u=n[1]-r[1],d=n[2]-r[2],p=o[0]-r[0],m=o[1]-r[1],f=o[2]-r[2],h=i*f-c*m,b=c*p-s*f,g=s*m-i*p,y=l*h+u*b+d*g,x=Math.sqrt((s*s+i*i+c*c)*(l*l+u*u+d*d)*(p*p+m*m+f*f));if(Math.abs(y)<=1e-12*x)return!1;let v=1/y,k=e[0]-r[0],R=e[1]-r[1],M=e[2]-r[2],S=(k*h+R*b+M*g)*v;if(S<0||S>1)return!1;let w=R*d-M*u,F=M*l-k*d,T=k*u-R*l,A=(s*w+i*F+c*T)*v;if(A<0||S+A>1)return!1;let C=(p*w+m*F+f*T)*v;return C<0||C>1?!1:(a[0]=e[0]+C*s,a[1]=e[1]+C*i,a[2]=e[2]+C*c,!0)}function yf(e,t,r,n,o,a,s){if(WG(e,t,r,n,o,s))return a[0]=s[0],a[1]=s[1],a[2]=s[2],0;let i=[0,0,0],c=[0,0,0],l=gf(e,r,n,o,s);a[0]=e[0],a[1]=e[1],a[2]=e[2];let u=(d,p,m)=>{d>=l||(l=d,a[0]=p[0],a[1]=p[1],a[2]=p[2],s[0]=m[0],s[1]=m[1],s[2]=m[2])};return u(gf(t,r,n,o,c),t,c),u(mR(e,t,r,n,i,c),i,c),u(mR(e,t,n,o,i,c),i,c),u(mR(e,t,o,r,i,c),i,c),l}function pR(e,t,r,n){let o=e.box,a=6*t,s=0;for(let i=0;i<3;i++){let c=Math.max(0,o[a+i]-n[i],r[i]-o[a+3+i]);s+=c*c}return s}function dR(e,t,r){for(let n of r){let o=0;for(let a=0;a<3;a++){let s=Math.max(Math.abs(n.c[a]-e[t+a]),Math.abs(e[t+3+a]-n.c[a]));o+=s*s}if(o<=n.r*n.r)return!0}return!1}function xf(e,t,r,n,o){let a=n;if(!e.nodes)return a;let s=[0],i=[t(0)];for(;s.length;){let c=s.pop();if(i.pop()>=a||o.length&&dR(e.box,6*c,o))continue;if(e.right[c]<0){let f=e.start[c]+e.size[c];for(let h=e.start[c];h<f;h++){let b=r(h,a);if(b<a&&(a=b),a<=0)return 0}continue}let u=c+1,d=e.right[c],p=t(u),m=t(d);p<=m?(m<a&&(s.push(d),i.push(m)),p<a&&(s.push(u),i.push(p))):(p<a&&(s.push(u),i.push(p)),m<a&&(s.push(d),i.push(m)))}return a}function EP(e,t,r){let n=[Math.min(t[0],r[0]),Math.min(t[1],r[1]),Math.min(t[2],r[2])],o=[Math.max(t[0],r[0]),Math.max(t[1],r[1]),Math.max(t[2],r[2])],a=r[0]-t[0],s=r[1]-t[1],i=r[2]-t[2],c=a*a+s*s+i*i,l=e.box;return u=>{let d=6*u,p=(l[d]+l[d+3])/2,m=(l[d+1]+l[d+4])/2,f=(l[d+2]+l[d+5])/2,h=(l[d+3]-l[d])/2,b=(l[d+4]-l[d+1])/2,g=(l[d+5]-l[d+2])/2,y=c>1e-12?((p-t[0])*a+(m-t[1])*s+(f-t[2])*i)/c:0;y=y<0?0:y>1?1:y;let x=p-t[0]-y*a,v=m-t[1]-y*s,k=f-t[2]-y*i,R=Math.sqrt(x*x+v*v+k*k)-Math.sqrt(h*h+b*b+g*g);return Math.max(R,Math.sqrt(pR(e,u,n,o)))}}var Ut=(e,t,r)=>{let n=9*t+3*r;return[e.tri[n],e.tri[n+1],e.tri[n+2]]};function cu(e,t,r,n=1/0,o=[]){let a=EP(e,t,r),s=[0,0,0],i=[0,0,0],c=null,l=xf(e,a,(u,d)=>{let p=1/0;return no(Ut(e,u,0),Ut(e,u,1),Ut(e,u,2),o,(m,f,h)=>{let b=Math.sqrt(yf(t,r,m,f,h,s,i));b<p&&(p=b),b<d&&(!c||b<c.distance)&&(c={distance:b,onMesh:[...i],onPart:[...s]})}),p},n,o);return c&&c.distance===l?c:null}function Rf(e,t,r,n,o,a=1/0,s=[]){let i=yi(t,r,n,o),c=Math.hypot(r[0],r[1],r[2])||1,l=r[0]/c,u=r[1]/c,d=r[2]/c,p=o/2,m=[t[0]-p*l,t[1]-p*u,t[2]-p*d],f=[t[0]+p*l,t[1]+p*u,t[2]+p*d],h=e.box,b=EP(e,m,f),g=R=>{let M=6*R,S=(h[M]+h[M+3])/2,w=(h[M+1]+h[M+4])/2,F=(h[M+2]+h[M+5])/2,T=(h[M+3]-h[M])/2,A=(h[M+4]-h[M+1])/2,C=(h[M+5]-h[M+2])/2,P=(S-t[0])*l+(w-t[1])*u+(F-t[2])*d,L=Math.abs(l)*T+Math.abs(u)*A+Math.abs(d)*C,E=Math.max(0,Math.abs(P)-L-p);return Math.max(E,b(R)-n,Math.sqrt(pR(e,R,i.min,i.max)))},y=[0,0,0],x=[0,0,0],v=null,k=xf(e,g,(R,M)=>{let S=1/0;return no(Ut(e,R,0),Ut(e,R,1),Ut(e,R,2),s,(w,F,T)=>{let A=Math.min(M,S),C=(w[0]-t[0])*l+(w[1]-t[1])*u+(w[2]-t[2])*d,P=(F[0]-t[0])*l+(F[1]-t[1])*u+(F[2]-t[2])*d,L=(T[0]-t[0])*l+(T[1]-t[1])*u+(T[2]-t[2])*d;if(Math.max(0,Math.min(C,P,L)-p,-p-Math.max(C,P,L))>=A||Math.sqrt(yf(m,f,w,F,T,y,x))-n>=A)return;let _=xi(Va([w,F,T]),i,1e-6);if(_.distance<A)if(_.distance>0)v={distance:_.distance,onMesh:_.onA,onPart:_.onB};else{let D=[0,0,0];gf(t,w,F,T,D),v={distance:0,onMesh:D,onPart:D}}_.distance<S&&(S=_.distance)}),S},a,s);return v&&v.distance===k?v:null}var fR=(e,t,r)=>cu(e,t,t,r)!==null,ff=(e,t)=>{let r=e[0]-t.c[0],n=e[1]-t.c[1],o=e[2]-t.c[2];return r*r+n*n+o*o<=t.r*t.r},vi=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2,(e[2]+t[2])/2],ki=(e,t)=>(e[0]-t[0])**2+(e[1]-t[1])**2+(e[2]-t[2])**2,jG=1,UG=6;function no(e,t,r,n,o,a=0){if(!n.length)return o(e,t,r);let s=[0,0,0],i=n.filter(p=>gf(p.c,e,t,r,s)<=p.r*p.r);if(!i.length)return o(e,t,r);for(let p of i)if(ff(e,p)&&ff(t,p)&&ff(r,p))return;if(Math.sqrt(Math.max(ki(e,t),ki(t,r),ki(r,e)))<=Math.max(jG,Math.min(...i.map(p=>p.r))/8)||a>=UG){let p=[(e[0]+t[0]+r[0])/3,(e[1]+t[1]+r[1])/3,(e[2]+t[2]+r[2])/3];i.some(m=>ff(p,m))||o(e,t,r);return}let l=vi(e,t),u=vi(t,r),d=vi(r,e);no(e,l,d,i,o,a+1),no(l,t,u,i,o,a+1),no(d,u,r,i,o,a+1),no(l,u,d,i,o,a+1)}function XG(e,t,r,n){let o=[];return no(e,t,r,n,(a,s,i)=>o.push([a,s,i])),o}var qG=e=>[Math.min(e[0][0],e[1][0],e[2][0]),Math.min(e[0][1],e[1][1],e[2][1]),Math.min(e[0][2],e[1][2],e[2][2]),Math.max(e[0][0],e[1][0],e[2][0]),Math.max(e[0][1],e[1][1],e[2][1]),Math.max(e[0][2],e[1][2],e[2][2])];function hR(e,t,r=1/0,n=[]){let o=null,a=xf(e,s=>Math.sqrt(pR(e,s,t.min,t.max)),(s,i)=>{let c=1/0;return no(Ut(e,s,0),Ut(e,s,1),Ut(e,s,2),n,(l,u,d)=>{let p=Va([l,u,d]),m=Math.min(i,c),f=0;for(let b=0;b<3;b++){let g=Math.max(0,p.min[b]-t.max[b],t.min[b]-p.max[b]);f+=g*g}if(Math.sqrt(f)>=m)return;let h=xi(p,t,1e-6);if(h.distance<m)if(h.distance>0)o={distance:h.distance,onMesh:h.onA,onPart:h.onB};else{let b=[(l[0]+u[0]+d[0])/3,(l[1]+u[1]+d[1])/3,(l[2]+u[2]+d[2])/3];o={distance:0,onMesh:b,onPart:b}}h.distance<c&&(c=h.distance)}),c},r,n);return o&&o.distance===a?o:null}function QG(e,t,r,n,o,a,s,i){let c=[0,0,0],l=[0,0,0],u=1/0,d=(f,h,b)=>{f>=u||(u=f,s[0]=h[0],s[1]=h[1],s[2]=h[2],i[0]=b[0],i[1]=b[1],i[2]=b[2])},p=[e,t,r],m=[n,o,a];for(let f=0;f<3;f++)if(d(yf(p[f],p[(f+1)%3],n,o,a,c,l),c,l),u===0)return 0;for(let f=0;f<3;f++)if(d(yf(m[f],m[(f+1)%3],e,t,r,c,l),l,c),u===0)return 0;return u}var ZG=.002;function bR(e,t,r,n=1/0,o=[]){if(!e.nodes||!t.nodes)return null;let a=new Float64Array(6*t.nodes).fill(NaN),s=x=>{let v=6*x;if(!Number.isNaN(a[v]))return v;let k=1/0,R=1/0,M=1/0,S=-1/0,w=-1/0,F=-1/0;for(let T=0;T<8;T++){let A=Vt(r,[t.box[v+(T&1?3:0)],t.box[v+1+(T&2?3:0)],t.box[v+2+(T&4?3:0)]]);A[0]<k&&(k=A[0]),A[0]>S&&(S=A[0]),A[1]<R&&(R=A[1]),A[1]>w&&(w=A[1]),A[2]<M&&(M=A[2]),A[2]>F&&(F=A[2])}return a.set([k,R,M,S,w,F],v),v},i=(x,v)=>{let k=6*x,R=s(v),M=0;for(let S=0;S<3;S++){let w=Math.max(0,e.box[k+S]-a[R+3+S],a[R+S]-e.box[k+3+S]);M+=w*w}return Math.sqrt(M)},c=(x,v)=>(x[v+3]-x[v])**2+(x[v+4]-x[v+1])**2+(x[v+5]-x[v+2])**2,l=(x,v,k)=>{let R=[Ut(x,v,0),Ut(x,v,1),Ut(x,v,2)];return k?R.map(M=>Vt(k,M)):R},u=new Map,d=new Map,p=(x,v,k,R)=>{let M=R.get(v);if(!M){M=[];let S=x.start[v]+x.size[v];for(let w=x.start[v];w<S;w++)for(let F of XG(...l(x,w,k),o))M.push({t:F,box:qG(F)});R.set(v,M)}return M},m=n,f=n,h=null,b=[0,0,0],g=[0,0,0],y=[[0,0,i(0,0)]];for(;y.length;){let[x,v,k]=y.pop();if(k>=f||o.length&&(dR(e.box,6*x,o)||dR(a,s(v),o)))continue;let R=e.right[x]<0,M=t.right[v]<0;if(R&&M){let A=p(t,v,r,d);if(!A.length)continue;for(let C of p(e,x,null,u))for(let P of A){let L=0;for(let _=0;_<3;_++){let D=Math.max(0,C.box[_]-P.box[3+_],P.box[_]-C.box[3+_]);L+=D*D}if(L>=f*f)continue;let E=Math.sqrt(QG(C.t[0],C.t[1],C.t[2],P.t[0],P.t[1],P.t[2],b,g));if(E<m&&(m=E,f=E*(1-ZG),h={distance:E,onA:[...b],onB:[...g]},m<=0))return h}continue}let w=!R&&(M||c(e.box,6*x)>=c(a,s(v)))?[[x+1,v],[e.right[x],v]]:[[x,v+1],[x,t.right[v]]],F=w.map(([A,C])=>i(A,C)),T=F[0]<=F[1]?[1,0]:[0,1];for(let A of T)F[A]<f&&y.push([w[A][0],w[A][1],F[A]])}return h}function hf(e,t){let r=e[0]-t.centre[0],n=e[1]-t.centre[1],o=e[2]-t.centre[2],a=r*t.axis[0]+n*t.axis[1]+o*t.axis[2],s=r-a*t.axis[0],i=n-a*t.axis[1],c=o-a*t.axis[2];return[a,Math.sqrt(s*s+i*i+c*c)]}function LP(e,t,r,n,o){let a=1/0;for(let s of o){let i=Math.max(0,s.z0-t,e-s.z1),c=Math.max(0,s.r0-n,r-s.r1),l=Math.hypot(i,c);l<a&&(a=l)}return a}var bf=8;function IP(e,t,r,n=1/0,o=[]){if(!r.length)return null;let a=e.box,s=m=>{let f=6*m,h=1/0,b=-1/0,g=0;for(let y=0;y<8;y++){let[x,v]=hf([a[f+(y&1?3:0)],a[f+1+(y&2?3:0)],a[f+2+(y&4?3:0)]],t);x<h&&(h=x),x>b&&(b=x),v>g&&(g=v)}return LP(h,b,0,g,r)},i=m=>iu(m,r,t),c=null,l=(m,f)=>{let h=i(m),b=Math.max(0,h.distance);return b<f&&(!c||b<c.distance)&&(c={distance:b,onMesh:m,onPart:b>0?h.on:m}),b},u=(m,f,h)=>{let b=T=>i([m[0]+(f[0]-m[0])*T,m[1]+(f[1]-m[1])*T,m[2]+(f[2]-m[2])*T]).distance,g=0,y=1/0;for(let T=1;T<bf;T++){let A=b(T/bf);A<y&&(y=A,g=T)}let x=(g-1)/bf,v=(g+1)/bf,k=(Math.sqrt(5)-1)/2,R=v-k*(v-x),M=x+k*(v-x),S=b(R),w=b(M);for(;v-x>.001;)S<=w?(v=M,M=R,w=S,R=v-k*(v-x),S=b(R)):(x=R,R=M,S=w,M=x+k*(v-x),w=b(M));let F=S<=w?R:M;return l([m[0]+(f[0]-m[0])*F,m[1]+(f[1]-m[1])*F,m[2]+(f[2]-m[2])*F],h)},d=(m,f,h,b,g)=>{let y=hf(m,t),x=hf(f,t),v=hf(h,t);if(LP(Math.min(y[0],x[0],v[0]),Math.max(y[0],x[0],v[0]),0,Math.max(y[1],x[1],v[1]),r)>=b)return 1/0;if(Math.max(ki(m,f),ki(f,h),ki(h,m))>DP*DP&&g<4){let S=vi(m,f),w=vi(f,h),F=vi(h,m),T=1/0;for(let[A,C,P]of[[m,S,F],[S,f,w],[F,w,h],[S,w,F]])T=Math.min(T,d(A,C,P,Math.min(b,T),g+1));return T}let M=1/0;for(let S of[m,f,h])M=Math.min(M,l(S,Math.min(b,M)));return M=Math.min(M,u(m,f,Math.min(b,M)),u(f,h,Math.min(b,M)),u(h,m,Math.min(b,M))),M},p=xf(e,s,(m,f)=>{let h=1/0;return no(Ut(e,m,0),Ut(e,m,1),Ut(e,m,2),o,(b,g,y)=>{h=Math.min(h,d(b,g,y,Math.min(f,h),0))}),h},n,o);return c&&c.distance===p?c:null}var DP=25;var xR=["upright","wheel","upperArm","lowerArm","rocker","damperBody"],RR={upright:"upright",wheel:"wheel",upperArm:"upper wishbone",lowerArm:"lower wishbone",rocker:"rocker",damperBody:"damper body"},eK=.5;function vR(e,t,r){let n=[];switch(t){case"upright":case"wheel":e.mcpherson||n.push("uprightUpper"),n.push("uprightLower","tieOuter"),(e.mcpherson||r==="upright")&&n.push("pushrodOuter");break;case"upperArm":if(e.mcpherson)return[];n.push("ucaFront","ucaRear","uprightUpper"),r==="upperArm"&&n.push("pushrodOuter");break;case"lowerArm":n.push("lcaFront","lcaRear","uprightLower"),r==="lowerArm"&&!e.mcpherson&&n.push("pushrodOuter");break;case"rocker":if(e.direct)return[];n.push("rockerPivotA","rockerPivotB","rockerToPushrod","rockerToDamper");break;case"damperBody":if(e.decoupled||e.mcpherson)return[];n.push("damperChassis",e.direct?"pushrodOuter":"rockerToDamper");break}return n.filter(o=>e[o].every(Number.isFinite))}var tK=e=>e[1]==="L"?"left":"right",rK=e=>[e[0],-e[1],e[2]];function _P(e,t,r,n,o){let a=vR(r,t,o).filter(f=>e.placedOn[f]?.every(Number.isFinite)),s=tK(n)!==e.side,i=a.map(f=>s?rK(e.placedOn[f]):e.placedOn[f]),c=a.map(f=>r[f]),l=s?hP:null;if(t==="damperBody"){if(a.length<2)return null;let f=vf(Mi(i[1],i[0])),h=vf(Mi(c[1],c[0])),b=cR(Wu(f,h)),g=Vt({r:b,t:[0,0,0]},i[0]),y={r:b,t:Mi(c[0],g)};return{iso:l?su(y,l):y,worst:null}}if(a.length<3)return null;let u=gP(i,c),d=Math.max(...u.residuals),p=0,m=-1;for(let f=0;f<a.length;f++){let h=0;for(let b=0;b<a.length;b++)b!==f&&(h+=Math.abs(yR(Mi(i[f],i[b]))-yR(Mi(c[f],c[b]))));h>m&&([p,m]=[f,h])}return{iso:l?su(u.iso,l):u.iso,worst:{key:a[p],by:d}}}var NP=e=>!!e&&(!e.worst||e.worst.by<=eK);var nK=1,gR=.5;function oK(e,t,r=nK){let n=vf(t.axis),o=Math.abs(n[0])<.9?[1,0,0]:[0,1,0],a=vf(Mi(o,OP(n,lu(o,n)))),s=iK(n,a),i=Math.floor(e.length/9),c=new Float64Array(9*i),l=1/0,u=-1/0;for(let h=0;h<3*i;h++){let b=[e[3*h]-t.centre[0],e[3*h+1]-t.centre[1],e[3*h+2]-t.centre[2]],g=lu(b,n);c[3*h]=lu(b,a),c[3*h+1]=lu(b,s),c[3*h+2]=g,g<l&&(l=g),g>u&&(u=g)}if(!i)return[];let d=Math.max(1,Math.ceil((u-l)/r)),p=new Float64Array(d).fill(1/0),m=new Float64Array(d).fill(-1/0);for(let h=0;h<i;h++){let b=[0,1,2].map(k=>[c[9*h+3*k],c[9*h+3*k+1],c[9*h+3*k+2]]),g=Math.min(b[0][2],b[1][2],b[2][2]),y=Math.max(b[0][2],b[1][2],b[2][2]),x=Math.max(0,Math.min(d-1,Math.floor((g-l)/r))),v=Math.max(0,Math.min(d-1,Math.floor((y-l)/r)));for(let k=x;k<=v;k++){let R=aK(b,l+k*r,l+(k+1)*r);if(!R.length)continue;let M=0;for(let w of R)M=Math.max(M,Math.hypot(w[0],w[1]));let S=sK(R);S<p[k]&&(p[k]=S),M>m[k]&&(m[k]=M)}}let f=[];for(let h=0;h<d;h++){if(!(m[h]>=0))continue;let b=p[h]<gR?0:p[h],g=f[f.length-1],y=l+h*r;g&&Math.abs(g.z1-y)<1e-9&&Math.abs(g.r0-b)<=gR&&Math.abs(g.r1-m[h])<=gR?(g.z1=y+r,g.r0=Math.min(g.r0,b),g.r1=Math.max(g.r1,m[h])):f.push({z0:y,z1:y+r,r0:b,r1:m[h]})}return f}function aK(e,t,r){let n=(o,a)=>{let s=[];for(let i=0;i<o.length;i++){let c=o[i],l=o[(i+1)%o.length],u=a(c),d=a(l);if(u>=0&&s.push(c),u>=0!=d>=0){let p=u/(u-d);s.push([c[0]+(l[0]-c[0])*p,c[1]+(l[1]-c[1])*p,c[2]+(l[2]-c[2])*p])}}return s};return n(n(e,o=>o[2]-t),o=>r-o[2])}function sK(e){let t=!1,r=!1,n=1/0;for(let o=0;o<e.length;o++){let a=e[o],s=e[(o+1)%e.length],i=a[0]*s[1]-a[1]*s[0];i>1e-12?t=!0:i<-1e-12&&(r=!0);let c=s[0]-a[0],l=s[1]-a[1],u=c*c+l*l,d=u>1e-18?Math.max(0,Math.min(1,-(a[0]*c+a[1]*l)/u)):0;n=Math.min(n,Math.hypot(a[0]+d*c,a[1]+d*l))}return t!==r?0:n}var Mi=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],lu=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],iK=(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]],yR=e=>Math.sqrt(lu(e,e)),OP=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],vf=e=>OP(e,1/(yR(e)||1));function VP(e,t,r){if(!e.bands){let n=e.tree.tri,o=new Float64Array(n.length);for(let a=0;a+2<n.length;a+=3){let s=Vt(t,[n[a],n[a+1],n[a+2]]);o[a]=s[0],o[a+1]=s[1],o[a+2]=s[2]}e.bands=oK(o,r)}return e.bands}var HP=25,ft=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],wr=e=>Math.hypot(e[0],e[1],e[2]),br=(e,t,r)=>[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r,e[2]+(t[2]-e[2])*r],MR={lowerArm:"lowerArm",upperArm:"upperArm",upright:"upright"},cK=(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]],$a=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],uu=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],zr=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],kf=e=>zr(e,1/(wr(e)||1)),lK={"upper wishbone, front leg":{tube:"upperArm",joints:["ballJoint","ballJoint"]},"upper wishbone, rear leg":{tube:"upperArm",joints:["ballJoint","ballJoint"]},"lower wishbone, front leg":{tube:"lowerArm",joints:["ballJoint","ballJoint"]},"lower wishbone, rear leg":{tube:"lowerArm",joints:["ballJoint","ballJoint"]},"tie rod":{tube:"tieRod",joints:["rodEnd","rodEnd"]},pushrod:{tube:"rod",joints:["rodEnd","rodEnd"]},strut:{tube:"strut",joints:["ballJoint","ballJoint"]}},uK=(e,t)=>e.axles?.[t[0]==="F"?"front":"rear"]??null;function mK(e,t){let r=kf(e.spinAxis),n=ft(e.uprightUpper,e.uprightLower),o=kf(ft(n,zr(r,$a(n,r)))),a=cK(r,o);a[0]<0&&(a=zr(a,-1));let s=t.discDiameter/2+t.caliperHeight,i=Math.max(0,Math.min(t.discDiameter/2,2*t.effRadius-t.discDiameter/2)),c=t.caliperAngle*Math.PI/180,l=Math.min(Math.PI/2,t.caliperLength/2/Math.max(1,s)),u=(p,m,f)=>uu(uu(e.wheelCenter,zr(r,f)),uu(zr(o,m*Math.cos(p)),zr(a,m*Math.sin(p)))),d=[];for(let p of[t.discOffset-t.caliperWidth/2,t.discOffset+t.caliperWidth/2]){for(let m of[-1,-.5,0,.5,1])d.push(u(c+m*l,s,p));for(let m of[-1,1])d.push(u(c+m*l,i,p))}return d}function dK(e,t){let r=[];return e.mcpherson||r.push(e.uprightUpper),r.push(e.uprightLower,e.tieOuter),(e.mcpherson||t==="upright")&&r.push(e.pushrodOuter),r.filter(n=>n.every(Number.isFinite))}function zP(e,t,r,n,o){let a=[],s=uK(n,t),i=fK(s,e,t,r),c=!!s?.rackHousing&&t[0]==="F";for(let f of sR(e)){if(f.body==="upperArm"&&i.has("upperArm")||f.body==="lowerArm"&&i.has("lowerArm"))continue;let h=e[f.inboard],b=e[f.outboard];if(![...h,...b].every(Number.isFinite))continue;let g=[c&&f.name==="tie rod"?"rack":f.ends[0],f.ends[1]==="rodAttach"?MR[r]:f.ends[1]],y=lK[f.name],x=!s||!y?n.linkRadius:y.tube==="strut"?s.strut:s.tube[y.tube],v=s&&y?[s.housing[y.joints[0]],s.housing[y.joints[1]]]:[n.jointAllowance,n.jointAllowance];a.push({kind:"link",id:`${t} ${f.name}`,name:f.name,corner:t,body:f.body,ends:g,a:h,b,radius:x,housing:v})}let l=s?.damper;if(l&&!e.decoupled&&!e.mcpherson){let f=e.damperChassis,h=e.direct?e.pushrodOuter:e.rockerToDamper,b=e.direct?MR[r]:"rocker";if([...f,...h].every(Number.isFinite)){let g=SP(`${t} damper`,"damper","damper",t,{p:f,body:"chassis",corner:t},{p:h,body:b,corner:t},l,s.housing.rodEnd);a.push(...i.has("damperBody")?g.filter(y=>y.id!==`${t} damper body`):g)}}s?.arb&&o&&a.push(...vP(s.arb,o.def,o.r,t,s)),s?.rackHousing&&t[0]==="F"&&a.push(kP(s.rackHousing,t));let u=s?.driveshaft?MP(s.driveshaft,e,t):null;u&&a.push(u);let d={centre:e.wheelCenter,axis:kf(e.spinAxis)},p=t[0]==="F"?n.tyreRadius.front:n.tyreRadius.rear;a.push({kind:"tyre",id:`${t} tyre`,name:"tyre",corner:t,body:"wheel",centre:e.wheelCenter,axis:e.spinAxis,radius:p,width:n.tyreWidth,section:s?.rim?AP(s.rim,p,n.tyreWidth):null});let m=i.get("wheel");if(m?a.push({kind:"rim",id:`${t} rim`,name:"rim",corner:t,body:"wheel",frame:d,bands:VP(m.live,m.fit.iso,d),model:!0}):s?.rim&&a.push({kind:"rim",id:`${t} rim`,name:"rim",corner:t,body:"wheel",frame:d,bands:wP(s.rim)}),s){let f=dK(e,r);f.length&&!i.has("upright")&&a.push({kind:"hull",id:`${t} upright`,name:"upright",corner:t,body:"upright",points:f,radius:s.uprightWall}),s.brake&&a.push({kind:"hull",id:`${t} caliper`,name:"caliper",corner:t,body:"upright",points:mK(e,s.brake),radius:0})}for(let[f,h]of i)f!=="wheel"&&a.push(gK(f,h.live,h.fit,e,t,r,n,s));return a}var pK={upright:"upright",upperArm:"upperArm",lowerArm:"lowerArm",rocker:"rocker",damperBody:"damper"};function fK(e,t,r,n){let o=new Map;if(!e?.models)return o;for(let a of xR){let s=e.models[a];if(!s)continue;let i=_P(s,a,t,r,n);NP(i)&&o.set(a,{live:s,fit:i})}return o}var hK=["ucaFront","ucaRear","lcaFront","lcaRear","uprightUpper","uprightLower"];function bK(e,t,r,n){switch(t){case"uprightUpper":return e==="upright"?"upperArm":"upright";case"uprightLower":return e==="upright"?"lowerArm":"upright";case"tieOuter":return"tieRod";case"pushrodOuter":return e==="damperBody"?MR[n]:r.mcpherson?"strut":"rod";case"rockerToPushrod":return"rod";case"rockerToDamper":return e==="rocker"?"damper":"rocker";default:return"chassis"}}function gK(e,t,r,n,o,a,s,i){let c=vR(n,e,a).map(l=>({key:l,p:n[l],on:bK(e,l,n,a),reach:i?i.housing[hK.includes(l)?"ballJoint":"rodEnd"]:s.jointAllowance}));return{kind:"model",id:`${o} ${RR[e]} model`,name:`${RR[e]} model`,corner:o,body:pK[e],piece:e,tree:t.tree,iso:r.iso,inverse:bP(r.iso),ends:[...new Set(c.map(l=>l.on))],joints:c}}function yK(e,t,r){let n=e.ends[t];if(n==="chassis")return!1;let o=e.endCorners?.[t]??e.corner;return r.body===n&&r.corner===o||r.ends.some((a,s)=>a===n&&(r.endCorners?.[s]??r.corner)===o)}var BP=(e,t)=>(e.body==="rod"||e.body==="dropLink")&&e.ends[1]===t.body&&(e.endCorners?.[1]??e.corner)===t.corner,$P=(e,t)=>e.body==="damper"&&e.ends[1]===t.body;function AR(e,t,r){return e.find(({parts:[n,o]})=>n===t.name&&o===r.name||n===r.name&&o===t.name)}function YP(e,t,r=[]){let n=[],o=(d,p,m,f,h=!1)=>{let b=f?void 0:AR(r,d,p);n.push({a:d,b:p,name:`${d.name} / ${p.name}`,trim:m,skip:b?"ignored":f,...b?{reason:b.reason}:{},...h?{fixed:h}:{}})},a=e.filter(d=>d.kind==="link");for(let d=0;d<a.length;d++)for(let p=d+1;p<a.length;p++){let m=xK(a[d],a[p],r);m&&n.push(m)}let s=e.find(d=>d.kind==="tyre"&&d.section!==null),i=e.find(d=>d.kind==="rim");for(let d of a)s&&o(d,s,[0,0,0,0],null),i&&o(d,i,[0,0,0,0],null);let c=e.filter(d=>d.kind==="hull");for(let d of c)i&&o(d,i,[0,0,0,0],null,!0);let l=c.find(d=>d.name==="caliper");if(l)for(let d of a)o(d,l,[d.ends[0]==="upright"?d.housing[0]:0,d.ends[1]==="upright"?d.housing[1]:0,0,0],null);let u=e.filter(d=>d.kind==="model");for(let d=0;d<u.length;d++){let p=u[d];for(let m of a){let f=RK(p,m,r);f&&n.push(f)}s&&p.body!=="upright"&&o(p,s,[0,0,0,0],null),i&&o(p,i,[0,0,0,0],null,p.body==="upright"),l&&p.body!=="upright"&&o(p,l,[0,0,0,0],null);for(let m=d+1;m<u.length;m++)o(p,u[m],[0,0,0,0],null)}for(let d of t)for(let p of e)p.kind==="tyre"||p.kind==="model"||p.kind==="link"&&!p.shared?o(d,p,[0,0,0,0],null):p.kind==="link"&&p.corner[1]==="L"&&d.kind==="volume"&&o(d,p,[0,0,0,0],null,!0);return n}function xK(e,t,r=[]){if(e.body===t.body&&e.corner===t.corner)return null;let n=(i,c,l)=>yK(i,c,l)?i.housing[c]:0,o=[n(e,0,t),n(e,1,t),n(t,0,e),n(t,1,e)],a=BP(e,t)||BP(t,e)?"rod on arm":$P(e,t)||$P(t,e)?"damper on arm":null,s=a?void 0:AR(r,e,t);return{a:e,b:t,name:`${e.name} / ${t.name}`,trim:o,skip:s?"ignored":a,...s?{reason:s.reason}:{},...e.shared&&t.shared?{fixed:!0}:{}}}function RK(e,t,r=[]){if(t.body===e.body&&t.corner===e.corner)return null;let n=i=>{let c=t.ends[i];return c==="chassis"?0:(t.endCorners?.[i]??t.corner)===e.corner&&(c===e.body||e.ends.includes(c))?t.housing[i]:0},a=(t.body==="rod"||t.body==="dropLink")&&t.ends[1]===e.body&&(t.endCorners?.[1]??t.corner)===e.corner?"rod on arm":t.body==="damper"&&t.ends[1]===e.body?"damper on arm":null,s=a?void 0:AR(r,e,t);return{a:e,b:t,name:`${e.name} / ${t.name}`,trim:[0,0,n(0),n(1)],skip:s?"ignored":a,...s?{reason:s.reason}:{}}}function mu(e,t,r,n){let o=wr(ft(t,e));if(o<=r+n){let a=br(e,t,.5);return[a,a]}return[br(e,t,r/o),br(e,t,1-n/o)]}function xn(e,t,r){let n=ft(t,e),o=wr(n);return o>1e-9?br(e,t,r/o):e}function GP(e,t,r,n){let o=ft(r,t),a=wr(o),s=a>1e-12?zr(o,1/a):[1,0,0],i=$a(ft(e,t),s),c=ft(ft(e,t),zr(s,i)),l=wr(c),u=Math.max(0,Math.min(a,i)),d=l>n?zr(c,n/l):c,p=uu(uu(t,zr(s,u)),d);return{distance:wr(ft(e,p)),on:p}}function WP(e,t,r,n){let o=ft(t,e),a=ft(n,r),s=ft(e,r),i=$a(o,o),c=$a(a,a),l=$a(a,s),u=b=>Math.max(0,Math.min(1,b));if(i<=1e-12&&c<=1e-12)return{s:0,t:0};if(i<=1e-12)return{s:0,t:u(l/c)};let d=$a(o,s);if(c<=1e-12)return{s:u(-d/i),t:0};let p=$a(o,a),m=i*c-p*p,f=m>1e-12?u((p*l-d*c)/m):0,h=(p*f+l)/c;return h<0?(h=0,f=u(-d/i)):h>1&&(h=1,f=u((p-d)/i)),{s:f,t:h}}function vK(e,t,r,n,o){let{s:a,t:s}=WP(r,n,e,t);if(a>1e-9&&a<1-1e-9){let p=br(r,n,a),m=br(e,t,s),f=wr(ft(m,p));if(f>=o)return{distance:f-o,onSeg:m,onCyl:xn(p,m,o)}}let i=p=>GP(br(e,t,p),r,n,o).distance,l=[0,wr(ft(t,e))<1e-12?0:yP(i,0,1,1e-7).x,1].reduce((p,m)=>i(m)<i(p)?m:p),u=br(e,t,l),d=GP(u,r,n,o);return{distance:d.distance,onSeg:u,onCyl:d.on}}function SR(e,t,r){let n=ft(r,t),o=wr(n);return!e.flat||o<1e-9?{shape:aR(t,r),pad:e.radius}:{shape:yi(br(t,r,.5),zr(n,1/o),e.radius,o),pad:0}}function KP(e,t,r){let n=SR(e.part,e.p0,e.p1),o="part"in t?SR(t.part,t.p0,t.p1):t,a="part"in t?t.part.radius:t.radius,s=n.pad+o.pad;if(lf(n.shape,o.shape)-s>=r)return null;let i=-(e.part.radius+a);if("part"in t&&e.part.flat!==t.part.flat){let[l,u]=e.part.flat?[t,e]:[e,t],d=vK(l.p0,l.p1,u.p0,u.p1,u.part.radius),[p,m]=e.part.flat?[d.onCyl,d.onSeg]:[d.onSeg,d.onCyl];if(d.distance<=1e-9)return{distance:i,onA:p,onB:m};let f=l.part.radius;return e.part.flat?{distance:d.distance-f,onA:p,onB:xn(m,p,f)}:{distance:d.distance-f,onA:xn(p,m,f),onB:m}}if("part"in t&&e.part.flat&&t.part.flat){let{s:l,t:u}=WP(e.p0,e.p1,t.p0,t.p1),d=p=>p>1e-9&&p<1-1e-9;if(d(l)&&d(u)){let p=br(e.p0,e.p1,l),m=br(t.p0,t.p1,u),f=wr(ft(m,p));if(f>=e.part.radius+t.part.radius)return{distance:f-e.part.radius-t.part.radius,onA:xn(p,m,e.part.radius),onB:xn(m,p,t.part.radius)}}}let c=xi(n.shape,o.shape,e.part.flat||"part"in t&&t.part.flat?1e-6:1e-9);return c.distance<=0?{distance:i,onA:c.onA,onB:c.onB}:{distance:c.distance-s,onA:xn(c.onA,c.onB,n.pad),onB:xn(c.onB,c.onA,o.pad)}}var kK=["chassis","rack"];function MK(e,t,r,n){let o,a=!1;if(t.kind==="link"){let i=[0,0];for(let d of[0,1])kK.includes(t.ends[d])&&fR(e.tree,d===0?t.a:t.b,r.mountAllowance)&&(i[d]=t.housing[d],a=!0);let[c,l]=mu(t.a,t.b,i[0],i[1]),u=wr(ft(l,c));if(!t.flat||u<1e-9){let d=cu(e.tree,c,l,n+t.radius);o=d&&{...d,distance:d.distance-t.radius,onPart:d.distance>1e-9?xn(d.onPart,d.onMesh,t.radius):d.onPart}}else o=Rf(e.tree,br(c,l,.5),ft(l,c),t.radius,u,Math.max(0,n))}else o=Rf(e.tree,t.centre,t.axis,t.radius,t.width,Math.max(0,n));if(!o)return null;let s=o.distance<=0;return{distance:s?0:o.distance,onA:o.onMesh,onB:s?o.onMesh:o.onPart,...s?{touches:!0}:{},...a?{mounted:!0}:{}}}function jP(e,t,r=1/0){let{a:n,b:o}=e;if(n.kind==="model"||o.kind==="model")return AK(e,t,r);if(n.kind==="mesh"&&(o.kind==="link"||o.kind==="tyre"))return MK(n,o,t,r);if(n.kind==="link"&&o.kind==="link"){let[a,s]=mu(n.a,n.b,e.trim[0],e.trim[1]),[i,c]=mu(o.a,o.b,e.trim[2],e.trim[3]);return KP({part:n,p0:a,p1:s},{part:o,p0:i,p1:c},r)}if(n.kind==="volume"&&(o.kind==="link"||o.kind==="tyre")){let a=oR(n.box.min,n.box.max),s=o.kind==="link"?SR(o,o.a,o.b):null,i=s?s.shape:yi(o.centre,o.axis,o.radius,o.width),c=s?s.pad:0,l=lf(a,i);if(l>0&&l-c>=r)return null;let u=iR(a,i,c);return{distance:u.distance,onA:u.gap.box,onB:u.gap.part}}if(n.kind==="link"&&(o.kind==="rim"||o.kind==="tyre"&&o.section)){let a=o.kind==="rim"?o.bands:o.section,s=o.kind==="rim"?o.frame:{centre:o.centre,axis:o.axis},i=FP(n.a,n.b,n.radius,a,s);return{distance:i.distance,onA:i.onPart,onB:i.onWheel}}if(n.kind==="hull"&&o.kind==="rim"){let a=TP(n.points,n.radius,o.bands,o.frame);return{distance:a.distance,onA:a.onPart,onB:a.onWheel}}if(n.kind==="link"&&o.kind==="hull"){let[a,s]=mu(n.a,n.b,e.trim[0],e.trim[1]);return KP({part:n,p0:a,p1:s},{shape:Va(o.points),pad:o.radius,radius:o.radius},r)}return null}function Ba(e,t,r,n=!1){let o=e<=0;return{distance:o?0:e,onA:t,onB:o?t:r,...o?{touches:!0}:{},...n?{mounted:!0}:{}}}var SK=(e,t)=>e.joints.filter(r=>t.joints.some(n=>n.key===r.key)).map(r=>({c:r.p,r:2*r.reach})),kR=(e,t)=>t.map(r=>({c:Vt(e.inverse,r.c),r:r.r}));function AK(e,t,r){let{a:n,b:o}=e,a=(s,i)=>Vt(s.iso,i);if(n.kind==="model"&&o.kind==="link"){let[s,i]=mu(o.a,o.b,e.trim[2],e.trim[3]),c=kR(n,[0,1].filter(m=>e.trim[2+m]>0).map(m=>({c:m===0?o.a:o.b,r:e.trim[2+m]+o.radius}))),l=Vt(n.inverse,s),u=Vt(n.inverse,i),d=wr(ft(u,l));if(!o.flat||d<1e-9){let m=cu(n.tree,l,u,r+o.radius,c);if(!m)return null;let f=m.distance>1e-9?xn(m.onPart,m.onMesh,o.radius):m.onPart;return Ba(m.distance-o.radius,a(n,m.onMesh),a(n,f))}let p=Rf(n.tree,br(l,u,.5),ft(u,l),o.radius,d,Math.max(0,r),c);return p&&Ba(p.distance,a(n,p.onMesh),a(n,p.onPart))}if(n.kind==="model"&&o.kind==="model"){let s=bR(n.tree,o.tree,su(n.inverse,o.iso),Math.max(0,r),kR(n,SK(n,o)));return s&&Ba(s.distance,a(n,s.onA),a(n,s.onB))}if(n.kind==="model"&&(o.kind==="rim"||o.kind==="tyre"&&o.section)){let s=o.kind==="rim"?o.bands:o.section,i=o.kind==="rim"?o.frame:{centre:o.centre,axis:o.axis},c={centre:Vt(n.inverse,i.centre),axis:uf(n.inverse,kf(i.axis))},l=IP(n.tree,c,s,Math.max(0,r));return l&&Ba(l.distance,a(n,l.onMesh),a(n,l.onPart))}if(n.kind==="model"&&o.kind==="hull"){let s=kR(n,n.joints.filter(l=>l.on==="upright").map(l=>({c:l.p,r:l.reach}))),i=hR(n.tree,Va(o.points.map(l=>Vt(n.inverse,l))),r+o.radius,s);if(!i)return null;let c=i.distance>1e-9?xn(i.onPart,i.onMesh,o.radius):i.onPart;return Ba(i.distance-o.radius,a(n,i.onMesh),a(n,c))}if(n.kind==="volume"&&o.kind==="model"){let{min:s,max:i}=n.box,c=[];for(let u=0;u<8;u++)c.push(Vt(o.inverse,[u&1?i[0]:s[0],u&2?i[1]:s[1],u&4?i[2]:s[2]]));let l=hR(o.tree,Va(c),Math.max(0,r));return l&&Ba(l.distance,a(o,l.onPart),a(o,l.onMesh))}if(n.kind==="mesh"&&o.kind==="model"){let s=o.joints.filter(l=>l.on==="chassis"),i=s.some(l=>fR(n.tree,l.p,t.mountAllowance)),c=bR(n.tree,o.tree,o.iso,Math.max(0,r),s.map(l=>({c:l.p,r:2*l.reach})));return c&&Ba(c.distance,c.onA,c.onB,i)}return null}var qP=152,QP={travelSteps:9,rackSteps:5};function CK(e){let t=(r,n)=>{let o=vr(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 wR(e,t){let r=Dm(t);return{...cP,tyreRadius:CK(e),tyreWidth:r!==null?r*1e3:qP}}var UP={front:["FL","FR"],rear:["RL","RR"]},FK=e=>e.a.kind!=="volume"&&e.a.kind!=="mesh"&&(e.b.kind==="tyre"||e.b.kind==="rim"||e.b.kind==="hull");function TK(e,t,r,n,o){let a=null,s=(i,c)=>{for(let l of YP(zP(i,r,n,o),[])){if(l.skip||!FK(l)||!!l.fixed!==c)continue;let u=jP(l,o,a?.distance??1/0);u&&(!a||u.distance<a.distance)&&(a={distance:u.distance,pair:l.name})}};s(e,!0);for(let i of t)s(i,!1);return a}var XP=(e,t,r)=>r<=1||t===e?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function CR(e,t,r,n,o=QP,a={}){let s=e.vehicle,[i]=UP[t],c=Rd(e,i,0,0)?.geometry;if(!c)return null;let l=cf(s.chassis?.boxes??[],{vehicle:s,kc:e.kc}),u=t==="front"?It(s.front.config):0,d=u>0?XP(-u,u,Math.max(3,o.rackSteps|1)):[0],p=XP(Math.min(0,r.min),Math.max(0,r.max),Math.max(2,o.travelSteps)),m=[];for(let v of l.length?UP[t]:[i])for(let k of p)for(let R of d){let M=Rd(e,v,k,R)?.geometry;M&&m.push({corner:v,travel:k,rack:R,g:M})}let f=null;if(l.length){for(let v of pP(l,m,wR(e,n)))for(let k of[v.tyre,v.link])k&&(!f||k.distance<f.distance)&&(f={distance:k.distance,part:k.part,boxId:v.boxId});f??={distance:NaN,part:"",boxId:""}}let h=s[t].config,b=m.filter(v=>v.corner===i).map(v=>v.g),g=sf(c,b,h.pushrodAttach,h.rodType==="pull"?"pullrod":"pushrod"),y=tP({...wR(e,n),jointAllowance:HP},s,{...a,tyres:{front:n,rear:n}}),x=y.axles[t].rim?TK(c,b,i,h.pushrodAttach,y):null;return{chassis:f,wheel:x,...g}}var Ga=Math.PI/180,Si={travelSteps:9,heaveSteps:5,rollSteps:4,rackSteps:6},du={travelMin:-25,travelMax:25,rollMaxDeg:3,rollAtLimitDeg:2.5};function PK(e){let t=e.params,r=t.cg_height?jt({...t,surveyedRadiusFront:e.vehicle.front.config.loadedRadius,surveyedRadiusRear:e.vehicle.rear.config.loadedRadius}):null;return{cgHeight:r?r.cgHeight:300,...Wg(t),drive:Um(t),...r?{frontMassFrac:r.frontMassFrac}:{}}}function FR(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 TR(e,t=Si,r=du,n){let o=null,a=(D,I)=>(o||(o={violation:D,reason:I}),null),s=e.vehicle,i=D=>D==="front"?s.front:s.rear,c=null,l=null,u=()=>{if(c)return c;if(n)try{let D=n();if(D)return c=pr(s,D.kc),l=D.cgHeight,c}catch{a(500,"the car could not be stood on its tyre: its rates did not assemble")}return c=pr(s)},d=D=>D==="front"?"FL":"RL",p=D=>{let I=u();if(!I.kc)return;let V=i(D).config.loadedRadius,O=vr(V,I.kc,d(D));return O===V?void 0:{loadedRadius:O}},m=(D,I)=>-sc(u(),d(D),I),f=new Map,h=new Map,b=new Map,g=new Map,y=new Map,x=new Map,v,k=new Map,R=new Map,M=new Map,S=new Map,w=new Map,F=null,T=()=>{if(F)return F;u();let D=PK(e);return F=l!==null&&Number.isFinite(l)?{...D,cgHeight:l}:D},A,C=()=>{let D=Zx(r.travelMin,r.travelMax,s.config.wheelbase),I=2*Math.max(2,t.rollSteps)-1;return Array.from({length:I},(V,O)=>-D+2*D*O/(I-1))},P,L=()=>{if(P!==void 0)return P;let D=mm(u().ctx.FL,It(s.front.config));return P=D?dm(D):null,P},E=(D,I,V)=>{if(D.has(I))return D.get(I)??null;let O=V();return D.set(I,O),O};return{car:e,density:t,envelope:r,get failure(){return o},axisLength:(D,I)=>{let V=i(D),O=V.hardpoints;return I==="uca"&&V.config.layout==="mcpherson"?NaN:I==="uca"?Pe(O.ucaFront,O.ucaRear):Pe(O.lcaFront,O.lcaRear)},linkLength:D=>{let I=i(D).hardpoints;return Pe(I.tieInner,I.tieOuter)},compliance:D=>E(h,D,()=>Ub(i(D))??null),sweep:D=>E(f,D,()=>{let I;try{I=ct(i(D),{travelMin:r.travelMin,travelMax:r.travelMax,steps:t.travelSteps})}catch{return a(500,`the ${D} travel sweep threw`)}if(!I.covered){let O=I.samples.map(j=>j.travel),B=Math.max(...O)-Math.min(...O),z=r.travelMax-r.travelMin;return a(Math.max(0,z-B),`the ${D} linkage reaches only ${B.toFixed(0)} mm of the ${z.toFixed(0)} mm travel range`)}if(I.fold)return a(200,`the ${D} travel(beta) folds \u2014 the suspension goes over centre in range`);let V=I.samples.filter(O=>!O.converged).length;if(V>0)return a(100+10*V,`${V} of ${I.samples.length} ${D} travel solves did not converge`);if(D==="front"&&i("front").config.steerMode==="rack"){let O=L();if(O)return a(O.violation,O.reason)}return I}),rcHeave:D=>E(b,D,()=>{let I=[],V=[],O=Math.max(2,t.heaveSteps);try{for(let z=0;z<O;z++){let j=r.travelMin+(r.travelMax-r.travelMin)*z/(O-1);I.push(j),V.push($r(u(),{heave:m(D,j),pitch:0,roll:0,steer:0},D))}}catch{return a(500,`the ${D} roll-centre construction threw in heave`)}let B=FR(V,z=>Math.abs(I[z]-I[z-1]));return B>0?a(300,`the ${D} roll-centre construction lands on another branch at ${I[B].toFixed(0)} mm of travel`):{at:I,rc:V}}),rcRoll:D=>E(g,D,()=>{let I=[],V=[],O=Math.max(2,t.rollSteps);try{for(let z=0;z<O;z++){let j=r.rollMaxDeg*z/(O-1);I.push(j),V.push($r(u(),{heave:0,pitch:0,roll:j*Ga,steer:0},D))}}catch{return a(500,`the ${D} roll-centre construction threw in roll`)}let B=FR(V,z=>Math.abs(V[z].cpLeft?.[0]??0)*Math.abs(I[z]-I[z-1])*Ga);return B>0?a(300,`the ${D} roll-centre construction lands on another branch at ${I[B].toFixed(1)}\xB0 of roll`):{at:I,rc:V}}),rcPitch:D=>E(y,D,()=>{let I=C(),V=[];try{for(let B of I)V.push($r(u(),{heave:0,pitch:-B*Ga,roll:0,steer:0},D))}catch{return a(500,`the ${D} roll-centre construction threw in pitch`)}let O=FR(V,B=>Math.abs(I[B]-I[B-1])*Ga*s.config.wheelbase);return O>0?a(300,`the ${D} roll-centre construction lands on another branch at ${I[O].toFixed(2)}\xB0 of pitch`):{at:I,rc:V}}),pcHeave:()=>E(x,"heave",()=>{let D=[],I=[],V=Math.max(2,t.heaveSteps);try{for(let O=0;O<V;O++){let B=r.travelMin+(r.travelMax-r.travelMin)*O/(V-1);D.push(B);let z={heave:m("front",B),pitch:0,roll:0,steer:0},j={heave:m("rear",B),pitch:0,roll:0,steer:0},$=u();I.push({left:to(Tt($,"FL",z),Tt($,"RL",j)),right:to(Tt($,"FR",z),Tt($,"RR",j))})}}catch{return a(500,"the pitch-centre construction threw in heave")}return{at:D,pc:I}}),pcPitch:()=>E(x,"pitch",()=>{let D=C(),I=[];try{for(let V of D){let O={heave:0,pitch:-V*Ga,roll:0,steer:0},B=u();I.push({left:to(Tt(B,"FL",O),Tt(B,"RL",O)),right:to(Tt(B,"FR",O),Tt(B,"RR",O))})}}catch{return a(500,"the pitch-centre construction threw in pitch")}return{at:D,pc:I}}),cg:()=>{if(v!==void 0)return v;let D=T();if(D.frontMassFrac===void 0||!Number.isFinite(D.frontMassFrac))return v=null;let I=s.config,V=rf({wheelbase:I.wheelbase,frontAxleX:I.frontAxleX,frontMassFrac:D.frontMassFrac,cgHeight:D.cgHeight});return v={...V,z:Kr(D.cgHeight,V.x,u())}},roadUnder:D=>{let I=k.get(D);return I===void 0&&(I=Kr(0,ze(d(D),s.config).axleX,u()),k.set(D,I)),I},steer:()=>{if(A!==void 0)return A;try{A=Tb(u(),{steerMax:It(s.front.config),steps:t.rackSteps})}catch{A=a(500,"the steering sweep threw")}let D=A?.filter(I=>!I.converged).length??0;if(A&&D>0){let I=L();A=I?a(I.violation,I.reason):a(100+10*D,`${D} of ${A.length} steering solves did not converge`)}return A??null},solveAt:(D,I,V=0)=>E(R,`${D}:${I}:${V}`,()=>{try{let O=Ae(u().ctx[d(D)],I,V,void 0,p(D));return O.ok?O.state:O.why==="unconverged"?a(100,`the ${D} corner did not solve at ${I.toFixed(0)} mm of travel`):a(100+Math.abs(O.travelMiss),`the ${D} corner reaches only ${(I+O.travelMiss).toFixed(0)} of ${I.toFixed(0)} mm of travel`)}catch{return a(150,`the ${D} corner solve threw at ${I.toFixed(0)} mm of travel`)}}),readout:D=>E(S,`${D.heave}:${D.pitch}:${D.roll}:${D.steer}`,()=>{try{return Jx(u(),D,T())}catch{return a(500,"the derived readout threw")}}),readoutAtTravel:(D,I)=>E(w,`${D}:${I}`,()=>{try{return nu(u(),{heave:m(D,I),pitch:0,roll:0,steer:0},D,T())}catch{return a(500,`the ${D} readout threw at ${I.toFixed(0)} mm of travel`)}}),travelAtRoll:(D,I)=>{let V=i(D).hardpoints.wheelCenter[1]*Math.sin(I*Ga),O=u();if(!O.kc)return V;try{let B=Qt(O,{heave:0,pitch:0,roll:I*Ga,steer:0}),z=D==="front"?Math.max(B.FL.travel,B.FR.travel):Math.max(B.RL.travel,B.RR.travel);return Number.isFinite(z)?z:V}catch{return a(500,`the ${D} axle could not be rolled on its tyre`),V}},onTyre:()=>!!u().kc,contexts:u,keepOuts:D=>E(M,D,()=>{try{let I=e.params,V=D==="front"?I.tireModel:I.tireModelRear??I.tireModel,O={min:r.travelMin,max:r.travelMax},B={brakes:I.brakeModel,dampers:{front:I.damperModel,rear:I.damperModelRear??I.damperModel},drive:eP(Um(I))};return CR(u(),D,O,V,void 0,B)??a(100,`the ${D} corner did not solve at its design ride`)}catch{return a(500,`the ${D} keep-outs threw`)}})}}var LK=Hy();function PR(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=yp(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,d=a.track?Bl([c],a.track,a.numerics,Il(s),a.settings,LK)[0]:Al(c,s,{numerics:a.numerics,standingStart:l,lapCounts:u});o={};for(let p of s.metrics)Du(p)&&(o[p.key]=p.value(d,void 0))}}catch{o=null}return r.set(n,o),o}}}var Mf=.01;function DK(e,t){return t.bump!==null&&e>t.bump-Mf?{at:"closed",past:Math.max(0,e-t.bump)}:t.droopStated&&e<t.droop+Mf?{at:"toppedOut",past:Math.max(0,t.droop-e)}:t.seat!==null&&e<t.seat+Mf?{at:"unseated",past:Math.max(0,t.seat-e)}:{at:"free",past:0}}var ZP=e=>({droop:e.droop,droopStated:e.droopStated,bump:e.bump,seat:e.holdsLoad&&Number.isFinite(e.free)?e.free:null}),EK=[["front","FL","FR"],["rear","RL","RR"]];function DR(e,t){let r=[];for(let[n,o,a]of EK){let s=[t[o],t[a]];for(let d of[o,a]){let p=e.curve[d],m=p.spring?.law;if(!p.spring||!m)continue;let f=lb(p,t[d]);f===null||!Number.isFinite(f)||r.push(LR(d,n,n,f,p.spring.length0-f,ZP(m),!0))}let i=e.elements?.[n];if(!i)continue;let c=i.heave?.law;if(c){let d=Pk(i,s),p=i.read.heave?.span0,m=n==="front"?"heaveFront":"heaveRear";r.push(LR(m,m,n,d,p!==void 0?p-d:null,ZP(c),i.carriesLoad))}let l=i.rollStop,u=l?Lk(i,s):null;if(l&&u!==null){let d=l.length0-u,p=n==="front"?"rollFront":"rollRear",m={droop:l.droop??-1/0,droopStated:l.droop!==null,bump:l.bump,seat:null};r.push(LR(p,p,n,d,u,m,i.carriesLoad))}}return r}function LR(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,...DK(n,a),bumpStated:a.bump!==null,bounds:s}}var tL=Math.PI/180;function ER(e,t,r,n){let o=t.speedKmh/3.6,a=Yh(e,o,t.axG,po(e,t.ayG,0));if(!a||!e.aero)return null;let s=e.wheelbase,i=ms(e.aero,s),c=(h,b)=>Math.atan((b-h)/s)/tL,l={},u={};for(let h of Zr)l[h]=r.corners[h].travel,u[h]=r.corners[h].ground;let d=n.kc?DR(n.kc,l):[],p=e.aero.model,m=a.downFront+a.downRear,f=p?{balance:Math.abs(m)>1e-9?100*a.downFront/m:NaN,clA:(a.clFront+a.clRear)*a.area,cdA:a.cd*a.area,loopMargin:1-a.gain,dataMargin:rL(p,s,a.hFront,a.hRear)}:null;return{front:{height:a.hFront,...JP(d,"front")},rear:{height:a.hRear,...JP(d,"rear")},rakeDeg:c(a.hFront,a.hRear),pitchDeg:c(a.hFront,a.hRear)-c(i.hFront,i.hRear),rollDeg:Math.abs(r.rollDeg),aero:f,clearance:IK(n,u)}}function JP(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 rL(e,t,r,n){let o=(a,[s,i])=>Math.min(a-s,i-a);if(Sv(e)){let{x:a,y:s}=is(e),i=[a[0],a[a.length-1]],c=[s[0],s[s.length-1]];return uo(e)?eL(e.frame,t,i,c,r,n):Math.min(o(r,i),o(n,c))}return Vu(e)?eL(e.frame,t,e.range.h,e.range.pitch,r,n):Math.min(o(r,e.range.hFront),o(n,e.range.hRear))}function eL(e,t,r,n,o,a){let s=cs(e,t,o,a),i=l=>t*Math.tan(l*tL),c=a-o;return Math.min(s.h-r[0],r[1]-s.h,c-i(n[0]),i(n[1])-c)}function IK(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=ir(e.vehicle,!0)/2,c=ir(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]],d=[0,0,0];for(let b of Zr){let g=[1,l[b][0],l[b][1]];for(let y=0;y<3;y++){d[y]+=g[y]*t[b];for(let x=0;x<3;x++)u[y][x]+=g[y]*g[x]}}let p=dP(u,d);if(!p)return null;let m=lP(n),f={z0:m.z0+p[0],dzdx:m.dzdx+p[1],dzdy:m.dzdy+p[2]},h=null;for(let b of cf(r,n)){let g=mP(b,f);(!h||g.height<h.height)&&(h={height:g.height,volume:b.name})}return h}function Sf(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 _K={front:"front",rear:"rear",heaveFront:"front",heaveRear:"rear",rollFront:"front",rollRear:"rear"};function pu(e,t,r,n){let o=Pd(e,t);return yd.some(s=>{if(_K[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 IR(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 Af=Math.PI/180,wf=1e-6;function oL(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 fu(e){let t=e.measured;if(t)return oL(t.travel,t.camber);let r=te(e.config.spinAxis);return-Math.asin(Math.max(-1,Math.min(1,r[2])))/Af}function hu(e){let t=e.measured;if(t)return oL(t.travel,t.toe);let[r,n]=e.config.spinAxis;return Math.atan2(r,n)/Af}function _R(e,t){let r=Math.abs(t.camber)>=wf,n=Math.abs(t.toe)>=wf;if(!r&&!n)return e;let o=e.measured;if(o)return{...e,measured:{...o,...r?{camber:o.camber.map(m=>m+t.camber)}:{},...n?{toe:o.toe.map(m=>m+t.toe)}:{}}};let[a,s]=e.config.spinAxis,i=Math.hypot(a,s);if(!(i>0))return e;let c=(fu(e)+t.camber)*Af,l=(hu(e)+t.toe)*Af,[u,d]=n?[Math.sin(l),Math.cos(l)]:[a/i,s/i],p=[u*Math.cos(c),d*Math.cos(c),-Math.sin(c)];return{...e,config:{...e.config,spinAxis:p}}}function Cf(e){let t=e&&typeof e=="object"?e.value:void 0;return typeof t=="number"&&Number.isFinite(t)?t:void 0}function NK(e,t){let r=t;return{front:Cf(r.camber_front_deg)??fu(e.front),rear:Cf(r.camber_rear_deg)??fu(e.rear)}}function OK(e,t){let r=t;return{front:Cf(r.toe_front_deg)??hu(e.front),rear:Cf(r.toe_rear_deg)??hu(e.rear)}}function VK(e){return{camber:{front:fu(e.front),rear:fu(e.rear)},toe:{front:hu(e.front),rear:hu(e.rear)}}}var nL=new WeakMap;function BK(e,t){let r=VK(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)<wf&&Math.abs(u.toe)<wf;if(o(n.front)&&o(n.rear))return e;let a=`${t.camber.front}|${t.camber.rear}|${t.toe.front}|${t.toe.rear}`,s=nL.get(e),i=s?.get(a);if(i)return i;let c=e.corners?Object.fromEntries(Object.entries(e.corners).map(([u,d])=>[u,d&&_R(d,n[fs(u)])])):void 0,l={...e,front:_R(e.front,n.front),rear:_R(e.rear,n.rear),...c?{corners:c}:{}};return s||nL.set(e,s=new Map),s.size>=16&&s.clear(),s.set(a,l),l}function Ai(e,t){return t?BK(e,{camber:NK(e,t),toe:OK(e,t)}):e}var $K=9.81;function wi(e){let t=Wo(e),r=Math.max(0,e.unsprungPerCorner)*$K,n=a=>{let s=a==="FL"||a==="FR",i=s?"front":"rear",c=yt(e,i),l=c>0?c:1/0,u=Ah(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:Mr(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 d=!i&&!!l&&(l.gap>0||!l.bothWays);(s?.heave||s?.roll||i||d)&&(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 aL=new WeakMap;function GK(e){let t=Ai(e.vehicle,e.params);if(t===e.vehicle)return e;let r=aL.get(e);return(!r||r.vehicle!==t)&&aL.set(e,r={...e,vehicle:t}),r}function Lo(e,t={}){let r=GK(e),n=Vx(r,t),o=t.assemble?()=>{let d=n.dynInput();if(!d)throw new Error("the car did not assemble");return{kc:wi(d),cgHeight:d.cgHeight}}:void 0,a=TR(r,t.density,t.envelope,o),s=zx(r,n,t),i=PR(r,t),c=t.states??[],l=new Map;return{...a,...n,...s,...i,get failure(){return a.failure},values:new Map,states:c,stateOf:d=>d===void 0?c[0]??null:c.find(p=>p.id===d)??null,platformAt:d=>{let p=`${d.speedKmh}|${d.ayG}|${d.axG}`,m=l.get(p);if(m!==void 0)return m;let f=n.poseAt(d),h=n.dynInput(),b=null;if(f&&h)try{b=ER(h,d,f,a.contexts())}catch{b=null}return l.set(p,b),b}}}var KK=["x","y","z"],HK=/^(line|plane)\((-?\d+),(-?\d+)\)([uv]?)$/,sL=Math.PI/18e3,iL=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],cL=(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]],zK=e=>Math.hypot(e[0],e[1],e[2]),NR=(e,t)=>[e[0]*t,e[1]*t,e[2]*t];function OR(e){let t=zK(e);return t>1e-9?NR(e,1/t):null}function YK(e,t){let r=e*sL,n=t*sL;return[Math.cos(n)*Math.cos(r),Math.cos(n)*Math.sin(r),Math.sin(n)]}function Cr(e){let t=e.lastIndexOf(".");if(t<0)return null;let r=HK.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:YK(Number(r[2]),Number(r[3]))},coord:n==="line"?"along":r[4]}}function lL(e){let t=OR(cL([0,0,1],e))??[1,0,0];(t[0]<-1e-9||Math.abs(t[0])<=1e-9&&t[1]<0)&&(t=NR(t,-1));let r=OR(cL(e,t))??[0,1,0];return(r[2]<-1e-9||Math.abs(r[2])<=1e-9&&r[1]<0)&&(r=NR(r,-1)),[t,r]}function VR(e){if(e.coord==="along")return e.shape.dir;let[t,r]=lL(e.shape.dir);return e.coord==="u"?t:r}function uL(e,t){let r=Cr(t);if(!r)return;let n=KK.map(u=>e[`${r.point}.${u}`]);if(n.some(u=>!u))return;let o=VR(r),a=[0,1,2].filter(u=>Math.abs(o[u])>1e-12),s=u=>n.map(d=>d.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=>iL(s(u),o),write:(u,d)=>{let p=s(u),m=d-iL(p,o),f=u;for(let h of a)f=n[h].write(f,p[h]+m*o[h]);return f},...c?{supersededBy:c}:{}}}var Ci=["x","y","z"];var WK=/^(?:hp\.(?:front|rear)\.\w+|(?:heave|roll)\.(?:front|rear)\.(?:outer|inner|anchor))$/;function Ka(e){let t=e.lastIndexOf("."),r=e.slice(0,t);if(t<0||!WK.test(r))return null;let n=e.slice(t+1);if(n==="x"||n==="y"||n==="z")return{point:r,axis:n};let o=Cr(e);return o?{point:r,axis:o.coord}:null}var bu="*";function BR(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 $R=e=>e?.reads==="speed"||e?.reads==="operating",GR=e=>e?.reads==="lateral"||e?.reads==="operating";function Ha(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 Ff(e,t){return e?.appliesAt?t.find(r=>!e.appliesAt(r)):t[0]}function Fi(e,t,r){let n=r?.stateId?e.stateOf(r.stateId):Ff(t,e.states)??null;return n&&!t.appliesAt?.(n)?n:null}function Rt(e,t,r){let n=`${t.id}@${Ha(r)}`,o=e.values.get(n);if(o!==void 0)return o;let a;try{a=r?.courseId===bu&&t.reads==="course"?jK(e,t,r):r?.stateId===gn&&t.reads==="state"?UK(e,t,r):t.read(e,r)}catch{a=NaN}return e.values.set(n,a),a}function jK(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:Rt(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 UK(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:Rt(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 KR(e){let t={mean:"weighted mean",max:"highest",min:"lowest",span:"span"};return e?.acrossStates?`every state, ${t[e.acrossStates]}`:"every state"}function ht(e){return`${e.quantity??e.groupShort??e.group} \xB7 ${e.label}`}var XK={front:"Front",rear:"Rear"},za={heave:0,pitch:0,roll:0,steer:0},mL="RC height (chassis) [mm]";function dL(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 RL(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 Rn=e=>e.length?Math.max(...e)-Math.min(...e):NaN;function pL(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 fL(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 Pi(e,t,r){let n=e.stateOf(t?.stateId),o=n?e.poseAt(n):null;return o?r(o):NaN}var gu=(e,t)=>`${e==="front"?"F":"R"}${t}`,hL=e=>e==="L"?"R":"L";function bL(e){let t=XK[e],r=R=>`kin.${e}.${R}`,n=(R,M)=>{let S=R.sweep(e);return S?{x:S.samples.map(w=>w.travel),y:S.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 d(R){let M=s(R);return M&&M.design.kind!=="none"?null:`${i} has no roll element`}function p(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 m=R=>{if(u(R.car))return null;let M=R.sweep(e);return M?fb(o(R.car),a(R.car).linkage,M.samples):null},f=R=>{if(p(R.car))return null;let M=R.sweep(e);if(!M)return null;let S=s(R.car),w=mb(o(R.car),S.linkage,S.design.kind,M.samples),F=w.atDesign<0?-1:1;return{travel:w.travel,ratio:w.ratio.map(T=>T*F),atDesign:w.atDesign*F}},h=R=>R.readout(za)?.[e],b=R=>R.readoutAtTravel(e,R.envelope.travelMax),g=R=>{let M=n(R,S=>S.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,S=>S.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?RL(M.at,M.rc.map(S=>S.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:mL,x:M.at,y:M.rc.map(S=>S.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?Rn(M.rc.map(S=>S.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:mL,x:M.at,y:M.rc.map(S=>S.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?Rn(M.rc.map(S=>S.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(S=>S.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),S=R.rcRoll(e);return!M||!S?NaN:Math.min(...M.rc.map(w=>w.sinAngle),...S.rc.map(w=>w.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(S=>S.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=>h(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=>h(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=>h(R)?.rollCamber??NaN},{id:r("rollCamberRecovery"),group:`${t} camber & toe`,label:"camber recovery in roll",unit:"%",scale:20,scope:e,cost:"readout",read:R=>h(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=>h(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=>h(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,S=>S.metrics.toe);return M.x.length?dL(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,S=>S.metrics.camber);return M.x.length?dL(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=>Rn(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=>Rn(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)),S=R.solveAt(e,0);return!M||!S?NaN:Math.abs(M.metrics.camber-S.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)=>Pi(R,M,S=>S.camber[gu(e,S.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)=>Pi(R,M,S=>S.camber[gu(e,hL(S.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)=>Pi(R,M,S=>S.corners[gu(e,S.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=>h(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=>h(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=>h(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=>h(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?fL(M.samples.map(S=>S.travel),M.samples.map(S=>S.metrics.motionRatio??NaN))??NaN:NaN},curve:R=>{if(c(R.car))return null;let M=n(R,S=>S.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 S=M.samples.map(F=>F.metrics.motionRatio??NaN).filter(Number.isFinite);if(!S.length)return NaN;let w=S.reduce((F,T)=>F+T,0)/S.length;return w>0?(Math.max(...S)-Math.min(...S))/w:NaN}},{id:r("wheelRate"),group:`${t} rates`,label:"wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:c,read:R=>{if(c(R.car))return NaN;let M=R.sweep(e);return M?fL(M.samples.map(S=>S.travel),M.samples.map(S=>S.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=>m(R)?.atDesign??NaN,curve:R=>{let M=m(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=>pL(m(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:qs(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:p,read:R=>f(R)?.atDesign??NaN,curve:R=>{let M=f(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:p,read:R=>pL(f(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:d,read:R=>d(R.car)||!R.sweep(e)?NaN:da(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(za)?.[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)=>Pi(R,M,S=>S.corners[gu(e,S.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)=>Pi(R,M,S=>S.corners[gu(e,hL(S.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:Rn(n(R,M=>M.metrics.damperLength).y),curve:R=>{if(c(R.car))return null;let M=n(R,S=>S.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=>h(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=>h(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(za)?.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(za)?.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(za)?.rear.antiLift??NaN});let v=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 ${v(R.group)}`}))}function gL(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 qK=[{id:"kin.front.ackermannCentre",group:"Steering",label:"Ackermann near centre",unit:"%",scale:25,scope:"front",cost:"cheap",read:e=>gL(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=>gL(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}}],QK=[{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)=>Pi(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}}],Ti=(e,t)=>e.left.valid&&e.right.valid?(t(e.left)+t(e.right))/2:NaN,HR=(e,t)=>{let r=e.readout(za)?.axes?.pitch;return r?.valid?t(r):NaN},yL=(e,t)=>{let r=e.readout(za)?.axes?.roll;return r?.usable?t(r):NaN},ZK=e=>(e.roadUnder("front")+e.roadUnder("rear"))/2;function xL(e){let t=e.rcRoll("front"),r=e.rcRoll("rear"),n=e.cg();if(!t||!r||!n)return null;let o=e.car.vehicle.config,a=t.rc.map((s,i)=>KT({front:s,rear:r.rc[i]},n,o.frontAxleX,o.wheelbase,()=>!0).arm);return{at:t.at,arm:a}}var JK="PC height (chassis) [mm]",eH=[{id:"kin.car.pcHeight",group:"Pitch axis",label:"pitch-centre height at design",unit:"mm",scale:30,scope:"car",cost:"readout",read:e=>HR(e,t=>t.heightAboveGround)},{id:"kin.car.pcAhead",group:"Pitch axis",label:"pitch centre ahead of the CG at design",unit:"mm",scale:300,scope:"car",cost:"readout",read:e=>HR(e,t=>t.ahead)},{id:"kin.car.pitchArm",group:"Pitch axis",label:"pitch arm at design",unit:"mm",scale:30,scope:"car",cost:"readout",read:e=>HR(e,t=>t.arm)},{id:"kin.car.pcHeaveWorst",group:"Pitch axis",label:"worst height migration vs travel",unit:"mm/mm",scale:.5,scope:"car",cost:"cheap",read:e=>{let t=e.pcHeave();return t?RL(t.at,t.pc.map(r=>Ti(r,n=>n.height))):NaN},curve:e=>{let t=e.pcHeave();if(!t)return null;let r=ZK(e);return{key:"kin.car.pcHeaveWorst",title:"Pitch-centre height vs wheel travel",xLabel:"travel [mm]",yLabel:JK,x:t.at,y:t.pc.map(n=>Ti(n,o=>o.height)-r)}}},{id:"kin.car.pcPitchSpan",group:"Pitch axis",label:"height span over the pitch envelope",unit:"mm",scale:15,scope:"car",cost:"cheap",read:e=>{let t=e.pcPitch();return t?Rn(t.pc.map(r=>Ti(r,n=>n.heightAboveGround))):NaN},curve:e=>{let t=e.pcPitch();return t?{key:"kin.car.pcPitchSpan",title:"Pitch-centre height vs body pitch",xLabel:"pitch [\xB0, + nose down]",yLabel:"PC height above road [mm]",x:t.at,y:t.pc.map(r=>Ti(r,n=>n.heightAboveGround))}:null}},{id:"kin.car.pcAheadSpan",group:"Pitch axis",label:"fore-aft migration over the pitch envelope",unit:"mm",scale:300,scope:"car",cost:"cheap",read:e=>{let t=e.pcPitch();return t?Rn(t.pc.map(r=>Ti(r,n=>n.x))):NaN},curve:e=>{let t=e.pcPitch(),r=e.cg();return!t||!r?null:{key:"kin.car.pcAheadSpan",title:"Pitch centre ahead of the CG vs body pitch",xLabel:"pitch [\xB0, + nose down]",yLabel:"PC ahead of CG [mm]",x:t.at,y:t.pc.map(n=>Ti(n,o=>o.x)-r.x)}}},{id:"kin.car.pcMinSinAngle",group:"Pitch axis",label:"construction conditioning (min sinAngle)",unit:"-",scale:.01,scope:"car",cost:"cheap",read:e=>{let t=e.pcHeave(),r=e.pcPitch();return!t||!r?NaN:Math.min(...[...t.pc,...r.pc].map(n=>Math.min(n.left.sinAngle,n.right.sinAngle)))}},{id:"kin.car.rollArm",group:"Roll axis",label:"roll arm at design",unit:"mm",scale:30,scope:"car",cost:"readout",read:e=>yL(e,t=>t.arm)},{id:"kin.car.rollAxisSlope",group:"Roll axis",label:"slope at design (+ rising rearward)",unit:"\xB0",scale:.5,scope:"car",cost:"readout",read:e=>yL(e,t=>t.slope)},{id:"kin.car.rollArmSpan",group:"Roll axis",label:"roll-arm span over the roll envelope",unit:"mm",scale:15,scope:"car",cost:"cheap",read:e=>{let t=xL(e);return t?Rn(t.arm):NaN},curve:e=>{let t=xL(e);return t?{key:"kin.car.rollArmSpan",title:"Roll arm vs body roll",xLabel:"roll [\xB0]",yLabel:"roll arm [mm]",x:t.at,y:t.arm}:null}}],zR=[...bL("front"),...bL("rear"),...qK,...QK,...eH];var tH={front:"Front",rear:"Rear"};function ML(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 rH(e,t,r){let n=r==="front"?t.tireModel:t.tireModelRear??t.tireModel;return tR(e.parts?.[r],n)?null:`The ${r} axle states no rim, so its tyre and rim are not measured; state one under Kinematics \u203A Linkage \u203A Wheel`}function vL(e,t,r){let n=e.parts?.[t]?.jointLimits?.[r];return rR(n)?n:void 0}function kL(e){let t=tH[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=>ML(s.vehicle),read:s=>o(s,i=>i.chassis?.distance)},{...a,id:r("wheelClearance"),label:`least clearance inside the wheel ${n}`,unit:"mm",scale:5,unavailable:s=>rH(s.vehicle,s.params,e),read:s=>o(s,i=>i.wheel?.distance)},{...a,id:r("ballJointAngle"),label:`largest ball-joint angle ${n}`,unit:"\xB0",scale:1,read:s=>o(s,i=>i.ballJoint?.angle),statedLimit:s=>vL(s.vehicle,e,"ballJoint")},{...a,id:r("rodEndAngle"),label:`largest rod-end angle ${n}`,unit:"\xB0",scale:1,read:s=>o(s,i=>i.rodEnd?.angle),statedLimit:s=>vL(s.vehicle,e,"rodEnd")}]}var YR=[...kL("front"),...kL("rear")];var FL={front:"Front",rear:"Rear"},SL=e=>_a("side",e),nH=e=>_a("drive",e)&&_a("brake",e)?"neither brakes nor drives":null;function oH(e,t,r,n){let o=Fi(e,t,r),a=o?e.tyreAt(o):null;return a?n(a):NaN}function Li(e,t){let r={...e,read:(n,o)=>oH(n,r,o,t)};return r}var AL=e=>e?100*e.lossCamber:NaN,wL=e=>e&&!e.lifted?e.camber-e.wants:NaN;function CL(e){let t=FL[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:SL,unavailable:s=>Wp(s.params,e)},a=[Li({...o,id:r("camberErrorOuter"),label:"camber error at the outer wheel",unit:"\xB0",scale:.5},s=>wL(s.side(e)?.wheels[0])),Li({...o,id:r("camberErrorInner"),label:"camber error at the inner wheel",unit:"\xB0",scale:.5},s=>wL(s.side(e)?.wheels[1])),Li({...o,id:r("sideLossCamber"),label:"side grip lost to camber",unit:"%",scale:1},s=>AL(s.side(e))),Li({...n,appliesAt:SL,id:r("sideLossToe"),label:"side grip lost to the toe split",unit:"%",scale:1},s=>100*s.toeLoss(e)),Li({...n,appliesAt:nH,unavailable:s=>Nx(s.params,e),id:r("longLossCamber"),label:"drive and brake grip lost to camber",unit:"%",scale:1},s=>AL(s.long(e)))];return e==="front"&&a.push(Li({...n,appliesAt:s=>_a("ackermann",s),id:r("ackermannError"),label:"Ackermann against the tyre",unit:"%",scale:25},s=>s.ackermann())),a}var WR=[...CL("front"),...CL("rear")],aH=/^tyre\.(front|rear)\.(camberErrorOuter|camberErrorInner|sideLossCamber|longLossCamber)$/;function jR(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=aH.exec(a.id);if(!i)continue;let c=i[1],l=i[2]==="longLossCamber",u=s?.stateId==="*"?e.states.filter(d=>!a.appliesAt?.(d)):[Fi(e,a,s)].filter(d=>!!d);for(let d of u){let p=`${c}|${d.id}|${l}`;if(r.has(p))continue;let m=e.tyreAt(d),f=m?l?m.long(c):m.side(c):null;if(!f)continue;let{lo:h,hi:b,stated:g}=f.range,y=g?`the ${o(h)} \u2026 ${o(b)} its data covers`:`the \xB1${b.toFixed(0)}\xB0 read without a stated range`,x=M=>l?M===0?"left":"right":M===0?"outer":"inner",v=f.wheels.findIndex(M=>M.atEdge),k=f.wheels.findIndex(M=>M.outside&&!M.lifted),R=[];v>=0&&R.push(`the ${FL[c].toLowerCase()} ${x(v)} tyre wants ${o(f.wheels[v].wants)}, the edge of ${y}, and may want more`),k>=0&&R.push(`the ${x(k)} wheel has ${o(f.wheels[k].camber)}, past it, and is read at ${o(f.wheels[k].read)}`),R.length&&r.set(p,`In the ${n(d)} ${R.join("; ")}.`)}}return[...r.values()]}function UR(e,t){let r=e.appliesAt?.(t);return r?`is read at ${t.name}, which ${r}`:null}var sH={front:"Front",rear:"Rear"};function iH(e,t,r,n){let o=Fi(e,t,r),a=o?e.platformAt(o):null;return(a?n(a):null)??NaN}function Fr(e,t){let r={...e,read:(n,o)=>iH(n,r,o,t)};return r}var XR={cost:"cheap",reads:"state"},cH={unavailable:e=>Sf(e.params)};function TL(e){let t=sH[e],r=o=>`platform.${e}.${o}`,n={...XR,group:`${t} platform`,quantity:`${t} \xB7 Platform`,scope:e};return[Fr({...n,id:r("rideHeight"),label:"ride height at a state",unit:"mm",scale:5,acrossStates:"min"},o=>o[e].height),Fr({...n,id:r("toBumpStop"),label:"travel left to the bump stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>pu(o.vehicle,o.params,e,"bump")},o=>o[e].toBump),Fr({...n,id:r("toDroopStop"),label:"travel left to the droop stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>pu(o.vehicle,o.params,e,"droop")},o=>o[e].toDroop)]}var Tf={...XR,group:"Platform",scope:"car"},yu={...XR,...cH,group:"Aero platform",groupShort:"Aero",scope:"car"},qR=[...TL("front"),...TL("rear"),Fr({...Tf,id:"platform.rake",label:"rake at a state",unit:"\xB0",scale:.2,acrossStates:"span"},e=>e.rakeDeg),Fr({...Tf,id:"platform.pitch",label:"pitch at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.pitchDeg),Fr({...Tf,id:"platform.roll",label:"body roll at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.rollDeg),Fr({...Tf,id:"platform.groundClearance",label:"ground clearance at a state",unit:"mm",scale:5,acrossStates:"min",unavailable:e=>IR(e.vehicle)},e=>e.clearance?.height),Fr({...yu,id:"platform.balance",label:"balance at a state",unit:"%",scale:1,acrossStates:"span"},e=>e.aero?.balance),Fr({...yu,id:"platform.clA",label:"downforce Cl\xB7A at a state",unit:"m\xB2",scale:.1,acrossStates:"mean"},e=>e.aero?.clA),Fr({...yu,id:"platform.cdA",label:"drag Cd\xB7A at a state",unit:"m\xB2",scale:.05,acrossStates:"mean"},e=>e.aero?.cdA),Fr({...yu,id:"platform.dataMargin",label:"margin to the model\u2019s data",unit:"mm",scale:5,acrossStates:"min"},e=>e.aero?.dataMargin),Fr({...yu,id:"platform.loopMargin",label:"aero-elastic margin, 1 \u2212 loop gain",unit:"-",scale:.1,acrossStates:"min"},e=>e.aero?.loopMargin)];var PL={understeer:"operating",yawFreq:"speed",yawZeta:"speed",yawStiffness:"operating",steeringTorque:"operating",steeringTorqueGradient:"operating"};function Lt(e,t,r,n="cheap"){let o=sy[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,...PL[e]?{reads:PL[e]}:{},read:(a,s)=>{let i=a.dynInput(),c=a.dynCtx(s);return i&&c?o.compute(i,c):NaN}}}function LL(e,t){let r=e.dynInput();if(!r)return null;let n=t("front"),o=t("rear");if(!n||!o||n.rc.length!==o.rc.length)return null;let a=e.roadUnder("front"),s=e.roadUnder("rear"),i=n.rc.map((c,l)=>{let u=Us(c),d=Us(o.rc[l]);if(!u||!d)return NaN;let p=Jk(r,u.height-a,d.height-s);return 100*eM(r,{rcFront:u.heightAboveGround,rcRear:d.heightAboveGround,arm:p})});return{at:n.at,share:i}}function QR(e,t,r,n,o){let a=`dyn.${e}`;return{id:a,group:"Handling \u2014 balance",label:t,unit:"%",scale:1,scope:"car",cost:"cheap",read:s=>{let i=LL(s,o(s));return i?Rn(i.share):NaN},curve:s=>{let i=LL(s,o(s));return i?{key:a,title:r,xLabel:n,yLabel:"TLLTD front [%]",x:i.at,y:i.share}:null}}}var lH=[Lt("understeer","Handling \u2014 balance",.1),Lt("tlltdFront","Handling \u2014 balance",5),QR("tlltdHeaveSpan","TLLTD span over the travel","TLLTD vs wheel travel","travel [mm]",e=>t=>e.rcHeave(t)),QR("tlltdPitchSpan","TLLTD span over the pitch envelope","TLLTD vs body pitch","pitch [\xB0, + nose down]",e=>t=>e.rcPitch(t)),QR("tlltdRollSpan","TLLTD span over the roll envelope","TLLTD vs body roll","roll [\xB0]",e=>t=>e.rcRoll(t)),Lt("rollStiffFront","Handling \u2014 balance",5)],uH=[Lt("yawFreq","Handling \u2014 response",.5),Lt("yawZeta","Handling \u2014 response",.2),Lt("stabilitySpeed","Handling \u2014 response",50),Lt("yawStiffness","Handling \u2014 response",2e4,"trim")],mH=[Lt("steeringTorque","Steering feel",1,"trim"),Lt("steeringTorqueGradient","Steering feel",2,"trim")],dH=[Lt("rollGradient","Ride & body",.5),Lt("pitchGradient","Ride & body",.5),Lt("rideFreqFront","Ride & body",.5),Lt("rideFreqRear","Ride & body",.5),Lt("rollFreq","Ride & body",.5),Lt("pitchFreq","Ride & body",.5),Lt("zetaFront","Ride & body",.2),Lt("zetaRear","Ride & body",.2)],pH=[{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}],fH=[{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}],ZR=[...lH,...uH,...mH,...dH,...pH,...fH];function hH(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 JR=[{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)=>hH(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 bH(e,t){let r=/^(.*?)\s*\(([^)]+)\)\s*$/.exec(e);return r?{label:r[1],unit:r[2]}:{label:e,unit:t?"s":""}}function gH(e){return e==="s"||e==="kWh"?.1:e==="km/h"?2:1}var DL=new WeakMap;function Pf(e){let t=DL.get(e);return t||(t=e.metrics.filter(Du).map(r=>{let{label:n,unit:o}=bH(r.label,r.format==="time");return{id:`event.${e.id}.${r.key}`,group:`Events \xB7 ${e.label}`,groupShort:"Events",label:n,unit:o,scale:gH(o),scope:"car",cost:"session",read:a=>a.session(e.id)?.[r.key]??NaN}}),DL.set(e,t),t)}var e1=li.flatMap(Pf);var Lf=[...zR,...YR,...WR,...qR,...ZR,...JR,...e1],Di=Object.fromEntries(Lf.map(e=>[e.id,e]));var EL={all:Lf,byId:Di},IL=new WeakMap;function gr(e=[]){if(e.length===0)return EL;let t=IL.get(e);if(t)return t;let r=Ey(e).filter(n=>!ui(n.id)).flatMap(Pf);return t=r.length?{all:[...Lf,...r],byId:{...Di,...Object.fromEntries(r.map(n=>[n.id,n]))}}:EL,IL.set(e,t),t}var xH=9.81;function Df(e,t=e.tireModel,r=e.tireModelRear){if(!t)return e;e=RH(e,t,r);let n=e.m.value*xH/4,o=ba(e,t,r),a=Ke(o.front).rollingRadius(n),s=o.rear===o.front?a:Ke(o.rear).rollingRadius(n),i=vH(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 RH(e,t,r){let n=ba(e,t,r),o=Ke(n.front).verticalStiffness(),a=n.rear===n.front?o:Ke(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 ${_L(o)}, rear ${_L(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 _L=e=>Math.round(e*10)/10;function vH(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 xu=180/Math.PI,Ei=Math.PI/180,kH=.2;function Ef(e,t){let r=H(t,e);return te(r[0]<0?jh(r):r)}var If=e=>({side:Math.atan2(e[2],e[0])*xu,plan:Math.atan2(e[1],e[0])*xu}),_f=(e,t)=>te([1,Math.tan(t*Ei),Math.tan(e*Ei)]),Ru=e=>Math.abs(e[0])>=kH,Nf=(e,t)=>Math.atan(t/Math.max(e,1))*xu,Of=(e,t)=>Math.tan(t*Ei)*Math.max(e,1);var Do=["side","plan","clock","len"],yr={uca:{fore:"ucaFront",aft:"ucaRear",ball:"uprightUpper"},lca:{fore:"lcaFront",aft:"lcaRear",ball:"uprightLower"}},vu={uca:"upper arm",lca:"lower arm"},MH=1,NL=(e,t)=>Ef(e[yr[t].fore],e[yr[t].aft]);function OL(e){let t=te(H(Wh,X(e,J(Wh,e))));return{e1:t,e2:le(e,t)}}function t1(e,t){let r=NL(e,t);if(!Ru(r))return`the ${vu[t]}'s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it`;let n=yr[t],o=Fn(e[n.ball],e[n.fore],r);return Math.hypot(...H(o,e[n.ball]))>=MH?null:`the ${vu[t]}'s ball joint sits on its own pivot axis, so the arm has no length to swing on`}function oo(e,t){let r=yr[t],n=e[r.ball],o=NL(e,t),a=Fn(n,e[r.fore],o),s=H(a,n),i=Math.hypot(s[0],s[1],s[2]),{e1:c,e2:l}=OL(o),u=i>0?X(s,1/i):c;return{...If(o),clock:Math.atan2(J(u,l),J(u,c))*xu,len:i,sFront:J(H(e[r.fore],a),o),sRear:J(H(e[r.aft],a),o)}}function r1(e,t){let r=_f(e.side,e.plan),{e1:n,e2:o}=OL(r),a=oe(X(n,Math.cos(e.clock*Ei)),X(o,Math.sin(e.clock*Ei))),s=oe(t,X(a,e.len));return{fore:oe(s,X(r,e.sFront)),aft:oe(s,X(r,e.sRear))}}function VL(e,t,r,n){let o=yr[t],a={...oo(e,t),[r]:n},{fore:s,aft:i}=r1(a,e[o.ball]);return{...e,[o.fore]:s,[o.aft]:i}}function BL(e,t){return t==="clock"?e.len:Math.abs(e.sFront-e.sRear)/2}function Vf(e,t,r){return t==="len"?r:Nf(BL(e,t),r)}function n1(e,t,r){return t==="len"?r:Of(BL(e,t),r)}var Ya=["side","plan","atY","atZ"],vn={fore:"rockerPivotA",aft:"rockerPivotB"},SH=5,$L=e=>Ef(e.rockerPivotA,e.rockerPivotB);function Ii(e){return Math.hypot(...H(e.rockerPivotB,e.rockerPivotA))<SH?"the rocker\u2019s two pivots are the same point, so there is no axis to describe":Ru($L(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=$L(e),r=Ru(t)?t:[1,0,0],n=e.rockerPivotA,o=oe(n,X(r,-n[0]/r[0]));return{...If(r),atY:o[1],atZ:o[2],sA:J(H(n,o),r),sB:J(H(e.rockerPivotB,o),r)}}function o1(e){let t=_f(e.side,e.plan),r=[0,e.atY,e.atZ];return{a:oe(r,X(t,e.sA)),b:oe(r,X(t,e.sB))}}function GL(e,t,r){if(Ii(e))return e;let{a:n,b:o}=o1({...Eo(e),[t]:r});return{...e,rockerPivotA:n,rockerPivotB:o}}var KL=e=>Math.abs(e.sA-e.sB)/2;function a1(e,t,r){return t==="side"||t==="plan"?Nf(KL(e),r):r}function s1(e,t,r){return t==="side"||t==="plan"?Of(KL(e),r):r}var Wr={front:"Front",rear:"Rear"},Yr=["x","y","z"],st=(e,t)=>t==="front"?e.front:e.rear,ku=(e,t,r)=>t==="front"?{...e,front:r}:{...e,rear:r},HL=[{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"}]}],zL={damperChassis:"strut top mount",pushrodOuter:"strut lower mount"},Wa=30;function AH(e){let t=[];for(let r of["front","rear"]){let n=st(e.vehicle,r).config.layout==="mcpherson";for(let o of HL)for(let{key:a,label:s}of o.keys){let i=n&&zL[a]||s;for(let c=0;c<3;c++)t.push({id:`hp.${r}.${a}.${Yr[c]}`,group:`${Wr[r]} hardpoints \u2014 ${o.kind}`,label:`${i} ${Yr[c]}`,scope:Wr[r],unit:"mm",defaultSpan:Wa,read:l=>st(l.vehicle,r).hardpoints[a][c],write:(l,u)=>{let d=st(l.vehicle,r),p=[...d.hardpoints[a]];p[c]=u;let m={...d.hardpoints,[a]:p};return{...l,vehicle:ku(l.vehicle,r,{...d,hardpoints:m})}}})}}return t}var wH={side:"axis side-view angle",plan:"axis plan-view angle",clock:"arm clock angle",len:"effective arm length"},CH={side:"\xB0",plan:"\xB0",clock:"\xB0",len:"mm"};function FH(e){let t=[];for(let r of["front","rear"]){let n=st(e.vehicle,r).config.layout==="mcpherson";for(let o of["uca","lca"]){let a=st(e.vehicle,r).hardpoints,s=t1(a,o)?null:oo(a,o);for(let i of Do)t.push({id:`arm.${r}.${o}.${i}`,group:`${Wr[r]} ${n?"arm axes":"wishbone axes"}`,label:`${vu[o]} \u2014 ${wH[i]}`,scope:Wr[r],unit:CH[i],defaultSpan:s?Vf(s,i,Wa):Wa,read:c=>oo(st(c.vehicle,r).hardpoints,o)[i],write:(c,l)=>{let u=st(c.vehicle,r),d=VL(u.hardpoints,o,i,l);return{...c,vehicle:ku(c.vehicle,r,{...u,hardpoints:d})}}})}}return t}var TH={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"},PH={side:"\xB0",plan:"\xB0",atY:"mm",atZ:"mm"};function LH(e){let t=[];for(let r of["front","rear"]){let n=st(e.vehicle,r).hardpoints,o=Ii(n)?null:Eo(n);for(let a of Ya)t.push({id:`rocker.${r}.${a}`,group:`${Wr[r]} rocker axis`,label:`rocker \u2014 ${TH[a]}`,scope:Wr[r],unit:PH[a],defaultSpan:o?a1(o,a,Wa):Wa,read:s=>Eo(st(s.vehicle,r).hardpoints)[a],write:(s,i)=>{let c=st(s.vehicle,r),l=GL(c.hardpoints,a,i);return{...s,vehicle:ku(s.vehicle,r,{...c,hardpoints:l})}}})}return t}var Bf={front:"heaveFrontDesign",rear:"heaveRearDesign"},i1={front:"arbFrontDesign",rear:"arbRearDesign"};function DH(e,t){return{heave:e.config.actuation==="decoupled"?"heave element":"third spring",roll:t?.design.kind==="coil"?"roll shock":"anti-roll bar"}}var $f=e=>/^(heave|roll)\.(front|rear)\.(outer|inner|anchor)\.[xyz]$/.test(e);function EH(e){let t=[];for(let r of["front","rear"]){let n=st(e.vehicle,r),o=e.params[Bf[r]],a=e.params[i1[r]],s=DH(n,a),i=f=>f.params[Bf[r]],c=f=>f.params[i1[r]],l=(f,h)=>({...f,params:{...f.params,[Bf[r]]:h}}),u=(f,h)=>({...f,params:{...f.params,[i1[r]]:h}}),d={group:`${Wr[r]} heave & roll elements`,scope:Wr[r]},p=(f,h,b,g,y)=>{for(let x of b)t.push({...d,id:`${f}.${Yr[x]}`,label:`${h} ${Yr[x]}`,unit:"mm",defaultSpan:Wa,read:v=>g(v)[x],write:(v,k)=>{let R=[...g(v)];return R[x]=k,y(v,R)}})},m=(f,h,b,g,y)=>{t.push({...d,id:f,label:h,unit:"N/mm",defaultSpan:Math.max(5,b*.4),read:g,write:y})};if(o?.design.kind==="coil"){if(o.linkage){let f=b=>i(b).linkage;p(`heave.${r}.outer`,`${s.heave} eye`,[0,1,2],b=>f(b).outer,(b,g)=>l(b,{...i(b),linkage:{...f(b),outer:g}})),o.linkage.mount?.kind==="chassis"&&p(`heave.${r}.anchor`,`${s.heave} chassis anchor`,[0,2],b=>f(b).mount.anchor,(b,g)=>l(b,{...i(b),linkage:{...f(b),mount:{kind:"chassis",anchor:g}}}))}if(typeof o.design.rate=="number"){let f=h=>i(h).design;m(`heave.${r}.rate`,`${s.heave} spring rate (@element)`,o.design.rate,h=>f(h).rate,(h,b)=>l(h,{...i(h),design:{...f(h),rate:b}}))}}if(a&&a.design.kind!=="none"){if(a.linkage&&a.design.kind!=="direct"){let h=x=>c(x).linkage,b=en(n,a.linkage,a.design.kind),[g,y]=b?["left arm eye","right arm eye"]:["drop-link pickup","arm tip"];p(`roll.${r}.outer`,`${s.roll} ${g}`,[0,1,2],x=>h(x).outer,(x,v)=>u(x,{...c(x),linkage:{...h(x),outer:v}})),p(`roll.${r}.inner`,`${s.roll} ${y}`,[0,1,2],x=>h(x).inner,(x,v)=>u(x,{...c(x),linkage:{...h(x),inner:v}}))}let f=a.design;if(f.kind==="coil"&&typeof f.rate=="number"){let h=b=>c(b).design;m(`roll.${r}.rate`,`${s.roll} spring rate (@element)`,f.rate,b=>h(b).rate,(b,g)=>u(b,{...c(b),design:{kind:"coil",rate:g}}))}else f.kind==="direct"&&m(`roll.${r}.wheelRate`,`${s.roll} rate (@wheel)`,f.wheelRate,h=>c(h).design.wheelRate,(h,b)=>u(h,{...c(h),design:{kind:"direct",wheelRate:b}}))}}return t}var IH=[{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 _H(e){let t=[];for(let r of["front","rear"]){let n=st(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:Wr[r],unit:"N/mm",defaultSpan:Math.max(500,l*.4),read:u=>i(st(u.vehicle,r).compliance??{})??l,write:(u,d)=>{let p=st(u.vehicle,r),m={...p,compliance:c(p.compliance??{},Math.max(1,d))};return{...u,vehicle:ku(u.vehicle,r,m)}}})};for(let a of["ucaFront","ucaRear","lcaFront","lcaRear","tieRod","pushRod"])o(`link.${a}`,`${NH[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}`,`${OH[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 NH={ucaFront:"UCA front leg",ucaRear:"UCA rear leg",lcaFront:"LCA front leg",lcaRear:"LCA rear leg",tieRod:"tie rod",pushRod:"push/pull rod"},OH={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 VH(){return IH.map(e=>({id:`cfg.${e.axle}.${e.field}`,group:e.group,label:e.label,scope:Wr[e.axle],unit:e.unit,defaultSpan:e.span(e.fallback),read:t=>st(t.vehicle,e.axle).config[e.field]??e.fallback,write:(t,r)=>{let n=st(t.vehicle,e.axle),o={...n,config:{...n.config,[e.field]:r}};return{...t,vehicle:ku(t.vehicle,e.axle,o)}}}))}function BH(e){let t=qo(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=>qo(c.params.steeringSystem)[n],write:(c,l)=>({...c,params:{...c.params,steeringSystem:qo({...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 $H(e){let t=ha(e.params),r=[];for(let n of["front","rear"]){if(t[n]!=="diff")continue;let o=fa(e.params.driveline?.[n]);if(o?.kind!=="clutch"&&o?.kind!=="torsen")continue;let a=(s,i)=>{let c=Id[`${n}.${s}`];return{id:`driveline.${n}.${s}`,group:"Differential",label:c.label.charAt(0).toLowerCase()+c.label.slice(1),scope:Wr[n],unit:c.unit===": 1"?"":c.unit??"",defaultSpan:i,read:l=>fa(l.params.driveline?.[n])?.[s],write:(l,u)=>({...l,params:{...l.params,driveline:Ed({...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 GH(e){if(Vc(e.params)!=="hydraulic")return[];let t=[{id:"brakeSetup.barFront",group:"Brakes",label:`${Zg("barFront").toLowerCase()}, front share`,unit:"-",defaultSpan:.05,read:a=>On(a.params.brakeSetup).barFront,write:(a,s)=>({...a,params:{...a.params,brakeSetup:On({...On(a.params.brakeSetup),barFront:s})}})}];if(!e.params.brakeModel)return t;let r=an(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:Qg(a.circuit?`${a.circuit}.${String(a.key)}`:a.key),unit:s,defaultSpan:i,read:c=>n(an(c.params.brakeModel),a),write:(c,l)=>{let u=an(c.params.brakeModel),d=a.circuit?{...u,[a.circuit]:{...u[a.circuit],[a.key]:l}}:{...u,[a.key]:l};return{...c,params:{...c.params,brakeModel:an(d)}}}});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 YL=e=>!!e&&typeof e=="object"&&"value"in e&&"label"in e;function WL(e){let t={...e};for(let r of Object.keys(t)){let n=t[r];YL(n)&&(t[r]={...n})}return t}function KH(e){let t=[];for(let r of kw(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 YL(s)?s.value:NaN},write:(a,s)=>{let i=WL(a.params);return Zs(i,n.label,s),{...a,params:i}}})}return t}function jL(e){let t={};for(let i of["front","rear"]){if(!st(e.vehicle,i).measured)continue;let l="this axle is described by measured curves, so its linkage is not solved";for(let u of HL)for(let{key:d}of u.keys)for(let p of Yr)t[`hp.${i}.${d}.${p}`]={why:l};for(let u of["uca","lca"])for(let d of Do)t[`arm.${i}.${u}.${d}`]={why:l};for(let u of Ya)t[`rocker.${i}.${u}`]={why:l};for(let u of["heave.outer","heave.anchor","roll.outer","roll.inner"]){let[d,p]=u.split(".");for(let m of Yr)t[`${d}.${i}.${p}.${m}`]={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(st(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 Yr)t[`hp.${i}.${l}.${u}`]={why:c};for(let l of Ya)t[`rocker.${i}.${l}`]={why:c}}for(let i of["front","rear"]){let c=st(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 d of Yr)t[`hp.${i}.${u}.${d}`]={why:l,useInstead:`heave.${i}.outer.${d}`};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=st(e.vehicle,i),l=e.params[Bf[i]]?.linkage;if(c.measured||!l||l.attach!=="rocker"||l.mount?.kind==="chassis")continue;let u=c.hardpoints,d=[0,1,2].map(m=>u.rockerPivotB[m]-u.rockerPivotA[m]),p=Math.hypot(d[0],d[1],d[2]);if(p>0)for(let m=0;m<3;m++)Math.abs(d[m]/p)<1-1e-12||(t[`heave.${i}.outer.${Yr[m]}`]={why:`the rocker shaft runs along ${Yr[m]} \u2014 this only slides the eye along it`})}for(let i of["front","rear"]){let c=st(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 d of Yr)t[`hp.${i}.${u}.${d}`]={why:l,useInstead:`hp.${i}.damperChassis.${d}`};for(let u of Do)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=st(e.vehicle,i);if(c.measured)continue;for(let u of["uca","lca"]){if(u==="uca"&&c.config.layout==="mcpherson")continue;let d=t1(c.hardpoints,u);if(d)for(let p of Do)t[`arm.${i}.${u}.${p}`]={why:d,useInstead:`hp.${i}.${yr[u].fore}.z`}}let l=Ii(c.hardpoints);if(l&&c.config.actuation!=="direct")for(let u of Ya)t[`rocker.${i}.${u}`]={why:l,useInstead:`hp.${i}.${vn.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,d]of n){let p=e.params[i];if(!p?.design||p.design.kind==="none")continue;let m=p.design.kind==="direct"?`${d}.${u}.wheelRate`:`${d}.${u}.rate`;t[c]={why:`computed from ${l}`,useInstead:m}}let o=e.params.aeroModelId||e.params.aeroModel?B0:$0;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(Nd))t[`param.${i}`]={why:c};for(let[i,c]of Object.entries(Od(e.params)))t[`param.${i}`]={why:c};let a={...Df(e.params).readouts,...e.sessionAir?{rho:Lp}:{}};for(let[i,c]of Object.entries(a)){let l=`param.${i}`;!(l in t)&&!(l in XL)&&(t[l]={why:c})}for(let[i,c]of Object.entries(G0(e.params)))t[`param.${i}`]={why:c};let s=Vc(e.params)==="hydraulic";for(let[i,c]of Object.entries(Xm(e.params)))t[`param.${i}`]=s?{why:c,useInstead:"brakeSetup.barFront"}:{why:c};return t}function UL(e){let t={...XL,...jL(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[...AH(e),...FH(e),...LH(e),...EH(e),...VH(),...BH(e),...GH(e),...$H(e),..._H(e),...KH(e.params)].map(r)}var HH={spring_front:"cfg.front.springRate",spring_rear:"cfg.rear.springRate"},XL=Object.fromEntries(Object.entries(V0).map(([e,t])=>[`param.${e}`,{why:t,useInstead:HH[e]}])),ut=e=>e.scope?`${e.scope} \xB7 ${e.label}`:e.label;function bt(e){let t={};for(let n of UL(e))t[n.id]=n;let r=(n,o)=>{if(typeof o!="string")return;let a=uL(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 c1=e=>e.step!==void 0&&Number.isFinite(e.step)&&e.step>0?e.step:0,l1=e=>c1(e)>0||(e.values?.length??0)>0,u1=e=>e.some(l1),qL=e=>1e-9*Math.max(1,Math.abs(e.lo),Math.abs(e.hi));function QL(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=c1(e);if(!r||!Number.isFinite(e.start))return t;let n=qL(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 ZL=(e,t)=>t.map((r,n)=>e[n]&&l1(e[n])?QL(e[n],r):r);function m1(e,t=1e3){if(e.values?.length)return e.values.length;let r=c1(e);if(!r||!Number.isFinite(e.start))return 1/0;let n=qL(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 d1(e,t,r){let n=ZL(e.variables,t),o=n.every((a,s)=>a===t[s]);return{x:n,score:o?r:In(e,n)}}function h1(e,t){if(!e.variables.some(JL))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(eD(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 JL=e=>!!(e.fixed||e.around||e.follows)||eD(e),eD=e=>!!e.values?.length&&(e.lo!==Math.min(...e.values)||e.hi!==Math.max(...e.values));function Bt(e,t){if(!t.variables.some(JL))return t;let r=bt(e);return h1(t,n=>{let o=r[n];if(!o)return NaN;try{return o.read(e)}catch{return NaN}})}var Kf=()=>({variables:[],constraints:[],objectives:[],watches:[],density:{...Si},envelope:{...du},operating:{...bi},lap:Jp()});function jr(e){return[...e.objectives,...e.constraints,...e.watches??[]]}var Hf=e=>(e.metrics??gr()).byId;function b1(e,t){t=Bt(e,t);let r=bt(e),n=[];for(let o of t.variables){let a=r[o.id];a&&n.push({id:a.id,name:ut(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 _i(e,t,r){t=Bt(e,t);let n=bt(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]))}),x1(e,o,t.followers,n)}function g1(e,t,r={}){let n=t.states??[],o=n.some(c=>c.follows);if(!o&&!t.envelopeFollows)return t;let a=Lo(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=Tx(n,c,WH(r)))}catch{s=n}let i=t.envelope;if(t.envelopeFollows&&s.length){let c=s.map(h=>a.poseAt(h)).filter(h=>h!==null),l=Hf(r),u=y1(t,l),d=jr(t).map(h=>({r:h,m:l[h.metricId]})).filter(({m:h})=>h&&h.id.startsWith("kin.")&&h.reads!=="state"&&(h.scope==="car"||u.includes(h.scope))),p=h=>{let b=Lo(e,{density:t.density,envelope:h,assemble:r.assemble,numerics:r.numerics});return d.every(({r:g,m:y})=>Number.isFinite(Rt(b,y,g.at)))},m=c.length===s.length?YH(e,Lx(c,u),u):null,f=m&&d.length?zH(m,p):m;f&&!Dx(f,t.envelope)&&(i=f)}return s===n&&i===t.envelope?t:{...t,states:s,envelope:i}}var Gf=3;function zH(e,t){let r=(c,l)=>t({...e,travelMin:c,travelMax:l}),n=e.travelMin-Gf,o=e.travelMax+Gf;if(r(n,o))return e;let a=(c,l,u)=>{for(;Math.abs(l-c)>1;){let d=Math.round((c+l)/2);u(d)?c=d:l=d}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+Gf)),i=Math.max(1,Math.min(e.travelMax,o-Gf));return s===e.travelMin&&i===e.travelMax?e:{...e,travelMin:s,travelMax:i}}function y1(e,t){let r=new Set;for(let n of jr(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 YH(e,t,r){if(!t)return null;let n=Ai(e.vehicle,e.params),{travelMin:o,travelMax:a}=t;for(let s of r.map(i=>n[i]))try{let i=ct(s,{travelMin:o,travelMax:a,steps:Si.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 WH(e){let t=e.projectTrack?.();if(!t)return null;try{return Fx(Ot(t.asset,t.numerics))}catch{return null}}function x1(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 Io(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 tD=(e,t="")=>t&&t!=="-"?`${e} ${t}`:`${e}`;function rD(e,t,r){let n=t??Di[e.metricId],o=(n?ht(n):e.metricId)+ja(e.at,n,r),a=s=>tD(s,n?.unit);return e.op==="max"?`${o} \u2264 ${a(e.limit)}`:e.op==="min"?`${o} \u2265 ${a(e.limit)}`:`${o} between ${e.limit} and ${a(e.limit2??e.limit)}`}function ja(e,t,r){if(!e&&t?.reads!=="state")return"";e??={};let n=[];if(t?.reads==="state")if(e.stateId===gn)n.push(KR(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&&$R(t)&&n.push(`${(e.speed*3.6).toFixed(0)} km/h`),e.ayG!==void 0&&GR(t)&&n.push(`${e.ayG.toFixed(2)} g`),e.courseId===bu&&t?.reads==="course")n.push(BR(t));else if(e.courseId&&t?.reads==="course"){let o=r?.lap.courses.find(a=>a.id===e.courseId);o&&n.push(Hx(o))}return n.length?` @ ${n.join(", ")}`:""}function nD(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 oD=5e-4;function aD(e,t){return e.cost!=="lap"&&e.cost!=="session"?0:Number.isFinite(t)?oD*Math.abs(t):0}function zf(e,t,r={}){return Lo(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 Ua(e,t,r={}){t=Bt(e,t);let n=b1(e,t),o=bt(e),a=Hf(r),s=t.constraints.map(d=>({spec:d,metric:a[d.metricId]})).filter(d=>!!d.metric),i=s.filter(d=>d.metric.cost==="geometry"),c=s.filter(d=>d.metric.cost!=="geometry"),l=t.objectives.map(d=>({spec:d,metric:a[d.metricId]})).filter(d=>!!d.metric),u=(d,p)=>{let m=0,f=[];for(let{spec:h,metric:b}of d){let g=Rt(p,b,h.at);if(!Number.isFinite(g))return{ok:!1,violation:p.failure?.violation??400,reason:p.failure?.reason??`${ht(b)} could not be computed`};let y=Io(h,g);y>0&&(m+=y/b.scale,f.push(`${rD(h,b,t)} (${tD(g.toFixed(3),b.unit)})`))}return f.length===0?wc:{ok:!1,violation:m,reason:f.join("; ")}};return{name:"study",variables:n,build:d=>{let p=e;return t.variables.forEach((m,f)=>{let h=o[m.id];h&&(p=h.write(p,d[f]))}),p=x1(e,p,t.followers,o),{car:p,ev:zf(p,t,r)}},feasible:({ev:d})=>{let p=u(i,d);if(!p.ok)return p;for(let{spec:m,metric:f}of c)Rt(d,f,m.at);for(let{spec:m,metric:f}of l)Rt(d,f,m.at);return d.failure?{ok:!1,violation:d.failure.violation,reason:d.failure.reason}:u(c,d)},terms:({ev:d})=>l.map(({spec:p,metric:m})=>{let f=Rt(d,m,p.at);return{name:ht(m)+ja(p.at,m,t),raw:f,unit:m.unit,weight:p.weight,contribution:nD(p,m,f),resolution:Math.abs(p.weight)*aD(m,f)/m.scale}})}}function p1(e){let t=/^arm\.(front|rear)\.(uca|lca)\./.exec(e);if(t)return`${t[1]}.${t[2]}`;let r=/^rocker\.(front|rear)\./.exec(e);if(r)return`${r[1]}.rocker`;let n=/^hp\.(front|rear)\.(ucaFront|ucaRear|lcaFront|lcaRear|rockerPivotA|rockerPivotB)\./.exec(e);return n?n[2].startsWith("rocker")?`${n[1]}.rocker`:`${n[1]}.${n[2].startsWith("uca")?"uca":"lca"}`:null}function sD(e,t){if(e.variables.some(o=>o.id===t))return!0;let r=Ka(t);if(!r||!Ci.includes(r.axis))return!1;if(e.variables.some(o=>Cr(o.id)?.point===r.point))return!0;let n=p1(t);return!!n&&e.variables.some(o=>/^(arm|rocker)\./.test(o.id)&&p1(o.id)===n)}function jH(e,t){let r=e.followers??[],n=new Map(r.map(i=>[i.id,i.follows])),o=i=>{let c=t[i],l=Ka(i);return c&&l&&Ci.includes(l.axis)?{name:ut({...c,label:c.label.replace(/ [xyz]$/,"")}),axis:l.axis}:{name:c?ut(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),d=o(i.follows),p=m=>m&&m!=="x, y, z"?` in ${m}`:"";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,m=>`${u.name}${p(m)} cannot be moved: ${c.supersededBy.why}.`),!l)s(`no-lead:${u.name}:${i.follows}`,u.axis,m=>`${u.name}${p(m)} 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,m=>`${u.name}${p(m)} cannot move with itself.`);else if(l.unit!==c.unit)s(`unit:${u.name}:${d.name}`,u.axis,m=>`${u.name}${p(m)} moves with ${d.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 m=o(n.get(i.follows));s(`chain:${u.name}:${d.name}`,u.axis,f=>`${u.name}${p(f)} moves with ${d.name}, which itself moves with ${m.name}. Link it to ${m.name}.`)}else sD(e,i.follows)||s(`still:${u.name}:${d.name}`,u.axis,m=>`${u.name}${p(m)} moves with ${d.name}, which the study does not move${p(m)}. Free that one, or give this its own bound.`)}return[...a.values()].map(i=>i.text(i.axes.join(", ")))}function R1(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=Bt(e,t);let a=bt(e),s=[],i=Hf(r),c=jr(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 d=jr(t).filter(y=>i[y.metricId]?.reads==="state");if(d.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(v=>v.id),gn]);for(let v of d){let k=i[v.metricId];if(v.at?.stateId&&!x.has(v.at.stateId))s.push(`${ht(k)} names a state this study no longer has. Point it at one of the states under Conditions.`);else if(v.at?.stateId===gn&&!k.acrossStates)s.push(`${ht(k)} is read at one state at a time, not over every state.`);else if(k.appliesAt){let R=v.at?.stateId&&v.at.stateId!==gn?y.find(S=>S.id===v.at.stateId):void 0,M=R?UR(k,R):null;M?s.push(`${ht(k)} ${M}. Point it at a state that does.`):!R&&!Ff(k,y)&&s.push(`${ht(k)} has no state to be read at: ${k.appliesAt(y[0])} in every state of this study.`)}}}r.assemble||s.push("This study reads targets at a state, and nothing here can assemble the car to find its pose.")}for(let y of t.states??[])(!(y.speedKmh>=0)||!Number.isFinite(y.ayG)||!Number.isFinite(y.axG))&&s.push(`The state \u201C${y.name}\u201D needs a speed of zero or more and finite accelerations.`),y.weight>0||s.push(`The state \u201C${y.name}\u201D needs a weight above zero.`);if(l&&!r.assemble&&s.push("This study reads whole-car metrics, and nothing here can assemble the car to read them from."),u&&!r.simParams&&s.push("This study reads lap metrics, and nothing here can prepare the car for a lap."),u&&!t.lap.courses.length&&s.push("This study reads lap metrics and has no course to drive. Add one under \u201CWhat the car drives\u201D."),u&&t.lap.courses.some(y=>y.course.kind==="project")&&!r.projectTrack?.()&&s.push("This study laps the project\u2019s track, and the project has none. Pick a manoeuvre, or load a track."),u)for(let y of t.lap.courses)y.course.kind==="track"&&!r.libraryTrack?.(y.course.trackId)&&s.push(`This study drives ${y.course.name}, which is not in the project\u2019s tracks, or has not loaded yet.`);let p=new Set([...t.lap.courses.map(y=>y.id),bu]);for(let y of jr(t))if(y.at?.courseId&&!p.has(y.at.courseId)){let x=i[y.metricId];s.push(`${x?ht(x):y.metricId} names a course this study no longer has. Point it at one of the courses below.`)}u&&t.lap.ggvMode==="fast"&&t.variables.some(x=>/arb_|spring|heave_|front_mass_diss|cg_height|chassis_torsion|^hp\.|^roll\./.test(x.id.replace("param.","")))&&s.push("The fast grip envelope is a point mass: no load transfer, no trim. It cannot see bars, springs, roll centres, the chassis\u2019s twist or where the mass sits, and this study moves at least one of those."),n?s.push(o?"Every variable is fixed or moves with another \u2014 there is nothing to search.":"Every variable is fixed \u2014 there is nothing to search."):t.variables.length===0&&s.push("No variables selected \u2014 there is nothing to search."),t.objectives.length===0&&s.push("No objective selected. Constraints alone say which designs are legal, not which is better.");for(let y of t.variables){let x=a[y.id];if(!x){s.push(`\u201C${y.id}\u201D is not a variable this car has.`);continue}if(y.values&&y.values.length<2?s.push(`${ut(x)}: list two values or more, or fix it where it is.`):y.hi>y.lo?y.step!==void 0&&m1({...y,start:x.read(e)})<2&&s.push(`${ut(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(`${ut(x)}: the upper bound must be above the lower one (${y.lo} to ${y.hi}).`),x.supersededBy){let k=x.supersededBy.useInstead?a[x.supersededBy.useInstead]:void 0,R=k?ut(k):void 0;s.push(`${ut(x)} cannot be searched: ${x.supersededBy.why}.`+(R?` Use ${R} instead.`:""))}let v=x.read(e);Number.isFinite(v)&&(v<y.lo||v>y.hi)&&s.push(`${ut(x)} starts at ${v.toFixed(1)} ${x.unit}, outside its own bounds.`)}let m=t.followers??[],f=new Map;for(let y of[...t.variables.map(x=>x.id),...m.map(x=>x.id)]){let x=p1(y);if(!x)continue;let v=f.get(x);v||f.set(x,v={arms:[],coords:[]}),(/^(arm|rocker)\./.test(y)?v.arms:v.coords).push(y)}for(let[y,x]of f){if(x.arms.length===0||x.coords.length===0)continue;let v=R=>a[R]?ut(a[R]):R,k=y.endsWith("rocker")?"rocker":`${y.endsWith("uca")?"upper":"lower"} arm`;s.push(`${y.startsWith("front")?"The front":"The rear"} ${k} is being moved two ways at once \u2014 as an axis (${x.arms.map(v).join(", ")}) and as pivot coordinates (${x.coords.map(v).join(", ")}). They describe the same ${k}, so whichever is applied second overwrites the other. Keep one.`)}let h=new Map,b=new Set(m.map(y=>y.id));for(let y of[...t.variables.map(x=>x.id),...b]){let x=Ka(y);if(!x)continue;let v=Cr(y),k=b.has(y)?"with":v?`${v.shape.kind}:${y.slice(y.lastIndexOf(".")+1).replace(/[uv]$/,"")}`:"axes",R=h.get(x.point);R||h.set(x.point,R=new Set),R.add(k)}for(let[y,x]of h){if(x.size<2||x.size===2&&x.has("axes")&&x.has("with"))continue;let v=[...x].map(w=>w.split(":")[0]),k=w=>v.filter(F=>F===w).length,R=[k("axes")?"in its axes":"",k("line")===1?"along a line":k("line")>1?"along two lines":"",k("plane")===1?"in a plane":k("plane")>1?"in two planes":"",k("with")?"with another point":""].filter(Boolean),M=a[`${y}.x`],S=M?ut({...M,label:M.label.replace(/ x$/,"")}):y;s.push(`${S} 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(...jH(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(`${ht(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 jr(t))if(y.at?.speed!==void 0&&!(y.at.speed>0)){let x=i[y.metricId];s.push(`${x?ht(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 jr(t)){let x=i[y.metricId],v=x?.unavailable?.(e);!x||!v||g.has(x.id)||(g.add(x.id),s.push(`${ht(x)} cannot be read on this car: ${v}.`))}for(let y of t.objectives)i[y.metricId]?y.weight>0?y.goal==="target"&&!Number.isFinite(y.target)?s.push(`${ht(i[y.metricId])}: \u201Chit a value\u201D needs a value.`):y.goal==="target"&&y.tolerance!==void 0&&!(y.tolerance>=0)&&s.push(`${ht(i[y.metricId])}: the tolerance must be zero or more.`):s.push(`${ht(i[y.metricId])}: weight must be positive.`):s.push(`\u201C${y.metricId}\u201D is not a metric.`);return s}var iD=.1,cD=2e3,f1=3;function v1(e,t,r={},n=cD){t=Bt(e,t);let o=Ua(e,t,r),a=Hf(r),s=bt(e),i=o.variables.map(A=>A.start),c=A=>{let C=o.build(A);return o.feasible(C).ok&&o.terms(C),C},l=c(i),u=o.feasible(l),d=[...t.objectives,...t.constraints],p=(A,C=d)=>{let P={};for(let L of C){let E=a[L.metricId];E&&(P[`${L.metricId}@${Ha(L.at)}`]=Rt(A.ev,E,L.at))}return P},m=A=>d.map(C=>A[`${C.metricId}@${Ha(C.at)}`]).map(C=>Number.isFinite(C)?C.toFixed(9):"x").join("|"),f=p(l,jr(t)),h=m(f),b=[],g=[],y={},x=[],v=0;t.variables.forEach((A,C)=>{let P=s[A.id];if(!P)return;if(x.length>=f1&&v>n){g.push(P);return}let L=[...i];L[C]=i[C]+(A.hi-i[C])*.25||A.hi;let E=performance.now(),_=c(L),D=performance.now()-E;v+=D,x.push(D);let I=p(_);y[P.id]=I,m(I)===h&&b.push(P)});let k=t.variables[0],R=k?t.variables.indexOf(k):-1;for(let A=0;k&&x.length>0&&x.length<f1;A++){let C=[...i];C[R]=i[R]+(k.hi-i[R])*(.4+.15*A)||k.hi;let P=performance.now();c(C),x.push(performance.now()-P)}let M=[...x].sort((A,C)=>A-C),S=M.length?M[M.length>>1]:0,w=[],F=jr(t).map(A=>A.metricId);if(F.some(A=>A.startsWith("dyn.trim")||A==="dyn.ymdMaxAy")){let A=l.ev.ymdLimit();A?.onGridEdge&&w.push("The yaw-moment diagram peaks on the edge of its swept grid, so the trim readings are where the sweep stopped rather than where the car does. Widen the \u03B2/\u03B4 envelope before trusting them."),!A&&l.ev.dynAvailable&&w.push("The yaw-moment diagram found no trim point, so anything read off the limit is unavailable.")}if(F.some(A=>A==="dyn.steeringTorque"||A==="dyn.steeringTorqueGradient")){let A=l.ev.tyre()?.model,C=A?bo(A):null;C==="assumed"?w.push("This tyre carries no explicit Mz coefficient block. Its steering-aligning contribution uses Magic Formula defaults, so optimise the curve only as a qualitative placeholder until Mz is imported or fitted."):C==="none"&&w.push("This tyre model has no aligning-moment curve. Steering metrics contain contact-patch force and jacking, but not the pneumatic-trail signal that normally warns the driver at the tyre limit.")}let T=["lap.minStabil","lap.understeerFrac"];if(F.some(A=>T.includes(A))){let C=l.ev.lapReserve()?.beyondFrac;if(C!==void 0&&Number.isFinite(C)){let P=(C*100).toFixed(0);C>=iD?w.push(`Over ${P} % of this course, some wheel is asked for more longitudinal force than its own tyre ellipse allows \u2014 the speed profile and the per-wheel reconstruction disagree that far. A reserve read there is the two models disagreeing rather than the car having nothing left, and a search pointed at one will optimise the disagreement. It concentrates in high-speed braking, so a shorter straight into the first corner is the usual cure.`):C>0&&w.push(`${P} % of this course is beyond the per-wheel tyre ellipse, which is the usual level of disagreement between the speed profile and the reconstruction. Reserves are readable; treat small differences between designs as smaller than they look.`)}}return w.push(...jR(l.ev,jr(t).map(A=>({m:a[A.metricId],at:A.at})).filter(A=>!!A.m))),{msPerEval:S,values:f,samples:x.length,times:x,dead:b,moves:y,unprobed:g,warnings:w,beyondFrac:F.some(A=>T.includes(A))?l.ev.lapReserve()?.beyondFrac:void 0,startFeasible:u.ok,startReason:u.reason}}var XH=[{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:qH.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 qH=["setup:m","characteristics:peak_power","characteristics:power_to_weight","characteristics:cla","characteristics:cda","characteristics:pack_energy","characteristics:maxAy","characteristics:top_speed"];var cge=new Set(XH.map(e=>e.kind));var lD={travel:{name:"Wheel travel",unit:"mm",axis:"Wheel travel (mm, + bump)",from:-25,to:25,step:1,reach:150},roll:{name:"Body roll",unit:"\xB0",axis:"Body roll (\xB0, + right side down)",from:-3,to:3,step:.25,reach:12},steer:{name:"Rack",unit:"mm",axis:"Rack (mm, + right)",from:-30,to:30,step:1,reach:80},pitch:{name:"Body pitch",unit:"\xB0",axis:"Body pitch (\xB0, + nose down)",from:-2,to:2,step:.25,reach:8}};var k1=["FL","FR","RL","RR"],nr=(e,t,r)=>({input:e,from:r?r[0]:lD[e].from,to:r?r[1]:lD[e].to,n:t}),dge=[{id:"sides",name:"Inside and outside",cards:[{id:"camber-roll",form:"curves",title:"Camber to the road through roll",sweep:nr("roll",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"toe-rack",form:"curves",title:"Wheel angle against the rack",sweep:nr("steer",25),wheels:["FL","FR"],y:["toe"]},{id:"camber-rack",form:"curves",title:"Camber to the road through the steer",sweep:nr("steer",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"load-roll",form:"curves",title:"Wheel loads through roll",sweep:nr("roll",25),wheels:k1,y:["wheelLoad"]},{id:"travel-roll",form:"curves",title:"Wheel travel through roll",sweep:nr("roll",25),wheels:k1,y:["travel"]},{id:"toe-roll",form:"curves",title:"Roll steer, all four",sweep:nr("roll",25),wheels:k1,y:["toe"]}]},{id:"maps",name:"Travel and steer together",cards:[{id:"camber-map",form:"surface",title:"Camber over travel and rack",sweep:nr("travel",17),second:nr("steer",13),wheels:["FL"],y:["camber"]},{id:"bump-steer-map",form:"map",title:"Bump steer over travel and rack",sweep:nr("travel",17),second:nr("steer",13),wheels:["FL"],y:["bumpSteer"]},{id:"bump-steer-family",form:"curves",title:"Bump steer through travel, at five rack positions",sweep:nr("travel",25),second:nr("steer",5,[-20,20]),wheels:["FL"],y:["bumpSteer"]},{id:"scrub-map",form:"surface",title:"Scrub radius over travel and rack",sweep:nr("travel",17),second:nr("steer",13),wheels:["FL"],y:["scrubRadius"]}]}];function M1(e){let t=Number(e);return Number.isFinite(t)?Math.min(Rg,Math.max(xg,t)):lr}var mD=6e4;var d0e=[{within:60*6e4,every:mD},{within:1440*6e4,every:60*6e4},{within:720*60*6e4,every:1440*6e4},{within:1/0,every:10080*6e4}];var c4=new Set(["color","visible","source","origin"]),v0e=["id",...c4];var fD=.18/1.18,hD={induction:{kind:"natural"}},bD=e=>e.breathing??hD;function Yf(e){switch(e?.kind){case"sae-j1349":return $l(99e3,25);case"measured":return $l(e.hPa*100,e.tempC);default:return $l(101325,20)}}var u4=Yf(void 0);function gD(e,t){let r=Yf(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 yD(e,t){let r=e.induction;if(r.kind==="table"){let o=s=>et(r.densityAltitudeM,r.powerPct,s),a=o(Yf(e.rated).densityAltitudeM);return a>0?Math.max(0,o(t.densityAltitudeM)/a):0}let n=e.frictionShare??fD;return Math.max(0,(gD(e,t)-n)/(1-n))}var pD=new WeakMap;function A1(e,t){let r=e.asRated??e,n=`${t.p}|${t.pDry}|${t.T}`,o=pD.get(r);o||pD.set(r,o=new Map);let a=o.get(n);if(a)return a;let s=yD(bD(r),t),i={...r,torque:r.torque.map(c=>c*s),asRated:r};return o.set(n,i),i}function f4(e){return JSON.parse(w1(C1(e,"public/laptime/index.json"),"utf8")).tracks}var h4=async e=>{let t=await fetch(e.url);if(!t.ok)throw new Error(`The track could not be read from ${$p(e)} (${t.status}).`);return new Uint8Array(await t.arrayBuffer())};function xD(e,t=new Map,r=h4){let n=f4(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(!jl(o.address))throw new Error(`"${o.address}" is not a catalogue address`);if(!Wl(o.link))throw new Error("This track is linked to a source this version does not read from.");i=await px(await r(o.link),o.link,o.address)}else if(o.kind==="catalogue"){if(!jl(o.address))throw new Error(`"${o.address}" is not a catalogue address`);let c=JSON.parse(w1(C1(e,"public/catalogue",hx(o.address)),"utf8"));i=await gx(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(w1(C1(e,"public/laptime",c),"utf8"))}return t.set(a,i),structuredClone(i)}}var b4=1e-6;function RD(e,t,r){let n=e.cgReference;if(!n||!e.cg_height)return e;let o=fw(e,t,r);if(o===void 0||Math.abs(o-n.standingRadius)<b4)return e;let a=n.typed??e.cg_height.value;return{...e,cg_height:{...e.cg_height,value:Qs(e.cg_height.value,n.standingRadius,o)},cgReference:{...n,standingRadius:o,typed:a}}}function vD(e,t,r){let n=e.rcRoad,o=e.rc_front,a=e.rc_rear;if(!n||!o||!a)return e;let s=Dd(e,t,r),i=Un(o.value,n.gainFront,n.radiusFront,s.front),c=Un(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 kD=e=>({brakeFade:e.brakeFade,airTempC:e.airTempC,diffYaw:e.diffYaw,...Fa(e.air)?{air:e.air}:{}});var Xa=(e,t)=>t?e.find(r=>r.id===t)?.model:void 0;function qa(e){return{tire:t=>Xa(e.tires,t),motor:t=>Xa(e.motors,t),aero:t=>Xa(e.aeros,t),battery:t=>Xa(e.batteries,t),brake:t=>Xa(e.brakes??[],t),damper:t=>Xa(e.dampers??[],t),suspensionOf:t=>Ai(F1(e,t),t)}}function F1(e,t){let r=Xa(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 Qa(e,t,r){let n={front:t.tire(e.tireModelId),rear:t.tire(e.tireModelIdRear)};return T1(iw(t.suspensionOf(e),e,n),t,r)}function g4(e){return Fa(e.air)?HF(e.air,e.airTempC??lr):void 0}function y4(e,t){return t?{...e,rho:{...e.rho,value:t.rho},readouts:{...e.readouts,rho:Lp}}:e}function x4(e,t,r){if(!r)return{rho:e.rho,motorModel:t,readouts:e.readouts};let{rho:n,readouts:o}=y4(e,r);return{rho:n,motorModel:t&&kt(t)?A1(t,r):t,air:r,readouts:o}}function T1(e,t,r){let n=t.tire(e.tireModelId),o=t.tire(e.tireModelIdRear),a=vD(RD(Df(yw(hw(Cw(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}=x4(a,t.motor(e.motorModelId),g4(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),...tl(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 M4=e=>e!==!1,S4=(e,t,r)=>r&&t>0?(e%t+t)%t:Math.min(Math.max(e,0),t);function A4(e,t,r){let n=e.points.filter(o=>Number.isFinite(o.at)&&Number.isFinite(o.z)).map(o=>({...o,at:S4(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 w4(e,t,r){let n=A4(e,t,r),o=n.length;if(o===0)return[];let a=m=>m<o-1?n[m+1].at-n[m].at:r?n[0].at+t-n[m].at:1/0,s=m=>m<o-1?(n[m+1].z-n[m].z)/a(m):r&&o>1?(n[0].z-n[m].z)/a(m):0,i=n.map(m=>Math.max(0,Number.isFinite(m.curve)?m.curve:0)/2),c=(m,f,h)=>i[m]+i[f]>h?h*i[m]/(i[m]+i[f]):i[m],l=m=>m<o-1||r?c(m,m<o-1?m+1:0,a(m)):Math.max(0,t-n[m].at),u=m=>m>0?c(m,m-1,a(m-1)):r?c(m,o-1,a(o-1)):n[m].at,d=m=>m>0?s(m-1):r&&o>1?s(o-1):n[m].at<=1e-9?s(m):0,p=m=>!r&&m===o-1&&o>1&&n[m].at>=t-1e-9?s(m-1):s(m);return n.map((m,f)=>{let h=l(f),b=u(f),g=Math.min(i[f],h,b),y=!r&&g<i[f]&&(f===o-1&&g===h||f===0&&g===b);return{at:m.at,z:m.z,gIn:d(f),gOut:p(f),half:g,asked:i[f],atEnd:y}})}function C4(e,t,r,n){let o=t-e.at;return n&&r>0?o-r*Math.round(o/r):o}function F4(e,t,r,n){for(let s of e){let i=C4(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 MD(e,t,r,n){let o=M4(n),a=w4(e,r,o);return a.length?t.map(s=>F4(a,s,r,o)):t.map(()=>0)}function Mu(e,t){if(!t?.points.length)return e;let r=Zl(e),{zSmoothing:n,...o}=e;return{...o,z:MD(t,r,Bx(e),e.closed)}}var Wf={widthLeft:1.5,widthRight:1.5,bank:0,mu:1};function SD(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 Su(e,t){let r=SD(e.source);return AD(e,r?await t(r):void 0)}function AD(e,t){let{source:r}=e;if(r.kind==="segments"){let{segments:i,closed:c,spacing:l}=r,{asset:u}=eu(i,{name:e.name,closed:c,spacing:l,base:Wf});return Mu(u,r.profile)}let n=r.sections??[];if(r.kind==="inline")return Mu(Xp(r.asset,n,Wf),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 Mu(Xp({...t,...o!==void 0?{widthLeft:o}:{},...a!==void 0?{widthRight:a}:{},...s!==void 0?{closed:s}:{}},n,Wf),r.profile)}var Wxe=1/500;var jxe=5*Math.PI/180;var rRe=1/3;var D4=[4,2,1,.5,.25,.125];function wD(e,t,r={}){let n=[...r.steps??D4].sort((g,y)=>y-g),o=Nt(r.numerics),a=r.tolPct??.5,s=ur(e),i=e.ggvMode??"twoTrack",c=pn(s,!1,i),l={...o,dsTarget:n[0]??o.dsTarget},u=n.length?va(s,c,[Ot(t,l)],l,i):void 0,d=Ao(s,c.rows),p=n.map((g,y)=>{let x={...o,dsTarget:g},v=Date.now(),k=Ot(t,x),R=er(c,k,x,{...u?{load:u}:{},...d?{shifts:d}:{}});return r.onStep?.(y+1,n.length),{dsTarget:g,npts:k.npts,lapTime:R.laptime,ms:Date.now()-v}}),m=p[p.length-1]?.lapTime??NaN,f=p.map(g=>{let y=g.lapTime-m;return{...g,delta:y,deltaPct:m?100*y/m:NaN}}),h=f.filter(g=>Math.abs(g.deltaPct)<=a),b=h.length?Math.max(...h.map(g=>g.dsTarget)):null;return{points:f,reference:m,recommended:b,tolPct:a}}function ao(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:M1(t.airTempC??r.airTempC),...Fa(Pp(t.air??r.air))?{air:Pp(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:Nt(r.numerics)}}async function jf(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 Su(r,t)}}function L1(e,t){let r=structuredClone(e);for(let[n,o]of Object.entries(t))if(!Zs(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 P1=(e,t)=>{let r=e?.name;return typeof r=="string"&&r?r:t};function _4(e,t){let r={};for(let n of Fo){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:P1(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:P1(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:P1(i.model,i.id),byFallback:!0}:null;continue}r[n.doc]=null}return r}function N4(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 CD(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 D1=e=>e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`;async function Uf(e,t,r={}){let n=ao(e,r.settings),{entry:o,asset:a}=await jf(e,t),s=qa(e),i=r.vehicleIds?.length?r.vehicleIds.map(f=>{let h=e.vehicles.find(b=>b.id===f);if(!h)throw new Error(`this project holds no vehicle "${f}"`);return h}):e.vehicles.filter(f=>f.visible);if(!i.length)throw new Error("no vehicle is visible in this project \u2014 name some in vehicleIds");let c=i.map(f=>{let h=r.overrides?.[f.id]?L1(f.params,r.overrides[f.id]):f.params;return Qa(structuredClone(h),s,n)}),l=Il(wa(e.meta.rulesetId,e.rulesets)),u=Bl(c,a,n.numerics,l,{racingLine:n.racingLine,standingStart:n.standingStart,lapCounts:n.lapCounts}),d={};i.forEach((f,h)=>{d[f.id]=u[h]});let{scores:p,field:m}=zy(l,d);return{rulesetId:e.meta.rulesetId,track:o.name,settings:{ggvMode:n.ggvMode,quasiTransient:n.quasiTransient,motorThermal:n.motorThermal,brakeFade:n.brakeFade,airTempC:n.airTempC,...n.air?{air:n.air}:{},diffYaw:n.diffYaw,racingLine:n.racingLine,standingStart:n.standingStart},fleetScored:p!==null,vehicles:i.map((f,h)=>({id:f.id,name:u[h].name||String(f.params.name??f.id),events:N4(u[h]),metrics:Yy(l,u[h],m?.[f.id]),fitted:_4(e,f.params),...p?.[f.id]?{score:{total:p[f.id].total,parts:{...p[f.id].parts}}}:{}})),raw:{results:d,scores:p,field:m}}}async function FD(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=ao(e),{asset:a}=await jf(e,t),s=Qa(structuredClone(n.params),qa(e),o);return wD(s,a,{...r.steps?{steps:r.steps}:{},numerics:o.numerics,...r.tolPct!==void 0?{tolPct:r.tolPct}:{},...r.onStep?{onStep:r.onStep}:{}})}var rve=Math.PI/180;var E1=["param.arb_front","roll.front.rate","roll.front.wheelRate"],PD="dyn.tlltdFront",I1=1e-6;function Xf(e){let t=bt(e),r=t["param.arb_front"];if(!r)return{why:"the car states no front anti-roll bar"};let n=r.supersededBy,o=n?n.useInstead:r.id,a=o?t[o]:void 0;if(!a||a.supersededBy)return{why:`its front bar is ${(n?.why??"computed elsewhere").replace(/^computed from /,"")}, whose rate is not one number to re-solve`};let s=a.read(e);return s>0?{id:a.id,def:a,now:s}:{why:"the car has no front bar to re-solve: its rate is zero"}}function LD(e,t,r,n,o=I1,a){let s=0,i=b=>(s++,e(b)-t),c=(b,g,y)=>({value:b,reading:t+g,reached:y,reads:s});if(a!==void 0&&a>=r&&a<=n){let b=i(a);if(Math.abs(b)<=o)return c(a,b,!0)}let l=r,u=n,d=i(l),p=i(u);if(!Number.isFinite(d)||!Number.isFinite(p))return c(NaN,NaN,!1);if(Math.abs(d)<=o)return c(l,d,!0);if(Math.abs(p)<=o)return c(u,p,!0);if(d*p>0)return Math.abs(d)<=Math.abs(p)?c(l,d,!1):c(u,p,!1);let m=0,f=l,h=d;for(let b=0;b<60;b++){if(f=(l*p-u*d)/(p-d),h=i(f),!Number.isFinite(h))return c(NaN,NaN,!1);if(Math.abs(h)<=o||Math.abs(u-l)<=1e-12*Math.max(1,Math.abs(f)))break;h*p>0?(u=f,p=h,m===-1&&(d/=2),m=-1):(l=f,d=h,m===1&&(p/=2),m=1)}return c(f,h,Math.abs(h)<=o)}function qf(e,t){let r=e.variables.findIndex(a=>E1.includes(a.id));if(r<0)return{why:"the front bar is not one of the variables"};let n=t.byId[PD];if(!n)return{why:"the balance cannot be read here"};let o=NaN;try{o=Rt(e.build(Vr(e.variables)).ev,n)}catch{}return Number.isFinite(o)?{slot:r,target:o,metric:n}:{why:"the car\u2019s balance could not be read"}}function Qf(e,t,r){let n=e.variables[r.slot],a=LD(i=>{let c=t.slice();c[r.slot]=i;try{return Rt(e.build(c).ev,r.metric)}catch{return NaN}},r.target,Math.max(0,n.lo),Math.max(0,n.hi),I1,t[r.slot]),s=t.slice();return Number.isFinite(a.value)&&(s[r.slot]=a.value),{x:s,held:{value:s[r.slot],balance:a.reading,target:r.target,reached:a.reached}}}var _1="param.m",N1=.01;function O1(e,t,r){return r===void 0||!Number.isFinite(r)||r===0||!Number.isFinite(e)||!Number.isFinite(t)?NaN:(e-t)/r}var Zf=.5,q4=new Set(["lap","session"]);function Q4(e){return ut({...e,label:e.label.replace(/ [xyz]$/,"")})}function DD(e){let t=Ka(e);if(t)return[t.point];let r=Cr(e);if(r)return[r.point];let n=/^arm\.(front|rear)\.(uca|lca)\./.exec(e);if(n){let a=yr[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]}.${vn.fore}`,`hp.${o[1]}.${vn.aft}`]:[]}function ED(e,t){let r=Bt(e,t),n=bt(e),o=new Map;for(let a of[...r.variables,...r.followers??[]])for(let s of DD(a.id)){if(o.has(s))continue;let i=Ci.map(c=>`${s}.${c}`).filter(c=>n[c]&&!n[c].supersededBy);i.length&&o.set(s,{id:s,name:Q4(n[i[0]]),coords:i})}return[...o.values()]}function V1(e,t,r,n={},o=Zf){let a=Bt(e,t),s=(n.metrics??gr()).byId,i=_i(e,a,r),c=ED(e,a),l=bt(i),u=[];a.objectives.forEach((A,C)=>{let P=s[A.metricId];P&&u.push({key:A.key??`target:${C}`,role:"target",metric:P,at:A.at})}),a.constraints.forEach((A,C)=>{let P=s[A.metricId];P&&u.push({key:A.key??`hold:${C}`,role:"hold",metric:P,at:A.at,hold:A})}),(a.watches??[]).forEach((A,C)=>{let P=s[A.metricId];P&&u.push({key:A.key??`watch:${C}`,role:"watch",metric:P,at:A.at})});let d=u.filter(A=>!q4.has(A.metric.cost)),p=A=>{let C=zf(A,a,n),P=d.map(L=>Rt(C,L.metric,L.at));return C.failure?null:P},m=p(i)??d.map(()=>NaN),f=[],h=[],b=[],g=1,y=[...m],x=[...m],v=A=>A.forEach((C,P)=>{Number.isFinite(C)&&(C>=y[P]||(y[P]=C),C<=x[P]||(x[P]=C))}),k=A=>{g++;try{return p(A())}catch{return null}};for(let A of c)for(let C of A.coords){let P=l[C],L=P.read(i),E=C.slice(C.lastIndexOf(".")+1),_=k(()=>P.write(i,L+o)),D=k(()=>P.write(i,L-o));if(!_||!D){b.push(`${A.name} ${E}`);continue}f.push({id:C,def:P,now:L,point:A,axis:E}),h.push([_,D]),v(_),v(D)}let R=new Map,M=A=>{let C=A.join("");if(R.has(C))return;let P=k(()=>f.reduce((L,E,_)=>E.def.write(L,E.now+A[_]*o),i));R.set(C,P),P&&v(P)};f.length>1&&d.forEach((A,C)=>{let P=h.map(([L,E])=>L[C]-m[C]>=E[C]-m[C]?1:-1);Number.isFinite(m[C])&&(M(P),M(P.map(L=>-L)))});let S=[...R.values()].filter(A=>!A).length;S&&b.push(`${S} of ${R.size} corners`);let w=u.map(A=>{let C={key:A.key,role:A.role,name:ht(A.metric)+ja(A.at,A.metric,a),unit:A.metric.unit==="-"?"":A.metric.unit,...A.hold?{limit:{op:A.hold.op,limit:A.hold.limit,...A.hold.limit2!==void 0?{limit2:A.hold.limit2}:{}}}:{}},P=d.indexOf(A);if(P<0)return{...C,value:NaN,lo:NaN,hi:NaN,skipped:"read off a lap"};let L=m[P],E=Number.isFinite(L)?y[P]:NaN,_=Number.isFinite(L)?x[P]:NaN,D=h.map(([B,z])=>Math.max(Math.abs(B[P]-L),Math.abs(z[P]-L))),I=D.filter(Number.isFinite).reduce((B,z)=>B+z,0),V;if(I>0){let B=D.indexOf(Math.max(...D.filter(Number.isFinite)));V={point:f[B].point.name,axis:f[B].axis,share:D[B]/I}}let O=A.hold?Math.max(Io(A.hold,E),Io(A.hold,_)):void 0;return{...C,value:L,lo:E,hi:_,...V?{most:V}:{},...O!==void 0?{excess:O}:{}}}),F=new Set(c.flatMap(A=>A.coords)),T=a.variables.filter(A=>!DD(A.id).length&&!F.has(A.id)).length;return{mm:o,points:c,rows:w,evaluations:g,unsolved:b,settings:T}}function B1(e){if(!e.chassis)return e;let{chassis:t,...r}=e;return t.boxes.length?{...r,chassis:{boxes:t.boxes}}:r}var KAe=180/Math.PI;var Ez={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:Aa,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 gCe=Ez.id;var Au=.02;function WD(e){let t=Math.max(Au,Math.abs(e.heaveMotionRatio)),r=Math.max(Au,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 _z=(e,t)=>({od:t,id:Math.min(e.id,t-.5)}),Nz=(e,t)=>e/(2*t*t);function YD(e,t){switch(e.kind){case"ubar":case"blade":case"torsionTube":return{...e,section:_z(e.section,t)};default:return e}}function jD(e,t,r){let n=Math.max(Au,Math.abs(r));if(e?.kind==="coil"){let l=Nz(t,n),u=e.rate;if(typeof u=="number")return{...e,rate:l};let d=Wn(u,0);if(!(d>0))return{...e,rate:l};let p=l/d;return{...e,rate:{...u,y:u.y.map(m=>m*p)}}}let o=t/(n*n),a=e&&(e.kind==="ubar"||e.kind==="blade"||e.kind==="torsionTube")?e:{kind:"torsionTube",section:{od:20,id:16},length:400,leverArm:60,G:8e4},s=l=>al(YD(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 YD(a,c)}function UD(e,t,r,n){let o=e?.design,a=jD(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 Oz=Math.PI/180,Jf=1e-6;function Vz(e){return!(Pe(e.rockerPivotA,e.rockerPivotB)<Jf||Pe(e.rockerToPushrod,e.rockerPivotA)<Jf||Pe(e.rockerToDamper,e.rockerPivotA)<Jf||Pe(e.rockerToDamper,e.damperChassis)<Jf)}function ZD(e){if(!Vz(e.hardpoints))return!1;let t={...e,config:{...e.config,actuation:"rocker"}};try{let r=wt(t);for(let n of[-20,-1,0,1,20]){let o=Ae(r,n,0);if(!o.ok||!Number.isFinite(o.state.metrics.damperLength))return!1}return!0}catch{return!1}}function JD(e){if(e.config.actuation!=="direct"||ZD(e))return;let{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}=$z(e);return{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}}var XD=40;function eh(e,t={}){let r=e.hardpoints,n=r.pushrodOuter,o=r.damperChassis,a=Pe(n,o),s=oe(n,X(H(o,n),Bz)),i=t.armRod??Math.max(25,.15*a),c=t.armDamper??i,l=[s[0]-XD,s[1],s[2]],u=[s[0]+XD,s[1],s[2]],d=te(H(u,l)),p=H(n,s),m=te(H(p,X(d,qD(p,d)))),f=sr(m,d,(t.armAngleDeg??60)*Oz),h=oe(s,X(f,i)),b=H(o,s),g=te(H(b,X(d,qD(b,d)))),y=X(te(le(d,g)),t.damperSide??1),x=oe(s,X(y,c));return{...r,rockerPivotA:l,rockerPivotB:u,rockerToPushrod:h,rockerToDamper:x}}var Bz=.72,qD=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2];function QD(e){let t=ct(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 $z(e,t={}){let r=t.target??QD(e),n=t.armAngleDeg,o=eh(e,{armAngleDeg:n});if(!(r>0))return o;let a=Pe(e.hardpoints.pushrodOuter,e.hardpoints.damperChassis),s=Math.max(25,.15*a),i=(()=>{for(let m of[1,-1]){let f=eh(e,{armRod:s,armAngleDeg:n,damperSide:m}),h={...e,config:{...e.config,actuation:"rocker"},hardpoints:f};try{let b=wt(h),g=Ae(b,15,0),y=Ae(b,-15,0);if(g.ok&&y.ok&&g.state.metrics.damperLength<y.state.metrics.damperLength)return m}catch{}}return 1})(),c=(m,f)=>{try{return QD({...e,config:{...e.config,actuation:"rocker"},hardpoints:eh(e,{armRod:m,armAngleDeg:n,armDamper:f,damperSide:i})})}catch{return Number.NaN}},l=[1,.6,.35,.2,1.7,2.6].map(m=>Math.max(12,s*m)),u=s,d=s,p=1/0;for(let m of l){let f=.25*m,h=6*m,b=m;for(let y=0;y<24;y++){let x=(f+h)/2,v=c(m,x);if(!Number.isFinite(v))break;b=x,v<r?f=x:h=x}let g=Math.abs(c(m,b)-r);if(Number.isFinite(g)&&g<p&&(p=g,u=m,d=b),p<1e-4*Math.max(1,r))break}return eh(e,{armRod:u,armAngleDeg:n,armDamper:d,damperSide:i})}var LCe=Array.from({length:19},(e,t)=>-45+5*t);var DCe=Math.PI/180;function Gz(e){let t=e.hardpoints,r=te(H(t.rockerPivotB,t.rockerPivotA)),n=Fn(t.rockerToDamper,t.rockerPivotA,r),o=.6*qr(H(t.rockerToDamper,n)),a=le(r,Hv),s=qr(a)>1e-6?te(a):te(H(t.rockerToDamper,n));return{outer:oe(n,X(s,o)),inner:oe(n,X(s,-o)),attach:"rocker"}}var Kz=(e,t)=>({...e,config:{...e.config,actuation:t}});function K1(e,t,r,n){let o=r==="front"?e.front:e.rear,a=Cd(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=da(e,t)[r]??re(t,r==="front"?"arb_front":"arb_rear"),u=qs(e,t)[r]??re(t,r==="front"?"heave_spring_front":"heave_spring_rear"),d=JD(o),p=Kz(d?{...o,hardpoints:{...o.hardpoints,...d}}:o,"decoupled"),m=r==="front"?t.heaveFrontDesign:t.heaveRearDesign,f=n?.heave??eE(m?.linkage,w=>Ho(p,w).atDesign)??bb(p,"rockerToRocker"),h=!c||c.design.kind==="none"||c.design.kind==="coil",b=h?"coil":"ubar",g=c?.linkage&&(c.design.kind==="none"||c.linkage.attach!=="rocker")?c.linkage:void 0,y=n?.roll??eE(h?g:c?.linkage,w=>xs(p,w,{kind:b}).atDesign)??(h?Gz(p):HA(p)),x=Ho(p,f).atDesign,v=xs(p,y,{kind:b}).atDesign,k=Td(e,t),R=WD({cornerWheelRate:s,cornerDamper:i,arbWheelRate:l,heaveWheelRate:u,heaveWheelDamping:r==="front"?k.heaveFront:k.heaveRear,rollWheelDamping:r==="front"?k.rollFront:k.rollRear,heaveMotionRatio:x,rollMotionRatio:v}),M=!c||c.design.kind==="none"?{design:{kind:"coil",rate:1},linkage:y}:{...c,linkage:y},S=UD({design:m?.design??{kind:"none"},linkage:f,damper:m?.damper},M,R,v);return d?{...S,crank:d}:S}function eE(e,t){return e&&Math.abs(t(e))>=Au?e:void 0}var th=[{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"]}],H1=()=>({arbFront:void 0,arbRear:void 0,heaveFront:void 0,heaveRear:void 0}),Hz={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]}},zz={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]}},Yz=()=>({outer:[0,189,486],attach:"rocker",mount:{kind:"chassis",anchor:[-225,0,486]}}),Wz={rate:60,motionRatio:1},jz={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]}},Uz=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]}},Xz={kind:"coil",rate:1560,motionRatio:1,gap:0,bothWays:!0},qz=40,Qz={rockerPivotA:[50,130,440],rockerPivotB:[-50,130,440],rockerToPushrod:[10,170,460],rockerToDamper:[-20,64,440],damperChassis:[-20,64,215]},tE=()=>({outer:[-50,130,480],attach:"rocker",shaftStation:-50}),rE=()=>({outer:[50,130,400],inner:[50,130,480],attach:"rocker",shaftStationOuter:50,shaftStationInner:50}),Zz=e=>[e[0],e[1],e[2]];function Jz(e){let t=r=>({...r,hardpoints:{...r.hardpoints,...oE(Qz)},config:{...r.config,actuation:"decoupled"}});return{...e,front:t(e.front),rear:t(e.rear)}}function oE(e){return Object.fromEntries(Object.entries(e).map(([t,r])=>[t,Zz(r)]))}function aE(e,t=Da(),r=e==="pull"?zz:Hz){let n=(o,a)=>({...o,hardpoints:{...o.hardpoints,...oE(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 rh(e,t){let r=z1(e),n=Ni(e);if(e==="heave")return{meta:r,vehicle:n,components:{...H1(),heaveFront:{design:{...E0,...Wz},linkage:Yz()}}};if(e!=="decoupled")return{meta:r,vehicle:n,components:H1()};let o=K1(n,t,"front",{heave:tE(),roll:rE()}),a=K1(n,t,"rear",{heave:tE(),roll:rE()});return{meta:r,vehicle:n,components:{arbFront:o.arb,arbRear:a.arb,heaveFront:o.heave,heaveRear:a.heave}}}function Ni(e){let{name:t}=z1(e);if(e==="direct")return{...Kl(),name:t};if(e==="mcpherson"){let n=Hl(),o=Ep();return{...n,front:{...o,config:{...o.config,loadedRadius:n.front.config.loadedRadius}},name:t}}let r=e6(aE(e==="pullrod"?"pull":"push"));return{...e==="decoupled"?Jz(r):r,name:t}}var nE={front:221.7,rear:220.9};function e6(e){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:nE.front}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:nE.rear}}}}function z1(e){let t=th.find(r=>r.id===e);if(!t)throw new Error(`Unknown suspension template: ${e}`);return t}function nh(){let e=t=>({design:{...Xz},linkage:Uz(t),damper:qz});return{meta:z1("heave"),vehicle:aE("push",Zy(),jz),components:{...H1(),heaveFront:e("front"),heaveRear:e("rear")}}}var sE=[10,25,50,100,200,300],t6=[{id:"c1",label:"Soft",scale:.7},{id:"c2",label:"Medium",scale:1},{id:"c3",label:"Firm",scale:1.4}],iE=e=>Math.round(e*100)/100;function r6(e,t,r){let n=sE.map(o=>iE(r*o));return{id:e,label:t,speedMmS:[...sE],bumpN:n,reboundN:[...n]}}function n6(e){return{name:e.name,body:{...e.body},curves:t6.map(t=>r6(t.id,t.label,iE(e.coefficient*t.scale)))}}function wu(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 kn(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:Xl[e.dampers.length%Xl.length],model:n6(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 $t=e=>`${e} (typical)`,Y1={car:{name:$t("Formula Student damper"),coefficient:2.5,body:{extended:249,stroke:55}}},oh={car:Y1.car,heave:{name:$t("Formula Student heave damper"),coefficient:3.4,body:{extended:270,stroke:47}},roll:{name:$t("Formula Student roll damper"),coefficient:3.7,body:{extended:322,stroke:100}}},ah={car:{name:$t("Formula 1 damper"),coefficient:6,body:{extended:240,stroke:40}},heave:{name:$t("Formula 1 heave damper"),coefficient:40,body:{extended:240,stroke:40}}},cE={car:{name:$t("GT damper"),coefficient:4.5,body:{extended:510,stroke:80}}},W1={car:{name:$t("Sports car damper"),coefficient:2.4,body:{extended:515,stroke:110}}},lE={car:{name:$t("Sports car strut"),coefficient:2.4,body:{extended:310,stroke:120}},rear:W1.car},uE={car:{name:$t("Cup car strut"),coefficient:4,body:{extended:285,stroke:75}},rear:{name:$t("Cup car rear damper"),coefficient:3.5,body:{extended:505,stroke:80}}},mE={car:{name:$t("Stock car front damper"),coefficient:7.5,body:{extended:555,stroke:110}},rear:{name:$t("Stock car rear damper"),coefficient:6.75,body:{extended:555,stroke:110}}},dE={car:{name:$t("Hill-climb front damper"),coefficient:3,body:{extended:285,stroke:65}},rear:{name:$t("Hill-climb rear damper"),coefficient:3.5,body:{extended:285,stroke:65}}},pE={car:{name:$t("Race truck front damper"),coefficient:12,body:{extended:780,stroke:160}},rear:{name:$t("Race truck rear damper"),coefficient:8.5,body:{extended:780,stroke:160}}};var _o=(e,t)=>({diameter:e*25.4,width:t*25.4,offset:20,wall:4}),Oi=e=>({front:e,rear:e}),j1=Oi(_o(13,7)),fE=Oi(_o(18,12)),hE=Oi(_o(18,10)),bE=Oi(_o(17,8)),gE={rear:_o(17,8)},yE=Oi(_o(18,9)),xE=Oi(_o(18,12)),RE={front:_o(22.5,9)};function so(e,t){for(let r of e.suspensions){let n={...r.model.parts};for(let o of["front","rear"]){let a=t[o];a&&(n[o]={...n[o],rim:{...a}})}(n.front||n.rear)&&(r.model.parts=n)}}function Bi(e){return e.vehicles=e.vehicles.slice(0,1),e.activeVehicleId=e.vehicles[0]?.id??null,e}function No(e,t){let r=ql(e);return r.meta.rulesetId=t,r}function Za(e,t,r,n){let o=No(e,t);return o.suspensions=[{...o.suspensions[0],model:n()}],o.vehicles=[Sx(r,"v1",0)],o.activeVehicleId="v1",o}var[,o6,a6,s6,i6,c6,l6,u6]=sx;function U1(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 vE(){return{...Ni("decoupled"),name:Da().name}}var m6=[{label:"Formula Student (decoupled)",vehicle:vE,components:e=>wu(rh("decoupled",e).components,oh)},{label:"Formula 1 (third springs)",vehicle:()=>nh().vehicle,components:()=>wu(nh().components,ah)}],X1={"direct-coilover":"direct",pushrod:"pushrod",pullrod:"pullrod","third-spring":"heave","mcpherson-strut":"mcpherson"},d6=[...m6.map(e=>e.vehicle),...Object.values(X1).map(e=>()=>Ni(e))];function Vi(e){let t=wu(rh("decoupled",e.vehicles[0].params).components,oh);e.suspensions=[{...e.suspensions[0],model:vE()}];for(let r of e.vehicles)U1(r.params,t);return kn(e,oh),so(e,j1),e}var Ja={title:"OpenStreetMap",url:"https://www.openstreetmap.org/copyright",licence:"ODbL-1.0",credit:"\xA9 OpenStreetMap contributors"},sh={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"},kE={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]"},ME={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"},p6={id:"cota",name:"Circuit of the Americas, Austin",address:"e0c6ea889d708cf15f9c",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,sh,ME]}},f6={id:"laguna-seca",name:"Laguna Seca, Monterey",address:"185b5811b9c423ef44ef",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,sh,ME]}},h6={id:"nordschleife",name:"Nordschleife, N\xFCrburg",address:"74c49603c7b2f15985c6",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,kE]}},b6={id:"brands-hatch",name:"Brands Hatch, Kent",address:"c4953e3c25eaba4a5b7e",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,{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."}]}},g6={id:"bristol",name:"Bristol, Tennessee",address:"f0e23953669a414ad600",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,sh]}},y6={id:"pikes-peak",name:"Pikes Peak, Colorado",address:"3de137fe33b5c2875036",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,sh]},standingStart:!0},x6={source:"venue",altitudeM:3580,pressure:{kind:"standard"},humidityPct:0},R6=10,v6={id:"nurburg-sprint",name:"Sprintstrecke, N\xFCrburg",address:"1875636cdbb615aa2756",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,kE]}};function es(e,t){let{id:r,name:n,address:o,provenance:a,standingStart:s}=t,i={kind:"catalogue",id:r,address:o},c=zl(bx({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 Oo(e,t,r){let n=e.vehicles[0].params,o=`m${e.motors.length+1}`;e.motors=[...e.motors,{id:o,color:To[e.motors.length%To.length],model:t}];let a=mw({},{...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 k6=3.8,ih={hubPlanetary:14.5,inboardChain:4,engineChain:3.4},M6="Hub motor, 35 kW (example)";function q1(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 SE(e){let t=e.motors.find(r=>r.id==="m1");return t.model={...t.model,name:M6},t.id}function ch(e,t,r){let n=Bi(Vi(No(e,r)));return n.vehicles[0].params.name=t,n}function S6(){let e=ch("Formula Student combustion car","Formula Student combustion","fs-cv");Oo(e,mx(),ih.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 A6(){let e=ch("Formula Student AWD car","Formula Student AWD","fs-ev");return q1(e,SE(e),4,"awd",ih.hubPlanetary,"hub"),e}function w6(){let e=ch("Formula Student RWD hub-motor car","Formula Student RWD hub motors","fs-ev");return q1(e,SE(e),2,"rear",ih.hubPlanetary,"hub"),e}function C6(){let e=ch("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:To[e.motors.length%To.length],model:ux()}],q1(e,t,1,"rear",ih.inboardChain),e.vehicles[0].params.driveline={rear:structuredClone(Jt.clutch)},e}function F6(){let e=Bi(Vi(No("Formula Student endurance energy","fs-ev"))),t=e.vehicles[0],r=structuredClone(t);if(r.id="v2",r.color=Ul[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 T6(){let e=nh(),t=Za("Formula 1 car","trackday",o6,()=>e.vehicle);return U1(t.vehicles[0].params,wu(e.components,ah)),kn(t,ah),so(t,fE),Oo(t,dx(),k6),es(t,p6)}function AE(e="GT car",t=Kl){let r=Za(e,"trackday",a6,t);return kn(r,cE),so(r,hE),Oo(r,nT(),r.vehicles[0].params.gear_ratio.value),es(r,f6)}function wE(e="Sports car",t=Hl,r=W1,n=bE){let o=Za(e,"trackday",s6,t);return kn(o,r),so(o,n),Oo(o,oT(),o.vehicles[0].params.gear_ratio.value),es(o,h6)}function P6(){let e=Za("Cup car","trackday",i6,YF);return kn(e,uE),so(e,yE),Oo(e,aT(),e.vehicles[0].params.gear_ratio.value),es(e,b6)}function L6(){let e=Za("Stock car","trackday",c6,WF);return kn(e,mE),so(e,xE),Oo(e,sT(),e.vehicles[0].params.gear_ratio.value),es(e,g6)}function D6(){let e=Za("Hill-climb prototype","trackday",l6,jF);return kn(e,dE),Oo(e,iT(),e.vehicles[0].params.gear_ratio.value),e.settings.air=structuredClone(x6),e.settings.airTempC=R6,es(e,y6)}function E6(){let e=Za("Race truck","trackday",u6,UF);return kn(e,pE),so(e,RE),Oo(e,cT(),e.vehicles[0].params.gear_ratio.value),es(e,v6)}function I6(e){let t=th.find(o=>o.id===e);if(e==="direct")return AE(t.name,()=>Ni(e));if(e==="mcpherson")return wE(t.name,()=>Ni(e),lE,gE);let r=Bi(No(t.name,"trackday")),n=rh(e,r.vehicles[0].params);return r.suspensions=[{...r.suspensions[0],model:n.vehicle}],U1(r.vehicles[0].params,n.components),kn(r,Y1),so(r,j1),r}function Cu(e,t,r){let n=X1[e],o=th.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:()=>I6(n)}}var _6=[{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:()=>Vi(No("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:F6},{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:()=>Bi(Vi(No("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:S6},{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:A6},{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:w6},{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:C6},{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:T6},{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:AE},{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:wE},{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:P6},{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:L6},{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:D6},{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:E6},{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:()=>Bi(Vi(No("Suspension study","trackday")))},Cu("direct-coilover","The GT car\u2019s wishbones driving coilovers straight into the towers, at Laguna Seca.","On the GT car, at Laguna Seca."),Cu("pushrod","The FS car on pushrods: a rod from each lower wishbone works a rocker.","On the Formula Student car, at FSG."),Cu("pullrod","The FS car on pullrods: a rod from each upper wishbone pulls a low rocker.","On the Formula Student car, at FSG."),Cu("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."),Cu("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:()=>Bi(Vi(No("Tyre study","fs-ev")))}],CE=_6.map(e=>({...e,load:()=>Ax(e.load())}));var FE={width:320,height:200},yFe=[.6*FE.width-9,.6*FE.height-9];var TE=new WeakMap,PE=new WeakMap,Q1=e=>JSON.stringify(e,(t,r)=>r===1/0?"Infinity":r);function LE(e,t){if(!t){let a=TE.get(e);return a||(a=pr(e),TE.set(e,a)),a}let r=PE.get(e);r||(r=new Map,PE.set(e,r));let n=Q1(t),o=r.get(n);return o||(r.size>=4&&r.clear(),o=pr(e,t),r.set(n,o)),o}var V6=Math.PI/180,B6=e=>e>1?e/100:e;function Fu(e){let t=null;return()=>(t??={v:e()}).v}function DE(e){let t=ct(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 EE=new WeakMap,Z1={heave:0,pitch:0,roll:0,steer:0},IE=[0,1,2,3,4],_E=[-20,-10,0,10,20];function OE(e,t){let r=jn(e,Z1),n=["front","rear"],o=c=>{let l=js(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 IE){let l=c===0?null:jn(e,{...Z1,roll:c*V6});n.forEach((u,d)=>{let p=l?js(l[u]):null,m=p&&Number.isFinite(a[d]);s[d].rc.push(m?t[d]+(p.left+p.right)/2-a[d]:t[d]),s[d].split.push(m?(p.left-p.right)/2:0)})}let i=n.map(()=>[]);for(let c of _E){let l=c===0?null:jn(e,{...Z1,heave:-c});n.forEach((u,d)=>{let p=l&&l[u].valid&&r[u].valid;i[d].push(p?t[d]+l[u].height-r[u].height:t[d])})}return{roll:{rollDeg:IE,rcFront:s[0].rc,rcRear:s[1].rc,rcSplitFront:s[0].split,rcSplitRear:s[1].split},heave:{drop:_E,rcFront:i[0],rcRear:i[1]}}}var NE=new WeakMap;function $6(e,t,r,n){let o=NE.get(e);o||(o=new Map,NE.set(e,o));let a=`${Q1(r)}|${n[0]}|${n[1]}`,s=o.get(a);if(!s){o.size>=4&&o.clear();try{s=OE(LE(e,r),n)}catch{s=t.rigidMigration(n)}o.set(a,s)}return s}function G6(e){let t=EE.get(e);if(t)return t;let r=pr(e),n=jn(r,{heave:0,pitch:0,roll:0,steer:0}),o=DE(e.front),a=DE(e.rear),s={wheelbase:e.config.wheelbase,trackFront:qt(e.front),trackRear:qt(e.rear),mrFront:o.motionRatio,mrRear:a.motionRatio,wheelRateFront:o.wheelRate,wheelRateRear:a.wheelRate,unsprungCgHeight:e.front.config.loadedRadius,rcHeightFront:n.front.valid?n.front.heightAboveGround:0,rcHeightRear:n.rear.valid?n.rear.heightAboveGround:0,rcGainFront:Xs(n.front),rcGainRear:Xs(n.rear),rigidMigration:i=>OE(r,i),kinFront:Fu(()=>Ps(e.front)),kinRear:Fu(()=>Ps(e.rear))};return EE.set(e,s),s}function VE(e,t,r,n){let o=G6(e),a=da(e,t),s=qs(e,t),i=ow(e,t),c=Td(e,t),l=aw(e,t),u=sw(t),d=Pd(e,t),p=ma(e.front),m=ma(e.rear),f=ua(t.damperModel,t.damperSetup,o.mrFront,o.mrRear,t.damperModelRear??t.damperModel),h={rho:t.rho.value,area:t.A.value,cl:t.c_l.value,cw:t.c_w.value,copLongFront:1-Math.max(0,Math.min(1,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=B6(t.front_mass_diss.value),y=ba(t,r,n),x=Ke(y.front),v=y.rear===y.front?x:Ke(y.rear),k=n??t.tireModelRear??r,R=t.m.value*b*g/2,M=t.m.value*b*(1-g)/2,S=x.corneringStiffness(R),w=v.corneringStiffness(M),F=(r?x.verticalStiffness():0)||re(t,"tire_vertical_rate"),T=(k?v.verticalStiffness():0)||re(t,"tire_vertical_rate"),A=on(r)??0,C=on(k)??0,P=_d({freeRadius:A,staticLoad:R,tyreRate:F,surveyed:e.front.config.loadedRadius},{freeRadius:C,staticLoad:M,tyreRate:T,surveyed:e.rear.config.loadedRadius},g),L=Mr(A,R,F,e.front.config.loadedRadius),E=Mr(C,M,T,e.rear.config.loadedRadius),_=[Un(o.rcHeightFront,o.rcGainFront,e.front.config.loadedRadius,L),Un(o.rcHeightRear,o.rcGainRear,e.rear.config.loadedRadius,E)],D=Fu(()=>ul(o.kinFront(),re(t,"camber_front_deg"))),I=Fu(()=>ul(o.kinRear(),re(t,"camber_rear_deg"))),V=Fu(()=>$6(e,o,wi(z),_)),O=Bc({...t,wheelbase:{...t.wheelbase,value:o.wheelbase}}),B=ll(t),z={massTotal:t.m.value,frontMassFrac:g,steeringSystem:t.steeringSystem,tv:fd(t),cgHeight:Qs(re(t,"cg_height"),t.cgReference?.standingRadius,P),cgStandingRadius:P,wheelbase:o.wheelbase,trackFront:o.trackFront,trackRear:o.trackRear,wheelRateFront:p?0:o.wheelRateFront,wheelRateRear:m?0:o.wheelRateRear,decoupledFront:p,decoupledRear:m,...u.front?{elementLinkagesFront:u.front}:{},...u.rear?{elementLinkagesRear:u.rear}:{},...d.front.source==="part"?{cornerCoiloverFront:d.front.coilover}:{},...d.rear.source==="part"?{cornerCoiloverRear:d.rear.coilover}:{},...d.heaveFront.coilover?{heaveCoiloverFront:d.heaveFront.coilover}:{},...d.heaveRear.coilover?{heaveCoiloverRear:d.heaveRear.coilover}:{},...i.front&&!p?{heaveSeatFront:i.front}:{},...i.rear&&!m?{heaveSeatRear:i.rear}:{},...d.rollFront.coilover?{rollCoiloverFront:d.rollFront.coilover}:{},...d.rollRear.coilover?{rollCoiloverRear:d.rollRear.coilover}:{},tireRate:F,...T!==F?{tireRateRear:T}:{},tireDamping:re(t,"tire_vertical_damping"),arbFront:a.front??re(t,"arb_front"),arbRear:a.rear??re(t,"arb_rear"),brakeBalanceFront:O.balanceFront,brakes:O,...B?{driveline:B}:{},heaveSpringFront:s.front??re(t,"heave_spring_front"),heaveSpringRear:s.rear??re(t,"heave_spring_rear"),unsprungPerCorner:re(t,"unsprung_mass"),unsprungCgHeight:Mr(A,R,F,o.unsprungCgHeight),tyreFreeRadius:A,...C!==A?{tyreFreeRadiusRear:C}:{},rcHeightFront:_[0],rcHeightRear:_[1],corneringStiffnessFront:S,corneringStiffnessRear:w,get kinFront(){return D()},get kinRear(){return I()},damperFront:p?0:f?.front?.rate??re(t,"damper_front")*o.mrFront*o.mrFront,damperRear:m?0:f?.rear?.rate??re(t,"damper_rear")*o.mrRear*o.mrRear,...f?.front&&!p?{damperCurveFront:f.front.curve}:{},...f?.rear&&!m?{damperCurveRear:f.rear.curve}:{},heaveDamperFront:l.heaveFront?.rate??c.heaveFront,heaveDamperRear:l.heaveRear?.rate??c.heaveRear,rollDamperFront:l.rollFront?.rate??c.rollFront,rollDamperRear:l.rollRear?.rate??c.rollRear,...l.heaveFront?{heaveDamperCurveFront:l.heaveFront.curve}:{},...l.heaveRear?{heaveDamperCurveRear:l.heaveRear.curve}:{},...l.rollFront?{rollDamperCurveFront:l.rollFront.curve}:{},...l.rollRear?{rollDamperCurveRear:l.rollRear.curve}:{},unsprungCornerMass:re(t,"unsprung_mass"),get rollCentreCurve(){return V().roll},get rcHeaveCurve(){return V().heave},aero:h,yawInertia:re(t,"I_yaw"),rollInertia:re(t,"I_roll"),pitchInertia:re(t,"I_pitch"),...la(t)?{chassisTorsion:la(t)}:{},...Qc(t,"front")?{twistInertiaFront:Qc(t,"front")}:{},...Qc(t,"rear")?{twistInertiaRear:Qc(t,"rear")}:{},get steerFront(){return Ld(e.front,L)},ackermannPct:re(t,"ackermann_pct"),toeFrontDeg:re(t,"toe_front_deg"),toeRearDeg:re(t,"toe_rear_deg")};return z}var $E=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}),ev={ggvMode:"twoTrack"},BE=new WeakMap;function tv(e,t=ev){let r=BE.get(e.vehicle);r||BE.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={...$E(e.params),suspensionOf:()=>e.vehicle};n.set(o,a=Qa(e.params,s,t))}return a}var GE=(e=ev)=>t=>tv(t,e),lh=(e=ev)=>t=>VE(t.vehicle,T1(t.params,$E(t.params),e),t.params.tireModel,t.params.tireModelRear);function K6(e,t){return tv(e,t.switches)}var rv=e=>gr(e?.rulesets);function KE(e,t,r,n,o={},a=()=>r.standingStart){let s=tv(n,r.switches),i=(l,u)=>{let d=Ap(l,t,{racingLine:r.racingLine,params:s});return{asset:d.asset,numerics:d.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 HE=e=>[...new Set(e.lap.courses.flatMap(t=>t.course.kind==="track"?[t.course.trackId]:[]))],zE=e=>{let t=e?.session;return t?{sessionParams:r=>K6(r,t),session:()=>t}:{}},Pu=e=>({metrics:rv(e),assemble:lh(e?.switches),simParams:GE(e?.switches),projectTrack:()=>e?.course??null,libraryTrack:t=>e?.tracks?.[t]??null,numerics:e?.numerics,...zE(e)}),H6=(e,t)=>({density:e.density,envelope:e.envelope,states:e.states,operating:e.operating,assemble:lh(t)}),z6=(e,t)=>({...H6(e,t?.switches),lap:e.lap,simParams:GE(t?.switches),projectTrack:()=>t?.course??null,libraryTrack:r=>t?.tracks?.[r]??null,numerics:t?.numerics,...zE(t)}),YE="nelder-mead",WE=600,Tu=[0,.15,.15];function jE(e,t,r,n=Tu.length){let o=av(t);return Tu.slice(0,Math.max(1,n)).map((a,s)=>({...e,seed:s+1,startJitter:a,car:o,...r?{lap:r}:{}}))}function UE(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 XE(e,t,r,n,o=.01){let a=rv(n).byId;return Y6(e,t,r,n).filter(s=>s.excess>-o*(a[s.metricId]?.scale??1))}function Y6(e,t,r,n){let o;try{o=Lo(_i(e,t,r),z6(t,n))}catch{return[]}return W6(o,t,rv(n))}function W6(e,t,r){let n=[];for(let o of t.constraints){let a=r.byId[o.metricId];if(!a)continue;let s=Rt(e,a,o.at);if(!Number.isFinite(s))continue;let i=`${ht(a)}${ja(o.at,a)}`;n.push({key:o.key,metricId:o.metricId,label:i,unit:a.unit==="-"?"":a.unit,value:s,excess:Io(o,s)})}return n}var j6=.05;function U6(e,t){if(t.id.startsWith("hp.")||$f(t.id))return 1;let r=/^rocker\.(front|rear)\.(\w+)$/.exec(t.id);if(r){let a=r[1]==="front"?e.vehicle.front:e.vehicle.rear;return s1(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 n1(oo(o.hardpoints,n[2]),n[3],1)}function qE(e,t,r){let n=r.filter(p=>p.score.feasible);if(n.length<2)return null;let o=t.map(p=>U6(e,p)),a=o.every(p=>p!==null)?"mm":null,s=0,i="",c=0,l=n.reduce((p,m)=>m.score.total<p.score.total?m:p);for(let p of n)if(p!==l)for(let m=0;m<t.length;m++){let f=Math.abs(p.x[m]-l.x[m])*(o[m]??1);c+=f*f,f>s&&(s=f,i=t[m].name)}let u=n.map(p=>p.score.total),d=l.score.terms.reduce((p,m)=>p+(m.resolution??0),0);return{distance:Math.sqrt(c),worst:s,worstName:i,scoreSpread:Math.max(...u)-Math.min(...u),tolerance:Math.max(j6,d),unit:a}}var X6={steeringSystem:!0,brakeSetup:!0,driveline:!0,heaveFrontDesign:!0,heaveRearDesign:!0,arbFrontDesign:!0,arbRearDesign:!0},QE=e=>Object.hasOwn(X6,e);function J1(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 q6(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":QE(t)||J1(e)?"block":null}function nv(e,t){t=Bt(e,t);let r=bt(e);return[...t.variables,...t.followers??[]].filter(n=>r[n.id]&&!r[n.id].supersededBy&&!q6(n.id)).map(n=>ut(r[n.id]))}function uh(e,t,r){t=Bt(e,t);let n=bt(e),o=_i(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),[d,p,m,f]=c.id.split(".");if(d==="rocker"){let h=`${p}.rocker`;if(i.has(h))continue;i.add(h);let b=p==="front"?o.vehicle.front:o.vehicle.rear;for(let g of[vn.fore,vn.aft]){let y=b.hardpoints[g];for(let x=0;x<3;x++)a.push({kind:"hardpoint",axle:p,key:g,axis:x,value:y[x]})}}else if(d==="arm"){let h=`${p}.${m}`;if(i.has(h))continue;i.add(h);let b=p==="front"?o.vehicle.front:o.vehicle.rear,g=yr[m];for(let y of[g.fore,g.aft]){let x=b.hardpoints[y];for(let v=0;v<3;v++)a.push({kind:"hardpoint",axle:p,key:y,axis:v,value:x[v]})}}else if(d==="hp"&&Cr(c.id)){let h=`${p}.${m}`;if(i.has(h))continue;i.add(h);let b=(p==="front"?o.vehicle.front:o.vehicle.rear).hardpoints[m];for(let g=0;g<3;g++)a.push({kind:"hardpoint",axle:p,key:m,axis:g,value:b[g]})}else if(d==="hp")a.push({kind:"hardpoint",axle:p,key:m,axis:"xyz".indexOf(f),value:u});else if(d==="cfg")a.push({kind:"config",axle:p,field:m,value:u});else if(d==="kc"){if(s.has(`kc.${p}`))continue;s.add(`kc.${p}`);let h=p==="front"?o.vehicle.front:o.vehicle.rear;a.push({kind:"compliance",axle:p,value:h.compliance})}else if(d==="param")a.push({kind:"param",label:ut(l),value:u});else if(d==="brakeModel"){if(s.has(d))continue;if(s.add(d),!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(QE(d)||J1(c.id)){let h=J1(c.id)??d;if(s.has(h))continue;s.add(h);let b=o.params[h];if(!b)throw new Error(`optimiser: "${c.id}" left the car with no ${h} to adopt`);a.push({kind:"block",key:h,value:b})}else throw new Error(`optimiser: Adopt has no way to write "${c.id}" back into the project`)}return a}function ov(e){let t=performance.now(),r=Pu(e.lap),n=e.follow?g1(e.car,e.spec,r):e.spec,{dead:o,unprobed:a,...s}=v1(e.car,n,r);return{...s,deadIds:o.map(i=>i.id),unprobedIds:a.map(i=>i.id),elapsedMs:performance.now()-t,...e.follow?{followed:!0,fromCar:n===e.spec?null:{states:n.states,envelope:n.envelope}}:{}}}function ZE(e){let t=performance.now();return{tolerance:V1(e.car,e.spec,e.x,Pu(e.lap),e.mm),elapsedMs:performance.now()-t}}var av=e=>e.vehicle.chassis?{...e,vehicle:B1(e.vehicle)}:e;function JE(e,t){try{let r=sv(e.car,e.spec,e.lap),n=Es.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:Vr(r.variables),score:In(r,Vr(r.variables)),infeasible:0}});let o=e.from,a=o?{...r,variables:r.variables.map((u,d)=>({...u,start:Number.isFinite(o[d])?o[d]: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&&u1(r.variables)?d1(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 sv=(e,t,r)=>Ua(e,t,Pu(r));function eI(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),...tl(e,t.damper)}}function tI(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}:{}},...Fa(n)?{sessionAir:!0}:{}}}var mh=e=>({ggvMode:e.ggvMode,quasiTransient:e.quasiTransient===!0&&e.ggvMode!=="fast",motorThermal:e.motorThermal===!0,...kD({brakeFade:e.brakeFade===!0,airTempC:e.airTempC,diffYaw:e.diffYaw===!0,...e.air?{air:e.air}:{}})});function Q6(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 rI(e,t){let r=t.plannedPath!==void 0,n=Q6(t);return{...KE(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 ts(e,t){let r=e.vehicles.find(o=>o.id===t);if(!r)throw new Error(`this project holds no vehicle "${t}"`);let n=qa(e);return tI(structuredClone(F1(e,r.params)),structuredClone(r.params),eI(r.params,n),ao(e).air)}var Z6="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 iv(e,t,r,n){if(e.settings.pathPlanId)throw new Error(Z6);let o=ao(e),a=e.tracks.length?(await jf(e,t)).asset:null,s={};for(let i of n?HE(n):[]){let c=e.tracks.find(l=>l.id===i);c&&(s[i]=await Su(c,t))}return rI(r,{track:a,numerics:o.numerics,racingLine:o.racingLine,standingStart:o.standingStart,lapCounts:o.lapCounts??{},switches:mh(o),rulesets:e.rulesets??[],library:s,standingOf:i=>e.tracks.find(c=>c.id===i)?.standingStart===!0})}async function nI(e,t,r,n){let o=ts(e,r),a=Bt(o,n),s=await iv(e,t,o,a);return ov({id:0,car:o,spec:a,lap:s})}async function oI(e,t,r,n){let o=ts(e,r),a=Bt(o,n),s=nv(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 iv(e,t,o,a)}catch(l){return{problems:[l instanceof Error?l.message:String(l)]}}let c=R1(o,a,{...Pu(i),metrics:gr(e.rulesets)});return c.length?{problems:c}:{problems:[],msPerEval:ov({id:0,car:o,spec:a,lap:i}).msPerEval,carFingerprint:Sa(av(o))}}async function J6(e,t,r,n,o,a=[]){let s=jE(t,e,r,n),i=s.length*t.budget,c=null,l=[];for(let[u,d]of s.entries()){if(a.includes(d.seed))continue;await o?.tick();let p=[],m=null,f=null;if(JE(d,y=>{y.kind==="progress"?(p.push([y.progress.evaluations,y.progress.score.total]),y.progress.evaluations===0&&(c??=y.progress.score),o?.progress(u*t.budget+y.progress.evaluations,i)):y.kind==="done"?m={result:y.result,elapsedMs:y.elapsedMs}:f=y.message}),f)throw new Error(f);if(!m)throw new Error("the search stopped without a result");let{result:h,elapsedMs:b}=m,g={seed:d.seed,startJitter:d.startJitter,x:h.x,score:h.score,evaluations:h.evaluations,infeasible:h.infeasible,history:h.history,trace:p,elapsedMs:b,...h.snapped?{snapped:h.snapped}:{}};l.push(g),o?.progress((u+1)*t.budget,i),await o?.finished?.(g)}if(!c)throw new Error("the search never scored the starting design");return{method:t.method,budget:t.budget,designScore:c,runs:l}}async function aI(e,t,r,n){let o=ts(e,r.vehicleId),a=Bt(o,r.spec),s=nv(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 iv(e,t,o,a),c=r.method??YE;if(!Es.some(x=>x.name===c))throw new Error(`unknown method "${c}" \u2014 it is one of ${Es.map(x=>x.name).join(", ")}`);let l=r.budget??WE,u=Math.max(1,Math.min(r.seeds??Tu.length,Tu.length)),d=await J6(o,{spec:a,method:c,budget:l},i,u,n),p=sv(o,a,i),m=d.runs.map(x=>({seed:x.seed,startScore:d.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:UE(p.variables,x.x),constraints:XE(o,a,x.x,i),...x.snapped?{onSteps:{x:x.snapped.x,score:x.snapped.score.total,feasible:x.snapped.score.feasible,...x.snapped.score.reason?{reason:x.snapped.score.reason}:{},terms:x.snapped.score.terms}}:{}})),f=d.runs.reduce((x,v)=>Cc(v.score,x.score)?v:x),h=f.snapped?.score.feasible?f.snapped:null,b=h?h.x:f.x,g=r.tolerance??Zf,y=f.score.feasible&&g>0?ZE({id:0,car:o,spec:a,x:b,lap:i,mm:g}).tolerance:null;return{method:c,budget:l,seeds:m,spread:d.runs.length>1?qE(o,p.variables,d.runs.map(x=>({x:x.x,score:x.score}))):null,writes:uh(o,a,b),...f.snapped?{adopts:h?"on its steps":`as found: on its steps it breaks a hold (${f.snapped.score.reason??"not legal"})`}:{},...y?{asBuilt:y}:{}}}var eY=(e,t)=>e[t]??[],tY=(e,t,r)=>r<=1?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function dh(e){return e.kind==="param"?tY(e.start,e.end,Math.max(1,Math.round(e.steps))):e.kind==="part"?[...e.partIds]:[...e.values]}var sI=e=>e.kind==="param"?e.label:e.kind==="part"?`${e.part} model`:e.setting;function rY(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=Qa(structuredClone(r.params),qa(e),ao(e)),o=Aw(n,{geometry:!0}),a=Vd(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=Fo.find(l=>l.doc===i.part);if(!c)throw new Error(`"${i.part}" is not a library \u2014 it is one of ${Fo.map(l=>l.doc).join(", ")}`);for(let l of i.partIds)if(!eY(e,c.doc).some(u=>u.id===l))throw new Error(`the ${c.label} library holds no "${l}"`)}}if(t.holdBalance){let i=a.find(l=>l.key==="arb_front");if(t.axes.find(l=>l.kind==="param"&&l.label===i?.label))throw new Error(`holding the balance moves "${i.label}": it cannot also be an axis`)}let s=t.axes.reduce((i,c)=>i*dh(c).length,1)+(t.priceInMass?iI:0);if(s>wp)throw new Error(`that grid is ${s} runs, over the ${wp} cap \u2014 a run is a whole session. Drop an axis or use fewer steps.`)}var iI=3,cI=(e,t)=>({...Kf(),variables:[{id:e,lo:0,hi:2*t}]});function nY(e,t){let r=ts(e,t.vehicleId),n=Xf(r);if("why"in n)throw new Error(`the balance cannot be held: ${n.why}`);let o=lh(mh(ao(e,t.settings))),a=qf(Ua(r,cI(n.id,n.now),{assemble:o}),gr(e.rulesets));if("why"in a)throw new Error(`the balance cannot be held: ${a.why}`);return{target:a.target,metric:a.metric,assemble:o,bar:ut(n.def),unit:n.def.unit,now:n.now}}function oY(e,t,r){let n=ts(e,t),o=Xf(n);if("why"in o)return{value:NaN,balance:NaN,reached:!1};let a=cI(o.id,o.now),{x:s,held:i}=Qf(Ua(n,a,{assemble:r.assemble}),[o.now],{slot:0,target:r.target,metric:r.metric}),c=e.vehicles.find(l=>l.id===t).params;for(let l of uh(n,a,s))if(l.kind==="param")Zs(c,l.label,l.value);else if(l.kind==="block")Object.assign(c,{[l.key]:structuredClone(l.value)});else throw new Error(`a held balance has no way to write ${l.kind} back into the car`);return{value:i.value,balance:i.balance,reached:i.reached}}var lI=e=>e.map(t=>String(typeof t=="number"?Number(t.toPrecision(4)):t)).join(" \xD7 ");function aY(e,t){let r=[...new Set(e.flatMap(o=>(o.didNotFinish??[]).map(a=>a.label)))],n=e.map(o=>({name:lI(o.at),events:r.map(a=>({label:a,incomplete:o.didNotFinish?.find(s=>s.label===a)}))}));return CD(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`:D1(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 sY(e){let t=[[]];for(let r of e){let n=dh(r),o=[];for(let a of n)for(let s of t)o.push([...s,a]);t=o}return t}async function uI(e,t,r,n){rY(e,r);let o=sY(r.axes),a=o.length+(r.priceInMass?iI:0),s=r.holdBalance?nY(e,r):null,i=[],c=!1,l=0,u=async(h,b={})=>{let g=structuredClone(e),y=g.vehicles.find(F=>F.id===r.vehicleId),x={...r.settings},v={...b};h&&r.axes.forEach((F,T)=>{let A=h[T];if(F.kind==="param")v[F.label]=A;else if(F.kind==="part"){let C=Fo.find(P=>P.doc===F.part);y.params[C.ref]=A}else x[F.setting]=A}),Object.keys(v).length&&(y.params=L1(y.params,v));let k=s?oY(g,r.vehicleId,s):void 0,R=r.fleet?g.vehicles.filter(F=>F.visible||F.id===r.vehicleId).map(F=>F.id):[r.vehicleId],M=await Uf(g,t,{vehicleIds:R,settings:x});c=M.fleetScored;let S=M.vehicles.find(F=>F.id===r.vehicleId),w=S.events.flatMap(F=>F.incomplete?[{label:F.label,...F.incomplete}]:[]);return n?.(++l,a),{at:h??[],metrics:S.metrics,...w.length?{didNotFinish:w}:{},...k?{held:k}:{}}};for(let h of o)i.push(await u(h));let d;if(r.priceInMass){let h=ts(e,r.vehicleId),b=bt(h)[_1],g=b.read(h),y=N1*g,x=ut(b),v=await u(null),k=await u(null,{[x]:g+y}),R=await u(null,{[x]:g-y}),M=Object.fromEntries(Object.keys(v.metrics).map(S=>[S,(k.metrics[S]-R.metrics[S])/(2*y)]));d={car:v.metrics,perKg:M,dKg:y};for(let S of i)S.asKg=Object.fromEntries(Object.keys(S.metrics).map(w=>[w,O1(S.metrics[w],v.metrics[w],M[w])]))}let p=Object.keys(i[0]?.metrics??{}),m=[];r.axes.forEach((h,b)=>{if(dh(h).length<2)return;p.some(y=>{if(new Set(i.map(k=>`${k.at[b]}`)).size<2)return!1;let v=i.map(k=>k.metrics[y]).filter(Number.isFinite);return Math.max(...v)-Math.min(...v)>1e-9})||m.push(sI(h))});let f=[];if(c&&!r.fleet&&f.push("Points here were scored with this car alone, so it takes the maximum in every event and the points axis is flat by construction. Re-run with fleet: true to price a change in points."),f.push(...aY(i,c)),s&&ao(e,r.settings).ggvMode==="fast"&&f.push("The fast envelope is a point mass: no balance reaches its laps, so a held sweep runs the same laps as a loose one. Hold it on the full envelope (settings.ggvMode)."),s){let h=i.filter(b=>b.held&&!b.held.reached).map(b=>lI(b.at));h.length&&f.push(`No ${s.bar} between 0 and twice the car's holds TLLTD at ${s.target.toFixed(2)} % at ${D1(h.length>6?[...h.slice(0,6),"\u2026"]:h)}: those points ran with the bar at the end nearer it, so their balance is not the car's.`)}return d&&f.push(`As mass: each point's change from the car as it is, over what 1 kg moves it, read at \xB1${d.dKg.toFixed(1)} kg. Negative is as much as taking that many kilograms off. A metric the mass hardly moves prices at nonsense: read the lap and event times.`),m.length&&f.push(`Nothing moved along ${m.join(", ")}. Exactly zero is a wiring question before it is a finding: check that a library part is not superseding the value, and that the switch it needs is on.`),{axes:r.axes.map(h=>({kind:h.kind,label:sI(h),values:dh(h)})),runs:i,metricKeys:p,fleetScored:c,flat:m,caveats:f,...s?{hold:{bar:s.bar,unit:s.unit,now:s.now,tlltdPct:s.target}}:{},...d?{price:d}:{}}}function dI(){if(typeof process.threadCpuUsage!="function")return performance.now();let e=process.threadCpuUsage();return(e.user+e.system)/1e3}async function cY(e,t){let r=xD(e.root);switch(e.kind){case"sweep":return uI(e.doc,r,e.req,t);case"convergence":return FD(e.doc,r,{vehicleId:e.vehicleId,...e.steps?{steps:e.steps}:{},...e.tolPct!==void 0?{tolPct:e.tolPct}:{},onStep:t});case"study":return aI(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 Uf(e.doc,r,{...e.vehicleIds?{vehicleIds:e.vehicleIds}:{},...e.settings?{settings:e.settings}:{},...e.overrides?{overrides:e.overrides}:{}});case"probe":return nI(e.doc,r,e.vehicleId,e.spec);case"quote":return oI(e.doc,r,e.vehicleId,e.spec)}}if(mI){let e=mI,t=r=>e.postMessage(r);(async()=>{try{let r=await cY(iY,(n,o)=>t({type:"progress",done:n,total:o}));t({type:"done",result:r,cpuMs:dI()})}catch(r){t({type:"failed",message:r instanceof Error?r.message:String(r),cpuMs:dI()})}})()}export{cY as runJob,dI as threadCpuMs};
|
|
226
|
+
`)),this.name="RulesetDefError",this.problems=r}},El=e=>typeof e=="number"&&Number.isFinite(e),Dl=e=>El(e)&&e>0,hr=(e,t)=>e===void 0||t(e);function s5(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":Dl(a.distance)||r(`${s} needs a distance above zero, in metres`),hr(a.vStart,i=>El(i)&&i>=0)||r(`${s}'s entry speed must be zero or more`);break;case"constantRadius":Dl(a.radius)||r(`${s} needs a radius above zero, in metres`),hr(a.laps,i=>El(i)&&i>=1)||r(`${s} runs at least one lap`);break;case"trackLap":hr(a.laps,i=>El(i)&&i>=1)||r(`${s} runs at least one lap`),hr(a.distance,Dl)||r(`${s}'s distance must be above zero, in metres`),hr(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),hr(a.unit,i=>typeof i=="string")||r("Its unit is text",s),hr(a.over,i=>typeof i=="string")||r("Names its event by id",s),hr(a.format,i=>i==="time"||i==="points")||r("Is shown as a time, as points, or as a number",s),hr(a.max,El)||r("Its maximum is a number",s),hr(a.lowerBetter,i=>typeof i=="boolean")||r("Lower is better, or it is not",s),hr(a.hidden,i=>typeof i=="boolean")||r("Is hidden, or it is not",s)}hr(e.track?.minTurnRadius,Dl)||r("The tightest turn the rules allow is a radius above zero");let n=e.battery;for(let o of["packVoltageMax","segmentVoltageMax","powerLimitKw"])hr(n?.[o],Dl)||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 FF(e){let t=s5(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}=bp(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 yp(e){return FF(e).problems}var Ly=e=>Number.isFinite(e)?e:NaN;function i5(e){return e.unit&&e.format!=="time"?`${e.label} (${e.unit})`:e.label}function Co(e){let t=structuredClone(e),{plan:r,problems:n}=FF(t);if(!r)throw new gp(t.id,n);let o=new WeakMap,a=m=>{let f=o.get(m);return f||(f=Py(r,m),o.set(m,f)),f},s=new Map(t.kpis.map(m=>[m.key,m])),i=new Map;for(let[m,f]of Object.entries(t.score?.parts??{}))i.has(f)||i.set(f,m);let c=m=>(f,h)=>{if(!h)return NaN;let b=h.kpis?.[m];if(b!==void 0)return Ly(b);let g=h,y=i.get(m);return y!==void 0?Ly(g.parts?.[y]):m===t.score?.total?Ly(g.total):NaN},l=t.kpis.filter(m=>!m.hidden).map(m=>{let f=r.field.has(m.key);return{key:m.key,label:i5(m),lowerBetter:m.lowerBetter??!1,...m.format?{format:m.format}:{},...f?{field:!0}:{},value:f?c(m.key):h=>a(h)[m.key]}}),u=t.score,d=u?m=>{let f=Ll(r,m),h={};for(let[b,g]of Object.entries(f)){let y={},x={};for(let[v,k]of Object.entries(u.parts)){y[v]=g[k];let R=s.get(k)?.max;R!=null&&(x[v]=R)}h[b]={total:g[u.total],parts:y,...Object.keys(x).length?{maxima:x}:{},kpis:Object.fromEntries(t.kpis.map(v=>[v.key,g[v.key]]))}}return h}:void 0,p=d||(r.field.size>0?m=>{let f=Ll(r,m),h={};for(let[b,g]of Object.entries(f))h[b]={kpis:Object.fromEntries(t.kpis.map(y=>[y.key,g[y.key]]))};return h}:void 0);return{id:t.id,label:t.label,description:t.description,events:t.events,metrics:l,...t.track?{track:t.track}:{},...t.battery?{battery:t.battery}:{},...t.traceEventId?{traceEventId:t.traceEventId}:{},...d?{score:d}:{},...p?{field:p}:{},definition:t}}var Gr={accel:"accel",skidpad:"skidpad",autocross:"autocross",endurance:"endurance"},TF=[{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}],PF=[{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"}],LF={total:"overall",parts:{[Gr.accel]:"accelPts",[Gr.skidpad]:"skidpadPts",[Gr.autocross]:"autocrossPts",[Gr.endurance]:"endurancePts",efficiency:"efficiencyPts"}},DF={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:TF,kpis:PF,score:LF,track:{minTurnRadius:4.5},battery:pv,traceEventId:Gr.autocross},EF={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:TF,kpis:PF,score:LF,track:{minTurnRadius:4.5},traceEventId:Gr.autocross},Il=Co(DF),Dy=Co(EF);var Ey="lap",c5=[{kind:"trackLap",id:Ey,label:fp,laps:1}],IF={id:"trackday",label:"Track day",description:"One flying lap of the selected track. Times and traces only \u2014 no scoring.",events:c5,kpis:[{key:"lap",label:"Lap time",format:"time",lowerBetter:!0,expr:"lap.time"},{key:"topSpeed",label:"Top speed",unit:"km/h",over:Ey,expr:"peak(speed)"},{key:"energy",label:"Energy / lap",unit:"kWh",lowerBetter:!0,expr:"lap.energy"}],traceEventId:Ey},Iy=Co(IF);function Fo(e){if(e===null||typeof e!="object")return JSON.stringify(e)??"null";if(Array.isArray(e))return`[${e.map(Fo).join(",")}]`;let t=e,r=Object.keys(t).sort(),n=[];for(let o of r)t[o]!==void 0&&n.push(`${JSON.stringify(o)}:${Fo(t[o])}`);return`{${n.join(",")}}`}function Ma(e){let t=Fo(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 ui=[Il,Dy,Iy],Sa=Il.id,mi=e=>ui.some(t=>t.id===e),_F=new WeakMap,_l=new Map,l5=64;function xp(e){let t=_F.get(e);if(t!==void 0)return t;let r=Fo(e),n=_l.get(r);return n===void 0&&(n=yp(e).length?null:Co(e),_l.size>=l5&&_l.delete(_l.keys().next().value),_l.set(r,n)),_F.set(e,n),n}function Rp(e,t=[]){if(e==null)return;if(typeof e!="string")return xp(e)??void 0;let r=ui.find(o=>o.id===e);if(r)return r;let n=t.find(o=>o.id===e);return n?xp(n)??void 0:void 0}function Aa(e,t=[]){return Rp(e,t)??Il}function _y(e=[]){let t=e.filter(r=>!mi(r.id)).map(r=>xp(r)).filter(r=>r!==null);return[...ui,...t]}var Nl=e=>e.definition??e.id;function vp(e,t,r){let n=e.length,o=new Array(n);for(let f=0;f<n;f++){let h=f+1<n?e[f+1]:r;o[f]=h-e[f]}let a=new Array(n).fill(0),s=new Array(n).fill(0),i=new Array(n).fill(0),c=new Array(n).fill(0);for(let f=0;f<n;f++){let h=o[(f-1+n)%n],b=o[f];a[f]=h,s[f]=2*(h+b),i[f]=b;let g=t[(f+1)%n],y=t[(f-1+n)%n];c[f]=6*((g-t[f])/b-(t[f]-y)/h)}let l=u5(a,s,i,c),u=new Array(n),d=new Array(n),p=new Array(n),m=new Array(n);for(let f=0;f<n;f++){let h=o[f],b=l[f],g=l[(f+1)%n],y=t[f],x=t[(f+1)%n];u[f]=y,p[f]=b/2,m[f]=(g-b)/(6*h),d[f]=(x-y)/h-h*(2*b+g)/6}return{n,eval:(f,h)=>u[f]+h*(d[f]+h*(p[f]+h*m[f])),d1:(f,h)=>d[f]+h*(2*p[f]+h*3*m[f]),d2:(f,h)=>2*p[f]+h*6*m[f]}}function Oy(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,d=new Array(u).fill(0),p=new Array(u).fill(0),m=new Array(u).fill(0),f=new Array(u).fill(0);for(let g=0;g<u;g++){let y=g+1;d[g]=o[y-1],p[g]=2*(o[y-1]+o[y]),m[g]=o[y],f[g]=6*((t[y+1]-t[y])/o[y]-(t[y]-t[y-1])/o[y-1])}let h=n>=3;if(h){let g=o[0]/o[1];p[0]+=o[0]*(1+g),m[0]-=o[0]*g;let y=o[n-1]/o[n-2];p[u-1]+=o[n-1]*(1+y),d[u-1]-=o[n-1]*y}let b=Ny(d,p,m,f);for(let g=0;g<u;g++)a[g+1]=b[g];h&&(a[0]=(1+o[0]/o[1])*a[1]-o[0]/o[1]*a[2],a[r-1]=(1+o[n-1]/o[n-2])*a[r-2]-o[n-1]/o[n-2]*a[r-3])}let s=new Array(n),i=new Array(n),c=new Array(n),l=new Array(n);for(let u=0;u<n;u++)s[u]=t[u],c[u]=a[u]/2,l[u]=(a[u+1]-a[u])/(6*o[u]),i[u]=(t[u+1]-t[u])/o[u]-o[u]*(2*a[u]+a[u+1])/6;return{n,eval:(u,d)=>s[u]+d*(i[u]+d*(c[u]+d*l[u])),d1:(u,d)=>i[u]+d*(2*c[u]+d*3*l[u]),d2:(u,d)=>2*c[u]+d*6*l[u]}}function u5(e,t,r,n){let o=t.length;if(o===1)return[n[0]/(t[0]+e[0]+r[0])];if(o===2){let f=t[0],h=r[0]+e[0],b=e[1]+r[1],g=t[1],y=f*g-h*b;return[(n[0]*g-h*n[1])/y,(f*n[1]-n[0]*b)/y]}let a=e[0],s=r[o-1],i=-t[0]||1e-30,c=t.slice();c[0]=t[0]-i,c[o-1]=t[o-1]-a*s/i;let l=Ny(e,c,r,n),u=new Array(o).fill(0);u[0]=i,u[o-1]=s;let d=Ny(e,c,r,u),p=(l[0]+a*l[o-1]/i)/(1+d[0]+a*d[o-1]/i),m=new Array(o);for(let f=0;f<o;f++)m[f]=l[f]-p*d[f];return m}function Ny(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 Ol(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 NF(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 OF(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,d=r*c+n*l+o*u;if(!(Math.abs(d)>1e-12*Math.max(1,Math.abs(r*a*i))))return null;let p=r*i-o*o,m=n*o-r*s,f=r*a-n*n;return[(c*t[0]+l*t[1]+u*t[2])/d,(l*t[0]+p*t[1]+m*t[2])/d,(u*t[0]+m*t[1]+f*t[2])/d]}function VF(e){let t=e.z.length;if(t<5)return 0;let r=[];for(let a=0;a<t;a++){let s=[a-2,a-1,a+1,a+2].map(h=>e.closed?(h+t)%t:h);if(s.some(h=>h<0||h>=t))continue;let i=s.map(h=>NF(e,a,h)),c=Math.max(...i.map(Math.abs));if(!(c>0))continue;let l=i.map(h=>h/c),u=[0,0,0,0,0];for(let h of l)for(let b=0;b<5;b++)u[b]+=h**b;let d=OF([u[0],u[1],u[2],u[2],u[3],u[4]],[1,0,0]);if(!d)continue;let p=l.map(h=>d[0]+d[1]*h+d[2]*h*h),m=0,f=1;p.forEach((h,b)=>{m+=h*e.z[s[b]],f+=h*h}),r.push(Math.abs(e.z[a]-m)/Math.sqrt(f))}if(!r.length)return 0;r.sort((a,s)=>a-s);let n=r.length>>1;return 1.4826*(r.length%2?r[n]:(r[n-1]+r[n])/2)}function m5(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=NF(e,t,c);if(Math.abs(l)>=r||Math.sign(l)!==s)break;o.push(c),a.push(l)}return{j:o,t:a}}function d5(e,t,r){let{j:n,t:o}=m5(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 d=a[u];for(let p=0;p<5;p++)i[p]+=d,d*=l});let c=OF([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 Vy(e,t){return t>0?e.z.map((r,n)=>{let o=d5(e,n,t/2);return o?o.value.reduce((a,s,i)=>a+s*e.z[o.j[i]],0):r}):[...e.z]}function p5(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 kp(e){let t=Ol(e);if(!t)return 0;let r=VF(t);return r>1e-6?Math.max(10,p5(r,f5(t))):0}function f5(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 bn(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 Sp(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 BF(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 Mp(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 h5(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 By(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=BF(r,(y,x)=>bn(e,y,x));if(!b)return null;let g=Mp(b,t);return g.every(Number.isFinite)?g:null}let n=r-2,a=BF(n,(b,g)=>bn(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]=bn(e,b,r-2),i[b]=bn(e,b,r-1);let c=Mp(a,t.slice(0,n)),l=Mp(a,s),u=Mp(a,i),d=(b,g)=>{let y=0;for(let x=0;x<b.length;x++)y+=b[x]*g[x];return y},p=[[bn(e,r-2,r-2)-d(s,l),bn(e,r-2,r-1)-d(s,u)],[bn(e,r-1,r-2)-d(i,l),bn(e,r-1,r-1)-d(i,u)]],m=[t[r-2]-d(s,c),t[r-1]-d(i,c)],f=h5(p,m);if(!f)return null;let h=new Array(r).fill(0);for(let b=0;b<n;b++)h[b]=c[b]-l[b]*f[0]-u[b]*f[1];return h[r-2]=f[0],h[r-1]=f[1],h.every(Number.isFinite)?h:null}function $F(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=By(i,t);if(c){let l=Sp(i,c).map((d,p)=>d-t[p]);if(Math.sqrt(l.reduce((d,p)=>d+p*p,0))<=1e-6*Math.max(a,1e-12))return c}o=o===0?n*1e-12:o*10}return null}var GF=4,b5=8,$y=.001;function g5(e,t,r){let n=[];for(let c=1;c<e.length;c++){let l=e[c]-e[c-1];l>=$y&&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/Ew(r,s,i)))}function y5(e,t){let r=e.closed!==!1,n=[],o=[],a=(S,w)=>{let F=n.length-1;F>=0&&Math.hypot(S-n[F],w-o[F])<$y||(n.push(S),o.push(w))},s=e.x.length,i=r?s:s-1,c=new Array(i+1);c[0]=0;for(let S=0;S<i;S++){let w=(S+1)%s;c[S+1]=c[S]+Math.hypot(e.x[w]-e.x[S],e.y[w]-e.y[S])}let l=c[i],u=e.fit==="interpolate",d=u?s:g5(c,r,t),p=r?d:d-1,m=0;for(let S=0;S<=p&&!(r&&S===p);S++){if(u){a(e.x[S],e.y[S]);continue}let w=S*l/p;for(;m<i-1&&c[m+1]<w;)m++;let F=c[m+1]-c[m],T=F>0?(w-c[m])/F:0,A=(m+1)%s;a(e.x[m]+T*(e.x[A]-e.x[m]),e.y[m]+T*(e.y[A]-e.y[m]))}if(r)for(;n.length>2&&Math.hypot(n[n.length-1]-n[0],o[o.length-1]-o[0])<$y;)n.pop(),o.pop();let f=n.length,h=r?f:f-1,b=new Array(h+1);b[0]=0;for(let S=1;S<=h;S++){let w=S%f,F=n[w]-n[S-1],T=o[w]-o[S-1],A=Math.sqrt(Math.hypot(F,T))||1e-9;b[S]=b[S-1]+A}let g=r?vp(b.slice(0,f),n,b[f]):Oy(b,n),y=r?vp(b.slice(0,f),o,b[f]):Oy(b,o),x=new Array(h);for(let S=0;S<h;S++)x[S]=b[S+1]-b[S];let v=[0],k=[0],R=[0],M=0;for(let S=0;S<h;S++){let w=x[S]/GF;for(let F=0;F<GF;F++){let T=F*w;M+=Bg(A=>Math.hypot(g.d1(S,A),y.d1(S,A)),T,T+w),v.push(M),k.push(S),R.push(T+w)}}return{closed:r,sx:g,sy:y,h:x,sTable:v,segTable:k,uTable:R,length:M,rawCum:c,rawLength:l}}function Vl(e,t,r,n){if(e===void 0)return r.map(()=>t);if(typeof e=="number")return r.map(()=>e);let o=e.length;if(o===0)return r.map(()=>t);if(o===1)return r.map(()=>e[0]);let a=n.rawCum.length-1,s=o===(n.closed?a:a+1);return r.map(i=>{let c;if(s){let p=i*n.rawLength,m=0,f=a;for(;m<f;){let b=m+f+1>>1;n.rawCum[b]<=p?m=b:f=b-1}let h=m<a?n.rawCum[m+1]-n.rawCum[m]:0;c=m+(h>0?(p-n.rawCum[m])/h:0)}else c=n.closed?i*o:i*(o-1);let l=Math.min(Math.floor(c),o-1)%o,u=c-Math.floor(c),d=n.closed?(l+1)%o:Math.min(l+1,o-1);return e[l]+u*(e[d]-e[l])})}var x5=.01,R5=3,KF=10;function v5(e,t,r,n=KF){let o={step:0,uncertainty:1/0},a=e.length;if(a<8||!(r>0))return o;let s=Math.max(KF,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 d=[],p=[],m=(x,v,k)=>{let R=x/s;d.push([1,R,R*R,R*R*R,v]),p.push(k)};for(let x=0;x<u;x++)m(t[x]+i,1,e[x]);for(let x=0;x<u;x++)m(t[a-1-x]-r+i,0,e[a-1-x]);let f=Array.from({length:5},()=>new Array(5).fill(0)),h=new Array(5).fill(0);d.forEach((x,v)=>{for(let k=0;k<5;k++){h[k]+=x[k]*p[v];for(let R=0;R<5;R++)f[k][R]+=x[k]*x[R]}});let b=Qr(f,h),g=Qr(f,[0,0,0,0,1]);if(b.singular||g.singular)return o;let y=0;return d.forEach((x,v)=>{let k=0;for(let R=0;R<5;R++)k+=x[R]*b.x[R];y+=(p[v]-k)**2}),{step:b.x[4],uncertainty:Math.sqrt(y/(d.length-5)*g.x[4])}}function k5(e,t){let r=t[t.length-1];return{pos:e===t.length-1?t.slice(0,e):Array.from({length:e},(o,a)=>a/e*r),loop:r}}function M5(e,t,r){let{pos:n,loop:o}=k5(e.length,t),{step:a,uncertainty:s}=v5(e,n,o,r);return Math.abs(a)>Math.max(x5,R5*s)?{z:e.map((i,c)=>i+a*n[c]/o),drift:-a}:{z:e,drift:0}}function S5(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),d=r[u],p=r[u+1],m=n[u+1],f=o[u+1],h=n[u]===m?o[u]:0,b=p-d,g=b>0?h+(t-d)/b*(f-h):h;for(let y=0;y<2;y++){let x=d+Bg(k=>Math.hypot(s.d1(m,k),i.d1(m,k)),h,g),v=Math.hypot(s.d1(m,g),i.d1(m,g));if(v<1e-12)break;g-=(x-t)/v}return{seg:m,du:Math.min(Math.max(g,0),a[m])}}var A5=3,Gy=5;function w5(e,t,r,n=Gy){return wp(e,t,r,n)}function wp(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 d=1e9*(1+s);for(let p of[0,a-1])i[p]+=d,u[p]*=1+d}return By({n:a,diag:i,off1:c,off2:l,closed:r},u)??[...e]}function Ot(e,t){let r=Nt(t),n=y5(e,r.fitSpacing),o=n.length,a=Math.max(b5,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),d=new Array(s).fill(i);n.closed||(d[s-1]=0);let p=new Array(s),m=new Array(s),f=new Array(s);for(let F=0;F<s;F++){let T=F*i,{seg:A,du:C}=S5(n,T);c[F]=n.sx.eval(A,C),l[F]=n.sy.eval(A,C),u[F]=T;let P=n.sx.d1(A,C),L=n.sy.d1(A,C),E=n.sx.d2(A,C),_=n.sy.d2(A,C),D=Math.hypot(P,L),I=Math.pow(P*P+L*L,1.5);p[F]=I>0?(P*_-L*E)/I:0,m[F]=D>0?-L/D:0,f[F]=D>0?P/D:0}let h=u.map(F=>o>0?Math.min(1,F/o):0),b=Array.isArray(e.z)&&e.z.length>1,g=b&&(e.zSmoothing??0)>0?e.zSmoothing:0,y=b&&n.closed?M5(e.z,n.rawCum,g):null,x=y?y.z:e.z,v=g>0?Ol(e):null,k=v?Vy({...v,z:x},g):x,R=Vl(k,0,h,n),M=new Array(s).fill(0);if(b){for(let T=0;T<s;T++){let A=n.closed?(T+1)%s:Math.min(T+1,s-1),C=n.closed?(T-1+s)%s:Math.max(T-1,0),P=n.closed?2:A-C,L=R[A]-R[C];M[T]=P>0?Math.atan2(L,P*i)*180/Math.PI:0}for(let T=0;T<s;T++){if(d[T]===0)continue;let A=n.closed?(T+1)%s:T+1,C=R[A]-R[T];d[T]=Math.hypot(i,C)}let F=0;for(let T=0;T<s;T++)u[T]=F,F+=d[T]}let S=b?d.reduce((F,T)=>F+T,0):o,w;if(b){w=new Array(s).fill(0);let F=Math.max(A5,e.zReach??kp(e)),T=Math.max(2,Math.round(F/i));if(n.closed?s>2*T:s>2*T+1){let A=0,C=0;for(let E=-T;E<=T;E++)A+=E*E,C+=E*E*E*E;let P=2*T+1,L=C-A*A/P;for(let E=0;E<s;E++){let _=n.closed?E:Math.min(Math.max(E,T),s-1-T),D=0,I=0;for(let B=-T;B<=T;B++){let z=R[n.closed?(_+B+s)%s:_+B];D+=(B*B-A/P)*z,I+=B*z}let V=2*D/L/(i*i),O=I/A/i;w[E]=V/Math.pow(1+O*O,1.5)}}}return{name:e.name,closed:n.closed,x:c,y:l,s:u,ds:d,curvature:e.turnReach?w5(p,i,n.closed,e.turnReach):p,npts:s,length:S,nx:m,ny:f,z:R,gradient:M,...w?{verticalCurvature:w}:{},widthLeft:Vl(e.widthLeft,1.5,h,n),widthRight:Vl(e.widthRight,1.5,h,n),bank:Vl(e.bank,0,h,n),mu:Vl(e.mu,1,h,n),...y?.drift?{elevationDrift:y.drift}:{}}}function HF(e,t,r){let n=Sp(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 C5(e,t,r,n){let o=e.n,a=e.closed!==!1,s=(l,u)=>{let d=l+u;return a?(d%o+o)%o:d>=0&&d<o?d:null},i=[...t];for(let l=0;l<o;l++){if(r[l]==="free")continue;let u=n(l);if(u!==0)for(let d of[-2,-1,1,2]){let p=s(l,d);p!=null&&(i[p]-=bn(e,p,l)*u)}}let c={n:o,closed:e.closed,diag:[...e.diag],off1:[...e.off1],off2:[...e.off2]};for(let l=0;l<o;l++){if(r[l]==="free")continue;c.diag[l]=1,c.off1[l]=0,c.off2[l]=0;let u=s(l,-1),d=s(l,-2);u!=null&&(c.off1[u]=0),d!=null&&(c.off2[d]=0),i[l]=n(l)}return $F(c,i)}var F5=1e-4;function zF(e,t,r,n,o={}){let a=e.n,s=o.maxIter??60,i=o.tol??1e-9,c=o.bounds,l=(f,h)=>Math.min(n[h],Math.max(r[h],f)),u=r.map((f,h)=>c?.[h]==="hi"?n[h]:c?.[h]==="lo"?r[h]:l(0,h)),d=HF(e,t,u),p=new Array(a).fill("free"),m=!1;for(let f=0;f<s;f++){let h=Sp(e,u).map((x,v)=>x-t[v]),b=!1;for(let x=0;x<a;x++){let v=u[x]<=r[x]+i&&h[x]>=-i?"lo":u[x]>=n[x]-i&&h[x]<=i?"hi":"free";v!==p[x]&&(p[x]=v,b=!0)}if(m&&!b)return{x:u,iterations:f+1,converged:!0,bounds:p};let g=C5(e,t,p,x=>u[x]);if(!g)return{x:u,iterations:f+1,converged:!1,bounds:p};let y=!1;for(let x=1;x>1e-12;x*=.5){let v=!1,k=u.map((S,w)=>{if(p[w]!=="free")return S;let F=S+x*(g[w]-S),T=l(F,w);return T!==F&&(v=!0),T}),R=HF(e,t,k),M=0;for(let S=0;S<a;S++)M+=h[S]*(k[S]-u[S]);if(x===1&&!v||R<d&&R<=d+F5*M){u=k,d=R,m=x===1&&!v,y=!0;break}}if(!y)return{x:u,iterations:f+1,converged:!1,bounds:p}}return{x:u,iterations:s,converged:!1,bounds:p}}var Ky={lineStep:2,carHalfWidth:.75,margin:.1,foldMargin:.25,referenceReach:5,passes:40,iterations:400},T5=[1,.5,.25,.125,.0625,.03125,.015625,.0078125,.00390625,.001953125,.0009765625],P5=e=>Math.sqrt(e.reduce((t,r)=>t+r*r,0)/(e.length||1));function Bl(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],d=t[i]-t[a],p=e[i]-e[s],m=t[i]-t[s],f=Math.hypot(c,l),h=Math.hypot(u,d),b=Math.hypot(p,m),g=f*h*b;o[a]=g>1e-12?2*(c*d-l*u)/g:0}return o}var L5=Math.PI/180,YF=20;function D5(e,t){let r=e.npts,n=e.closed,o=e.x.map((m,f)=>m+t[f]*e.nx[f]),a=e.y.map((m,f)=>m+t[f]*e.ny[f]),s=[0];for(let m=1;m<r;m++)s.push(s[m-1]+Math.hypot(o[m]-o[m-1],a[m]-a[m-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 m of c)for(let f=0;f<r;f++)l.push(s[f]+m*i),u.push(f+m*r);n&&(l.push(2*i),u.push(2*r));let d=[0];for(let m=1;m<l.length;m++)d.push(d[m-1]+.5*(u[m]+u[m-1])*(l[m]-l[m-1]));let p=m=>{let f=0,h=l.length-1;for(;h-f>1;){let g=f+h>>1;l[g]<=m?f=g:h=g}let b=l[h]>l[f]?(m-l[f])/(l[h]-l[f]):0;return d[f]+(l[h]-l[f])*b*(u[f]+.5*b*(u[h]-u[f]))};return s.map((m,f)=>{let h=n?YF:Math.min(YF,m,i-m);if(!(h>0))return e.z[f];let b=(p(m+h)-p(m-h))/(2*h),g=n?(b%r+r)%r:Math.min(Math.max(b,0),r-1),y=Math.min(Math.floor(g),r-1),x=n?(y+1)%r:Math.min(y+1,r-1);return e.z[y]+(g-y)*(e.z[x]-e.z[y])})}function E5(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?D5(t,r):t.z;return{...n||o?{z:s.map((i,c)=>i+r[c]*Math.tan(t.bank[c]*L5))}:{},...n?{zReach:e.zReach??kp(e)}:{},...o?{bank:[...t.bank]}:{},...a?{mu:[...t.mu]}:{}}}function WF(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 I5(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,d,p)=>l*p-u*d;for(let l=0;l<a;l++){if(!o&&(l===0||l===a-1))continue;let u=(l-1+a)%a,d=(l+1)%a,p=e[l]-e[u],m=t[l]-t[u],f=e[d]-e[l],h=t[d]-t[l],b=e[d]-e[u],g=t[d]-t[u],y=Math.hypot(p,m),x=Math.hypot(f,h),v=Math.hypot(b,g),k=y*x*v;if(!(k>1e-12))continue;let R=2*c(p,m,f,h)/k,M=Math.sqrt(.5*(y+x)),S=R/(2*M),w=(p*r[u]+m*n[u])/y,F=(b*r[u]+g*n[u])/v,T=(p*r[l]+m*n[l])/y,A=(f*r[l]+h*n[l])/x,C=(f*r[d]+h*n[d])/x,P=(b*r[d]+g*n[d])/v,L=-2*c(r[u],n[u],f,h)/k+R*(w/y+F/v),E=2*c(r[l],n[l],b,g)/k-R*(T/y-A/x),_=2*c(p,m,r[d],n[d])/k-R*(C/x+P/v);s[l]=R*M,i.l[l]=M*L-S*.5*w,i.d[l]=M*E+S*.5*(T-A),i.r[l]=M*_+S*.5*C}return{res:s,jac:i}}function _5(e,t,r,n,o){let a=n-r+1,s=e.l.slice(r,n+1),i=e.d.slice(r,n+1),c=e.r.slice(r,n+1),l=t.slice(r,n+1);o||(i[0]+=s[0],s[0]=0,i[a-1]+=c[a-1],c[a-1]=0);let u=(h,b)=>o?h[(b+a)%a]:b>=0&&b<a?h[b]:0,d=new Array(a),p=new Array(a),m=new Array(a),f=new Array(a);for(let h=0;h<a;h++){let b=u(c,h-1),g=u(s,h+1);d[h]=b*b+i[h]*i[h]+g*g,p[h]=i[h]*c[h]+g*u(i,h+1),m[h]=g*u(c,h+1),f[h]=-(b*u(l,h-1)+i[h]*l[h]+g*u(l,h+1))}return{M:{n:a,closed:o,diag:d,off1:p,off2:m},b:f}}function N5(e,t){let r=e.npts,n=e.closed;if(!(t>0)||r<7)return e;let o=n?r:r-1,a=0;for(let p=0;p<o;p++){let m=(p+1)%r;a+=Math.hypot(e.x[m]-e.x[p],e.y[m]-e.y[p])}let s=a/o,i=wp(e.x,s,n,t,!0),c=wp(e.y,s,n,t,!0),l=new Array(r),u=new Array(r);for(let p=0;p<r;p++){let m=n?(p-1+r)%r:Math.max(p-1,0),f=n?(p+1)%r:Math.min(p+1,r-1),h=i[f]-i[m],b=c[f]-c[m],g=Math.hypot(h,b)||1;l[p]=-b/g,u[p]=h/g}let d=Bl(i,c,n);return n||(d[0]=d[1],d[r-1]=d[r-2]),{...e,x:i,y:c,nx:l,ny:u,curvature:d}}var O5=6;function V5(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,d=Math.atan2(e.nx[l]*e.ny[u]-e.ny[l]*e.nx[u],e.nx[l]*e.nx[u]+e.ny[l]*e.ny[u]),p=Math.hypot(e.x[u]-e.x[l],e.y[u]-e.y[l]);s[l]=p>1e-9?d/p:0}let i=Math.max(0,Math.round(O5/(e.ds[0]||1))),c=1-n;for(let l=0;l<o;l++){let u=0,d=0;for(let p=-i-1;p<=i;p++){let m=e.closed?((l+p)%o+o)%o:l+p;m<0||m>=a||(u=Math.max(u,s[m]),d=Math.max(d,-s[m]))}u>0&&(t[l]=Math.max(r[l],Math.min(t[l],c/u))),d>0&&(r[l]=Math.min(t[l],Math.max(r[l],-c/d)))}}function Hy(e,t={}){let r={...Ky,...t},n=Ot(e,{dsTarget:r.lineStep}),o=N5(n,r.referenceReach),a=o.npts,s=T=>({x:o.x.map((A,C)=>A+o.nx[C]*T[C]),y:o.y.map((A,C)=>A+o.ny[C]*T[C])}),i=T=>{let A=Bl(T.x,T.y,o.closed),C=WF(T.x,T.y,o.closed),P=0;for(let L=0;L<A.length;L++)P+=A[L]*A[L]*C[L];return P},c=P5(n.curvature),l=WF(n.x,n.y,n.closed).reduce((T,A)=>T+A,0),u=new Array(a).fill(0),d=r.carHalfWidth+r.margin,p=new Array(a),m=new Array(a),f=0;for(let T=0;T<a;T++){let A=o.widthLeft[T]-d,C=-(o.widthRight[T]-d);if(A<C){f++;let P=(o.widthLeft[T]-o.widthRight[T])/2;p[T]=P,m[T]=P}else p[T]=A,m[T]=C}let h=[...p],b=[...m];V5(o,p,m,r.foldMargin);let g=T=>{let A=s(T),C=E5(e,o,T),P={name:`${e.name} \u2014 racing line`,x:A.x,y:A.y,closed:o.closed,widthLeft:h.map((O,B)=>Math.max(0,O-T[B])),widthRight:b.map((O,B)=>Math.max(0,T[B]-O)),...C,fit:"interpolate",turnReach:Gy},L=1e-6,E=T.filter((O,B)=>O>=p[B]-L||O<=m[B]+L).length,_=Bl(A.x,A.y,o.closed),D=O=>1/Math.max(...O.map(Math.abs),1e-9),I=0,V=o.closed?A.x.length:A.x.length-1;for(let O=0;O<V;O++){let B=(O+1)%A.x.length,z=A.x[B]-A.x[O],j=A.y[B]-A.y[O];I+=C.z?Math.hypot(z,j,C.z[B]-C.z[O]):Math.hypot(z,j)}return{offset:T,s:[...o.s],asset:P,curvatureRms:{centreLine:c,racingLine:Math.sqrt(i(A)/(l||1))},infeasibleSamples:f,atBoundary:a?E/a:0,length:{centreLine:n.length,racingLine:I},worstRadius:{centreLine:D(n.curvature),racingLine:D(_)}}},y=o.closed?0:1,x=o.closed?a-1:a-2,v=x-y+1,k=new Array(v),R=new Array(v);for(let T=0;T<v;T++)k[T]=m[y+T],R[T]=p[y+T];if(!o.closed&&v>0){let T=(A,C)=>{if(k[A]=Math.max(k[A],m[C]),R[A]=Math.min(R[A],p[C]),k[A]>R[A]){let P=.5*(k[A]+R[A]);k[A]=P,R[A]=P}};T(0,0),T(v-1,a-1),k[0]=R[0]=Math.min(R[0],Math.max(k[0],0))}if(v<7)return g(u);let M=T=>{let A=s(T),P=[...Bl(A.x,A.y,o.closed).map(Math.abs)].sort((L,E)=>L-E);return{integral:i(A),tail:P[Math.floor(.99*(P.length-1))]}},S=[...u],w=M(u),F;for(let T=0;T<r.passes;T++){let A=s(S),{res:C,jac:P}=I5(A.x,A.y,o.nx,o.ny,o.closed),{M:L,b:E}=_5(P,C,y,x,o.closed),_=zF(L,E,k.map((V,O)=>V-S[y+O]),R.map((V,O)=>V-S[y+O]),{maxIter:r.iterations,bounds:F});F=_.bounds;let D=new Array(a).fill(0);for(let V=0;V<v;V++)D[y+V]=_.x[V];o.closed||(D[0]=D[1],D[a-1]=D[a-2]);let I=!1;for(let V of T5){let O=S.map((z,j)=>z+V*D[j]),B=M(O);if(B.integral<w.integral*(1-1e-6)){S=O,w=B,I=!0;break}}if(!I)break}return g(S)}function zy(e){let t=Math.max(ee(e,"track_front"),ee(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?zy(r.params):void 0,o=Hy(e,{...r.line,...n?{carHalfWidth:n}:{}});return{asset:o.asset,numerics:{...t,fitSpacing:0},line:o}}function $l(e,t,r={}){let n=Cp(e,t,r);return{track:Ot(n.asset,n.numerics),line:n.line}}function Yy(e=4,t=$l){let r=new WeakMap;return(n,o,a={})=>{let s=a.racingLine===!0,i=s?[a.params?zy(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 d=t(n,o,a);return l.set(c,d),l.size>e&&l.delete(l.keys().next().value),d}}var jF={racingLine:!1,standingStart:!1},Fp=256;function Gl(e,t,r,n,o=jF,a=$l){let s=Aa(n),{racingLine:i,standingStart:c,lapCounts:l}=o;return e.map(u=>{let{track:d}=a(t,r,{racingLine:i,params:u});return Ay(Cl(u,s,{track:d,numerics:r,standingStart:c,lapCounts:l}))})}function Wy(e,t){let r=Aa(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 jy(e,t,r){let n={};for(let o of Aa(e).metrics)n[o.key]=o.value(t,r);return n}var Tp=37;var qy=287.05287,$5=461.495,Pp=9.80665/(qy*.0065),G5=101325/(qy*288.15),K5=273.15,H5=-500,z5=6e3,Y5=400,W5=1100,Lp={source:"car",altitudeM:0,pressure:{kind:"standard"},humidityPct:0};function j5(e){return 101325*Math.pow(1-.0065*e/288.15,Pp)}function U5(e){return 288.15/.0065*(1-Math.pow(e/G5,1/(Pp-1)))}function X5(e){return 288.15/.0065*(1-Math.pow(e/101325,1/Pp))}function q5(e,t){return e*Math.pow(1-.0065*t/288.15,Pp)}function Q5(e){return 611.21*Math.exp((18.678-e/234.5)*(e/(257.14+e)))}function Z5(e,t){switch(e.kind){case"standard":return j5(t);case"qnh":return q5(e.hPa*100,t);case"station":return e.hPa*100}}function Kl(e,t,r=0,n=X5(e)){let o=t+K5,a=Math.min(.5*e,Math.max(0,Math.min(100,r))/100*Q5(t)),s=e-a,i=s/(qy*o)+a/($5*o);return{altitudeM:n,p:e,pDry:s,T:o,rho:i,densityAltitudeM:U5(i)}}function UF(e,t){return Kl(Z5(e.pressure,e.altitudeM),t,e.humidityPct,e.altitudeM)}var Uy=(e,t,r)=>Math.min(r,Math.max(t,e)),Xy=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function Dp(e){if(!e||typeof e!="object")return structuredClone(Lp);let t=e,r=t.pressure??{},n=Uy(Xy(r.hPa,1013.25),Y5,W5),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:Uy(Xy(t.altitudeM,0),H5,z5),pressure:o,humidityPct:Uy(Xy(t.humidityPct,0),0,100)}}var Ca=e=>e?.source==="venue",Ep="the air the session states, at its venue";var J5=Math.PI/180;function e$(){return{ucaFront:[110,245,330],ucaRear:[-110,258,335],lcaFront:[130,185,112],lcaRear:[-130,205,116],tieInner:[-92,210,132],uprightUpper:[-6,542,352],uprightLower:[4,560,120],tieOuter:[-78,556,146],wheelCenter:[0,600,230],pushrodOuter:[8,520,128],rockerPivotA:[70,380,440],rockerPivotB:[-50,383,442],rockerToPushrod:[65,478.6,419.1],rockerToDamper:[10,280,440],damperChassis:[10,275,245]}}function t$(){return{ucaFront:[120,250,340],ucaRear:[-120,262,345],lcaFront:[140,190,118],lcaRear:[-140,210,122],tieInner:[120,215,150],uprightUpper:[-4,548,360],uprightLower:[6,566,126],tieOuter:[108,560,158],wheelCenter:[0,610,232],pushrodOuter:[10,526,132],rockerPivotA:[70,385,450],rockerPivotB:[-50,388,452],rockerToPushrod:[67,484.6,429.1],rockerToDamper:[12,286,450],damperChassis:[12,281,255]}}function Qy(e){let t=-e*J5;return re([0,Math.cos(t),Math.sin(t)])}function Ip(){let e={rodType:"push",pushrodAttach:"lowerArm",steerMode:"rack",spinAxis:Qy(-1),loadedRadius:230,springRate:35,rackAxis:[0,1,0]};return{hardpoints:e$(),config:e}}function Hl(){let e={rodType:"pull",pushrodAttach:"lowerArm",steerMode:"fixed",spinAxis:Qy(-1.5),loadedRadius:232,springRate:40,rackAxis:[0,1,0]};return{hardpoints:t$(),config:e}}function _p(){let e=[-25,635,460],t=[-40,600,710],r={layout:"mcpherson",actuation:"direct",rodType:"push",pushrodAttach:"upright",steerMode:"rack",spinAxis:Qy(-.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 Zy(){return{front:Ip(),rear:Hl(),config:{wheelbase:1600,trackFront:1200,trackRear:1220,frontAxleX:800}}}var r$=Math.PI/180;function XF(e){let t=-e*r$;return re([0,Math.cos(t),Math.sin(t)])}function Jy(e,t){let r=([l,u,d])=>[l*t.kx,u*t.ky,d*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:XF(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]=n$(o[l]);return{hardpoints:o,config:c}}function n$(e){return e.map(t=>Math.round(t*10)/10+0)}function Fa(e){return{name:e.name,front:Jy(Ip(),e.front),rear:Jy(Hl(),e.rear),config:{wheelbase:e.wheelbase,trackFront:e.trackFront,trackRear:e.trackRear,frontAxleX:e.wheelbase/2}}}function di(e,t,r){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:t}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:r}}}}var pi=600,Ta=610,fi=230,Pa=232;function La(){let e=Zy();return{...e,name:"Formula Student",front:{...e.front,config:{...e.front.config,actuation:"rocker"}},rear:{...e.rear,config:{...e.rear.config,actuation:"rocker"}}}}function ex(){return Fa({name:"Formula 1",wheelbase:3600,trackFront:1600,trackRear:1600,front:{kx:1.3,ky:800/pi,kz:355/fi,lowerInnerDz:-5,upperInnerDz:0,camberDeg:-3,loadedRadius:355,springRate:200},rear:{kx:1.3,ky:800/Ta,kz:355/Pa,lowerInnerDz:35,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:220}})}function zl(){return di(Fa({name:"GT car",wheelbase:2700,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/pi,kz:325/fi,lowerInnerDz:18,upperInnerDz:5,camberDeg:-3.5,loadedRadius:325,springRate:110,actuation:"direct"},rear:{kx:1.2,ky:825/Ta,kz:325/Pa,lowerInnerDz:36,upperInnerDz:15,camberDeg:-2,loadedRadius:325,springRate:120,actuation:"direct"}}),318.6,318.6)}function Yl(){return di(Fa({name:"Sports car",wheelbase:2750,trackFront:1550,trackRear:1550,front:{kx:1.15,ky:775/pi,kz:320/fi,lowerInnerDz:36,upperInnerDz:15,camberDeg:-.5,loadedRadius:320,springRate:55,actuation:"direct"},rear:{kx:1.15,ky:775/Ta,kz:320/Pa,lowerInnerDz:57,upperInnerDz:25,camberDeg:-1,loadedRadius:320,springRate:60,actuation:"direct"}}),305.4,309)}function o$(e,t,r,n,o,a){let s=_p(),i=Object.fromEntries(Object.entries(s.hardpoints).map(([l,[u,d,p]])=>[l,[u,d+e,p]])),c=(l,u)=>{i[l]=[i[l][0],i[l][1],i[l][2]+u]};return c("lcaFront",t),c("lcaRear",t),c("tieInner",r),{hardpoints:i,config:{...s.config,spinAxis:XF(n),springRate:o,rackTravel:a}}}function qF(){return di({name:"Cup car",front:o$(55,-25,-23,-3.5,150,55),rear:Jy(Hl(),{kx:1.15,ky:820/Ta,kz:320/Pa,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 QF(){return{...di(Fa({name:"Stock car",wheelbase:2794,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/pi,kz:355/fi,lowerInnerDz:20,upperInnerDz:5,camberDeg:-2.5,loadedRadius:355,springRate:175,actuation:"direct"},rear:{kx:1.2,ky:825/Ta,kz:355/Pa,lowerInnerDz:40,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:150,actuation:"direct"}}),343.8,345.3),chassis:{boxes:[],body:"nascar"}}}function ZF(){let e=di(Fa({name:"Hill-climb prototype",wheelbase:2550,trackFront:1580,trackRear:1540,front:{kx:1.1,ky:790/pi,kz:300/fi,lowerInnerDz:10,upperInnerDz:5,camberDeg:-2.5,loadedRadius:300,springRate:90},rear:{kx:1.1,ky:770/Ta,kz:300/Pa,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 JF(){let e=di(Fa({name:"Race truck",wheelbase:3700,trackFront:2050,trackRear:1950,front:{kx:1.5,ky:1025/pi,kz:506/fi,lowerInnerDz:40,upperInnerDz:10,camberDeg:-.5,loadedRadius:506,springRate:200,actuation:"direct"},rear:{kx:1.5,ky:975/Ta,kz:506/Pa,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 Ft=(e,t,r)=>({value:e,label:t,unit:r}),eT=(e,t)=>({...cn[e],value:t});function tT(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 Da(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 Jn(e){let t={name:e.name,m:Ft(e.m,"vehicle mass (with driver)","kg"),A:Ft(e.A,"frontal area","m^2"),c_l:Ft(e.cl,"downforce coefficient","-"),c_w:Ft(e.cw,"drag coefficient","-"),l_to_d_ratio:Ft(e.cw>0?e.cl/e.cw:0,"lift-to-drag ratio","-"),driven_wheels:Ft(e.drivenWheels,"driven wheels","-"),fr_0:Ft(-.012,"rolling-resistance coefficient","-"),front_aero_diss:Ft(e.frontAero,"front aero distribution","-"),front_mass_diss:Ft(e.frontMass,"front mass distribution","-"),r_dyn:Ft(e.rDyn,"dynamic tyre radius","m"),rho:Ft(1.2,"air density","kg/m^3"),gear_ratio:Ft(e.gearRatio,"gear ratio","-"),effi_pgb:Ft(e.drivetrainEfficiency,"drivetrain efficiency","-"),capacity:Ft(e.capacityAh,"pack capacity","Ah"),soc:Ft(1,"state of charge","-"),ocv:Ft(e.ocv,"pack open-circuit voltage","V"),power_scale:Ft(1,"power scaling factor","-"),power_limit_kw:eT("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]=eT(r,n);return t}var hi={name:"Formula Student",m:300,A:1,cl:3,cw:1.3,frontMass:.47,frontAero:.45,rDyn:.222,drivenWheels:2,gearRatio:11.5,motor:tT(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}},rx={name:"Formula 1",m:798,A:1.5,cl:3,cw:.9,frontMass:.46,frontAero:.44,rDyn:.35,drivenWheels:2,gearRatio:4.9,motor:Da(735,2e3,12500,2500,2),motorCount:1,driveline:{rear:Jt.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}},Np={name:"GT car",m:1300,A:2,cl:1.4,cw:.42,frontMass:.5,frontAero:.42,rDyn:.33,drivenWheels:2,gearRatio:3.43,motor:Da(410,2e3,8e3,2e3,2),motorCount:1,driveline:{rear:Jt.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}},Op={name:"Sports car",m:1600,A:2.2,cl:-.1,cw:.3,frontMass:.55,frontAero:.5,rDyn:.32,drivenWheels:2,gearRatio:3.14,motor:Da(220,1500,6500,1400,2),motorCount:1,driveline:{rear:Jt.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}},nx={name:"Cup car",m:1265,A:2.1,cl:.45,cw:.4,frontMass:.62,frontAero:.45,rDyn:.31,drivenWheels:2,gearRatio:3.5,motor:Da(250,2e3,7e3,1190,2),motorCount:1,motorPlacement:"front",driveline:{front:Jt.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}},ox={name:"Stock car",m:1620,A:2.2,cl:.6,cw:.45,frontMass:.53,frontAero:.45,rDyn:.35,drivenWheels:2,gearRatio:4.1,motor:Da(500,2500,9e3,1680,2),motorCount:1,driveline:{rear:Jt.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}},ax={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:Da(330,3e3,8500,1240,2),motorCount:1,driveline:{rear:Jt.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}},sx={name:"Race truck",m:5300,A:6.2,cl:-.1,cw:.65,frontMass:.6,frontAero:.6,rDyn:.502,drivenWheels:2,gearRatio:3.55,motor:Da(880,100,3e3,88e3,2),motorCount:1,driveline:{rear:Jt.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 tx(e,t,r){return Jn(r({...structuredClone(e),name:t}))}var Vp={[hi.name]:Jn(hi),"Formula Student +15% downforce":tx(hi,"Formula Student +15% downforce",e=>({...e,cl:e.cl*1.15,cw:e.cw*1.08})),"Formula Student -15 kg":tx(hi,"Formula Student -15 kg",e=>({...e,m:e.m-15})),"Formula Student +15% power":tx(hi,"Formula Student +15% power",e=>({...e,motor:tT(25*1.15,15e3,2e4),powerLimitKw:80*1.15})),[rx.name]:Jn(rx),[Np.name]:Jn(Np),[Op.name]:Jn(Op),[nx.name]:Jn(nx),[ox.name]:Jn(ox),[ax.name]:Jn(ax),[sx.name]:Jn(sx)},rT=Object.keys(Vp),ix=rT.slice(0,4),cx=[hi.name,rx.name,Np.name,Op.name,nx.name,ox.name,ax.name,sx.name];var nme={"Touring car":Np.name,"Street car":Op.name};var a$={bg:"#11141b",panel:"#161b22",panel2:"#202d3a",border:"#334050",borderBright:"#526477",sunken:"#0b1219",ink:"#06090d"},s$={normal:"#eef3fa",dim:"#9baab9",bright:"#ffffff",white:"#ffffff"},i$={label:"#c8d2dc",grid:"#39424e",gridFaint:"#232b35",empty:"#1a2028"},c$={accent:"#6aa8ff",accentInk:"#0d1b30",warn:"#ffb454",good:"#4ec9a0",bad:"#ff6b6b",badSoft:"#ff8f8f"},l$=["#f0e442","#7b68ee","#f7a8b8","#d55e00","#d8b4fe","#b5e48c"],Bp={front:"#a6e22e",rear:"#00b4d8"},nT=["#5b4bd6","#4aa3ff","#4ec9a0","#f0e442"],lx={power:"#ffb454",traction:"#f0845c",front:Bp.front,rear:Bp.rear,grip:"#73c9b3",braking:"#b48aff",crest:"#e88fd0",below:"rgba(214, 221, 230, 0.32)"},u$={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"},m$={x:"#ff6b6b",y:"#57c75a",z:"#4aa3ff"},d$={line:"#b4bfcb"},p$={compression:"#b48aff",tension:"#ff6b6b"},f$={fz:"#e7ecf3",fx:"#7ad7f0",fy:"#ff54c8"},h$={drivenLine:"#4d7cff",axis:"#eef3fa",slip:"#ffe81a",drive:lx.power,brake:lx.braking},b$={ground:"#101920",grid:"#1a2630",gridMajor:"#26343f",horizon:"#1d2833",bridge:"#6f7a86",coneLeft:"#2f63c9",coneRight:"#d9b51f",coneStart:"#ee7a2c"},g$={chassis:"#435160",volume:"#303b47",tyre:"#435160",tyreLine:"#39424e",tyreFace:"#1c232d"},y$={centreLine:"#4aa3ff",corridorFill:"rgba(74,163,255,0.10)",boundary:"#3d4956",racingLine:"#ffb454",start:"#e7ecf3",finish:"#ff6b6b",direction:"#8b96a3"},x$={SURFACE:a$,TEXT:s$,CHART:i$,ROLE:c$,SERIES:l$,AXLE:Bp,LAP_SPEED:nT,LIMITER:lx,RIG:u$,AXIS:m$,CONSTRUCTION:d$,FORCE:p$,TYRE_FORCE:f$,REPLAY:h$,SCENERY:b$,BODY:g$,TRACK:y$},oT=e=>Object.fromEntries(Object.entries(e).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):Object.freeze({...r})])),$p=oT(x$),tr=$p.SERIES,aT=(()=>{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 oT({SURFACE:{bg:"#f5f6f6",panel:"#fcfcfd",panel2:"#ffffff",border:"#d8dfe6",borderBright:"#b7c3ce",sunken:"#e8edf2",ink:"#ffffff"},TEXT:{normal:"#17212c",dim:"#606c79",bright:"#10171f",white:"#000000"},CHART:{label:"#3a424b",grid:"#c2c8cd",gridFaint:"#e2e5e7",empty:"#e8eae7"},ROLE:{accent:"#2162bd",accentInk:"#ffffff",warn:e,good:"#0f8a66",bad:t,badSoft:"#e2696d"},SERIES:["#b5a11a","#2844e3","#f47ec1","#9b3a1b","#764299","#58b977"],AXLE:r,LAP_SPEED:["#4b3bc4","#1a64c2","#0f8a66","#a87e00"],LIMITER:n,RIG:{chassis:"#1a64c2",ballJoint:"#c27200",arm:"#56616d",tie:"#24907b",pushrod:"#a3820f",rocker:"#6656b8",kingpin:"#8f7f10",arbBar:"#b04d77",arbArm:"#9a4767",arbLink:"#c27200",heaveSpring:"#1688ad",wheelCentre:"#15181c",contactPatch:t,ground:"#e2e6e8",groundFaint:"#edf0f1"},AXIS:{x:"#d93a3a",y:"#2f9d34",z:"#1a64c2"},CONSTRUCTION:{line:"#5a6570"},FORCE:{compression:"#7b55d0",tension:t},TYRE_FORCE:{fz:"#ffe600",fx:"#0f8fb0",fy:"#c8198f"},REPLAY:{drivenLine:"#2f5be0",axis:"#15181c",slip:"#c79a00",drive:n.power,brake:n.braking},SCENERY:{ground:"#dde3e1",grid:"#ccd3d1",gridMajor:"#b5bfbc",horizon:"#e8edf0",bridge:"#9aa3ab",coneLeft:"#2f63c9",coneRight:"#d9b51f",coneStart:"#ee7a2c"},BODY:{chassis:"#a9b3bd",volume:"#c7ced5",tyre:"#24282c",tyreLine:"#2c333a",tyreFace:"#c3cad0"},TRACK:{centreLine:"#1a64c2",corridorFill:"rgba(26,100,194,0.10)",boundary:"#a3acb4",racingLine:e,start:"#15181c",finish:t,direction:"#5c6570"}})})();var sT=e=>{let t=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());return t?`#${(t[1].length===3?t[1].replace(/./g,n=>n+n):t[1]).toLowerCase()}`:null},ame=(()=>{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=$p[r],o=aT[r];for(let a of Object.keys(n)){let s=sT(n[a]);s&&!e.has(s)&&e.set(s,o[a])}}return e})();var iT=(e,t)=>new Set(t.flatMap(r=>{let n=e[r];return Array.isArray(n)?[...n]:Object.values(n)}).map(sT).filter(r=>r!==null)),sme=iT(aT,["SERIES","AXLE","LAP_SPEED","LIMITER","ROLE","RIG","FORCE","TYRE_FORCE","REPLAY","AXIS","TRACK","CONSTRUCTION"]),ime=iT($p,Object.keys($p).filter(e=>e!=="SURFACE"));function ux(){return{kind:"simple",name:"Simple motor",rpm:[0,16e3,2e4],torque:[21,21,14],efficiency:.95}}function mx(){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 dx(){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 px(){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 fx(){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 cT(){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 lT(){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 uT(){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 mT(){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 dT(){return{kind:"ice",name:"Turbocharged 2.0 l four, hill climb (example)",rpm:[3e3,3500,4e3,4500,5e3,5500,6e3,6500,7e3,7500,8e3,8500],torque:[314,380,446,462,462,462,458,450,437,420,388,347],idleRpm:3e3,limitRpm:8500,inertia:.1,gearbox:{primary:1,ratios:[2.69,2,1.6,1.33,1.14,1],efficiency:.93,upshiftTime:.05,downshiftTime:.08},breathing:{induction:{kind:"boosted",boostKPa:250,maxPressureRatio:4.5}}}}function pT(){return{kind:"ice",name:"Race truck diesel six, 13 l (example)",rpm:[800,1e3,1200,1400,1600,1800,2e3,2200,2400,2600,2800,3e3],torque:[3e3,4e3,4900,5500,5250,4670,4200,3820,3500,3230,3e3,2700],idleRpm:800,limitRpm:3e3,inertia:1.5,gearbox:{primary:1,ratios:[16,12.44,9.67,7.51,5.84,4.54,3.53,2.74,2.13,1.66,1.29,1],efficiency:.92,upshiftTime:.35,downshiftTime:.35},breathing:{induction:{kind:"boosted",boostKPa:350,maxPressureRatio:4.3}}}}function fT(e){return Ma(R$(e))}function R$(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;let t={...e};return delete t.name,delete t.parts,Array.isArray(t.vehicles)&&(t.vehicles=t.vehicles.map(r=>{if(r===null||typeof r!="object"||Array.isArray(r))return r;let n={...r};return delete n.name,n})),t}function Wl(e,t){return{...t,fingerprint:fT(e)}}var hT="CC-BY-4.0",v$={title:"PaceDynamics built-in library",url:"https://pacedyn.dev/",licence:hT},bT={fidelity:"generic",licence:hT,sources:[v$]};var Gp=e=>Wl(e,bT);var gT=["raw.githubusercontent.com"],yT=["tum-csv"],M$=/^[0-9a-f]{64}$/;function Ul(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"||!M$.test(r)||!yT.includes(n))return!1;try{let o=new URL(t);return o.protocol==="https:"&&gT.includes(o.hostname)&&!o.username&&!o.password&&!o.port}catch{return!1}}var Kp=e=>new URL(e.url).hostname;async function xT(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 S$(e){let t=new URL(e).pathname.split("/").pop()??"";return decodeURIComponent(t).replace(/\.[^.]*$/,"")||"Linked track"}function A$(e,t){let r=[],n=[],o=[],a=[];for(let[s,i]of e.split(/\r?\n/).entries()){let c=i.trim();if(!c||c.startsWith("#"))continue;let l=c.split(",").map(u=>Number(u.trim()));if(l.length!==4||!l.every(Number.isFinite))throw new Error(`Line ${s+1} of ${t} is not four numbers.`);r.push(l[0]),n.push(l[1]),o.push(l[2]),a.push(l[3])}if(r.length<3)throw new Error(`${t} has ${r.length} points; a track needs at least 3.`);return{name:t,x:r,y:n,widthLeft:a,widthRight:o,closed:!0,fit:"interpolate"}}var w$={"tum-csv":A$};function RT(e,t){return w$[t.format](e,S$(t.url))}async function hx(e,t,r){let n=await xT(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=RT(new TextDecoder().decode(e),t),a=await Hp(o);if(a!==r)throw new Error(`Linked track ${r} does not convert to its name (it is ${a}).`);return o}var bx=20,F$=new RegExp(`^[0-9a-f]{${bx}}$`),Xl=e=>typeof e=="string"&&F$.test(e);async function Hp(e){let t=new TextEncoder().encode(Fo(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,bx)}var gx=e=>`tracks/${e}.json`;var T$=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function yx(e){return{model:{name:e.name,source:e.source},...e.provenance?{provenance:e.provenance}:{}}}async function xx(e,t){if(!T$(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 Hp(e);if(r!==t)throw new Error(`Catalogue track ${t} does not match its name (it is ${r}).`);return e}var Ea=(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}),To=[Ea("suspensions","suspensionId","suspension"),Ea("tires","tireModelId","tyre",[{key:"tiresRear",ref:"tireModelIdRear",label:"rear tyre"}]),Ea("motors","motorModelId","motor"),Ea("aeros","aeroModelId","aero map"),Ea("batteries","batteryModelId","battery"),Ea("brakes","brakeModelId","brakes"),Ea("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 zp(e){let t={...e};for(let r of To)for(let n of r.refs)delete t[n];return t}var Yp=tr,ql=Yp,Rx=Yp,Po=[...tr.slice(3),...tr.slice(0,3)],Mx=[...tr.slice(1),tr[0]],vx=[...tr.slice(2),...tr.slice(0,2)],kx=[...tr.slice(4),...tr.slice(0,4)],Sx=[...tr.slice(5),...tr.slice(0,5)],Ql=[...tr.slice(2),...tr.slice(0,2)];function Ax(){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 wx(e,t,r){let n=Vp[e];if(!n)throw new Error(`no preset vehicle named "${e}"`);return{id:t,params:{...Qc(structuredClone(n)),energy:{...Vn},suspensionId:"sus1"},visible:!0,color:ql[r%ql.length]}}function D$(){return ix.map((e,t)=>wx(e,`v${t+1}`,t))}function E$(){return[wc(),rg(),ng(),og(),ag(),sg(),ig(),cg(),lg(),ug()].map((t,r)=>({id:`t${r+1}`,color:Rx[r%Rx.length],model:t}))}function I$(){return[Oh(),Vh(),Bh(),$h(),Gh(),Kh(),Hh(),zh()].map((t,r)=>({id:`a${r+1}`,color:vx[r%vx.length],model:t}))}function _$(){return[kh(),Mh(),Sh()].map((t,r)=>({id:`b${r+1}`,color:kx[r%kx.length],model:t}))}function N$(){return[{id:"brk1",color:Sx[0],model:structuredClone(Pg)}]}function O$(){return[{id:"dmp1",color:Ql[0],model:structuredClone(gd)}]}function V$(){return[ux(),mx()].map((t,r)=>({id:`m${r+1}`,color:Po[r%Po.length],model:t}))}function Cx(e){let t=r=>({...r,provenance:Gp(r.model)});return{...e,suspensions:e.suspensions.map(t),vehicles:e.vehicles.map(r=>({...r,provenance:Gp(zp(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 Zl(e="Untitled project"){let t=new Date().toISOString(),r=D$();return Cx({schemaVersion:Tp,meta:{id:Ax(),name:e,domain:"racecar",rulesetId:Sa,createdAt:t,updatedAt:t},suspensions:[{id:"sus1",color:Mx[0],model:La()}],activeSuspensionId:"sus1",vehicles:r,activeVehicleId:r[0]?.id??null,tires:E$(),motors:V$(),aeros:I$(),batteries:_$(),brakes:N$(),dampers:O$(),tracks:[],activeTrackId:null,mathChannels:[],rulesets:[],studies:[],activeStudyId:null,loadCases:[],reportLayouts:[],tyreSheets:[],kinSheets:[],lapSheets:[],plans:[],results:[],settings:{numerics:{...pl},ggvMode:"twoTrack",quasiTransient:!1,motorThermal:!1,brakeFade:!1,airTempC:lr,air:structuredClone(Lp),diffYaw:!1,lapCounts:{},pathPlanId:null,useRacingLine:!0,standingStart:!1}})}var B$=["front","rear"],Fx=9.81,$$=Math.PI/180;var gn="*",Tx=40,vT=.8;function Px(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 kT(e,t,r){let n=t.rows.map(c=>c.v),o=c=>Ct(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/Fx*100)/100+0,axG:Math.round(u/Fx*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(Tx/3.6,o(Tx/3.6),0);let c=10;for(let l=0;l<30;l++)c=Math.min(s,Math.sqrt(r*o(c)));return a(c,o(c),0)}case"fastCorner":return a(vT*s,o(vT*s),0);case"braking":{let c=i.reduce((l,u)=>t.axDecel(u,0)<t.axDecel(l,0)?u:l);return a(c,0,t.axDecel(c,0))}case"traction":{let c=i.reduce((l,u)=>t.axAccel(u,0)>t.axAccel(l,0)?u:l);return a(c,0,t.axAccel(c,0))}case"topSpeed":return a(s,0,0)}}function Lx(e,t,r){let n=!1,o=e.map(a=>{if(!a.follows)return a;let s=kT(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 Dx(e,t){let r=e.speedKmh/3.6,n=e.ayG*Fx;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)/$$}var MT=e=>e.ayG<0?"L":"R";function Ex(e,t=B$){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 Ix=(e,t)=>e.travelMin===t.travelMin&&e.travelMax===t.travelMax&&e.rollMaxDeg===t.rollMaxDeg&&e.rollAtLimitDeg===t.rollAtLimitDeg;var eo=Math.PI/180,G$=9.81,Jl=.1,_x=20,ST=6,FT=50;function AT(e,t,r){let n=e(0),o=0;for(let p=t;p<=r+1e-9;p+=t){let m=e(p);if(m>n)n=m,o=p;else if(p>o+3*t)break}let a=Math.max(0,o-t),s=Math.min(r,o+t),i=.6180339887498949,c=s-i*(s-a),l=a+i*(s-a),u=e(c),d=e(l);for(let p=0;p<14;p++)u>d?(s=l,l=c,d=u,c=s-i*(s-a),u=e(c)):(a=c,c=l,u=d,l=a+i*(s-a),d=e(l));return u>n?u>=d?{force:u,at:c}:{force:d,at:l}:d>n?{force:d,at:l}:{force:n,at:o}}function Nx(e,t,r,n,o){let a=o*eo;if(t==="side")return AT(i=>r*e.Fy(r*i*eo,n,a),1,45);let s=t==="drive"?1:-1;return AT(i=>s*e.Fx(s*i,n,a),.02,.6)}function jp(e){let t=e?Lm(e)?.gamma:void 0,r=[t?.min,t?.max].filter(o=>o!==void 0&&Number.isFinite(o));if(!r.length)return{lo:-ST,hi:ST,stated:!1};let n=Math.max(...r.map(Math.abs))/eo;return{lo:-n,hi:n,stated:!0}}function K$(e,t,r){if(!(r>t))return t;let n=Math.max(2,Math.ceil(r-t)+1),o=(r-t)/(n-1),a=t,s=-1/0;for(let h=0;h<n;h++){let b=t+h*o,g=e(b);g>s&&(s=g,a=b)}let i=Math.max(t,a-o),c=Math.min(r,a+o),l=.6180339887498949,u=c-l*(c-i),d=i+l*(c-i),p=e(u),m=e(d);for(let h=0;h<12;h++)p>m?(c=d,d=u,m=p,u=c-l*(c-i),p=e(u)):(i=u,u=d,p=m,d=i+l*(c-i),m=e(d));let f=p>=m?{g:u,v:p}:{g:d,v:m};return f.v>s?f.g:a}var wT=250,CT=new WeakMap;function H$(e,t,r,n,o,a,s){let i=CT.get(e);i||CT.set(e,i=new Map);let c=`${t}|${n}|${o}|${s.lo}|${s.hi}`,l=i.get(c);l||i.set(c,l=new Map);let u=f=>{let h=l.get(f);if(h===void 0){let b=Math.max(50,f*wT);h=K$(g=>Nx(r,n,o,b,g).force,s.lo,s.hi),l.set(f,h)}return h},d=Math.max(0,a)/wT,p=Math.floor(d),m=d-p;return m<1e-9?u(p):u(p)*(1-m)+u(p+1)*m}function bi(e,t){return t==="front"?e.tireModel:e.tireModelRear??e.tireModel}var z$=new WeakMap,Y$=new WeakMap,W$=new WeakMap,Ox=(e,t,r)=>{let n=e.get(t);return n===void 0&&e.set(t,n=r()),n};function Up(e,t){let r=bi(e,t);return r?Ox(z$,r,()=>xc(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 Vx(e,t){let r=bi(e,t);return r?Ox(W$,r,()=>Dm(r).none)?"This tyre file has no drive or brake grip.":Ox(Y$,r,()=>{let n=Ke(r),o=r.kind==="magic"?r.fnomin:r.nominalLoad,a=n.Fx(.1,o,0),s=n.Fx(.1,o,3*eo);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 Ia(e,t){return e==="side"||e==="ackermann"?Math.abs(t.ayG)>=Jl?e==="ackermann"&&!(TT(t)<=_x)?`is a corner wider than ${_x} m`:null:"does not corner":(e==="drive"?t.axG:-t.axG)>=Jl?null:e==="drive"?"does not drive":"does not brake"}var j$=e=>e.axG>=Jl?"drive":e.axG<=-Jl?"brake":null;function TT(e){let t=e.speedKmh/3.6,r=Math.abs(e.ayG)*G$;return r>1e-9?t*t/r:1/0}var Wp=(e,t)=>`${e==="front"?"F":"R"}${t}`,U$=e=>e==="L"?"R":"L",X$=(e,t,r)=>Math.min(r,Math.max(t,e));function Bx({ev:e,params:t,input:r,state:n,pose:o}){let a=`${ee(t,"grip_scale")}|${ee(t,"stiffness_scale")}`,s=TT(n),i=r.wheelbase*(1-r.frontMassFrac)/1e3,c=r.wheelbase*r.frontMassFrac/1e3,l=r.wheelbase/1e3,u=v=>(v==="front"?r.trackFront:r.trackRear)/2e3,d=(v,k,R,M,S)=>{let w=we(e,v),F=bi(t,v),T=Math.max(0,o.loads[k]),A=o.camber[k],C=X$(A,S.lo,S.hi),P=Nx(w,R,M,T,C),L=T<FT,E=F&&!L?H$(F,a,w,R,M,T,S):C,_=L?P.force:Nx(w,R,M,T,E).force,D=.05;return{corner:k,Fz:T,lifted:L,camber:A,read:C,outside:C!==A,wants:E,atEdge:!L&&(E-S.lo<D||S.hi-E<D),peak:P.force,slip:P.at,best:_}},p=(v,k,R)=>{let M=k[0].best+k[1].best,S=k[0].peak+k[1].peak;return{kind:v,wheels:k,lossCamber:M>0?Math.max(0,1-S/M):NaN,range:R}},m=new Map,f=v=>{if(m.has(v))return m.get(v)??null;let k=null;if(!Ia("side",n)){let R=jp(bi(t,v));k=[d(v,Wp(v,o.outer),"side",1,R),d(v,Wp(v,U$(o.outer)),"side",-1,R)]}return m.set(v,k),k},h=new Map,b=new Map,g=new Map,y=(v,k,R)=>{let M=v==="front"?i:-c,S=(k?1:-1)*u(v),w=R*eo;return Math.atan2(M+s*Math.sin(w),s*Math.cos(w)-S)/eo},x=v=>(n.ayG<0?-1:1)*o.steer[v];return{side(v){if(h.has(v))return h.get(v)??null;let k=Up(t,v)?null:f(v),R=k?p("side",k,jp(bi(t,v))):null;return h.set(v,R),R},long(v){if(b.has(v))return b.get(v)??null;let k=j$(n),R=null;if(k&&!Vx(t,v)){let M=jp(bi(t,v));R=p(k,[d(v,Wp(v,"L"),k,1,M),d(v,Wp(v,"R"),k,1,M)],M)}return b.set(v,R),R},toeLoss(v){let k=g.get(v);if(k!==void 0)return k;let R=f(v),M=NaN;if(R&&R[0].peak+R[1].peak>0){let S=we(e,v),[w,F]=R,T=[{g:w,dt:1,inner:!1,steer:x(w.corner)},{g:F,dt:-1,inner:!0,steer:x(F.corner)}],A=_=>T.reduce((D,I)=>{let V=I.steer-y(v,I.inner,_);return D+I.dt*S.Fy(I.dt*V*eo,I.g.Fz,I.g.read*eo)},0),C=T.map(_=>_.steer-_.g.slip-y(v,_.inner,0)),P=Math.min(...C)-2,L=Math.max(...C)+2,E=q$(A,P,L,.25);M=Math.max(0,1-E/(w.peak+F.peak))}return g.set(v,M),M},ackermann(){if(Ia("ackermann",n))return NaN;let v=f("front");if(!v||v[0].lifted||v[1].lifted)return NaN;let[k,R]=v,M=Math.sqrt(Math.max(s*s-c*c,1e-6)),S=u("front"),w=(Math.atan(l/(M-S))-Math.atan(l/(M+S)))/eo;if(!(w>.001))return NaN;let F=x(R.corner)-x(k.corner),T=w+(R.slip-k.slip);return 100*(F-T)/w}}}function q$(e,t,r,n){let o=-1/0,a=t;for(let m=t;m<=r+1e-9;m+=n){let f=e(m);f>o&&(o=f,a=m)}let s=a-n,i=a+n,c=.6180339887498949,l=i-c*(i-s),u=s+c*(i-s),d=e(l),p=e(u);for(let m=0;m<14;m++)d>p?(i=u,u=l,p=d,l=i-c*(i-s),d=e(l)):(s=l,l=u,d=p,u=s+c*(i-s),p=e(u));return Math.max(o,d,p)}var Q$=9.81,PT=Math.PI/180,gi={speed:20,ayG:1.2};function $x(e,t={}){let r=t.operating??gi,n=t.assemble,o,a,s,i=new Map,c=new Map,l=new Map,u=new Map,d=new Map,p=k=>({speed:k?.speed!==void 0&&Number.isFinite(k.speed)&&k.speed>0?k.speed:r.speed,ayG:k?.ayG!==void 0&&Number.isFinite(k.ayG)?k.ayG:r.ayG}),m=()=>{if(o!==void 0)return o;if(!n)return o=null;try{o=n(e)}catch{o=null}return o},f=()=>{if(a!==void 0)return a;try{a=un(e.params)}catch{a=null}return a},h=k=>{let R=p(k),M=`${R.speed}|${R.ayG}`,S=i.get(M);if(S!==void 0)return S;let w=f();if(!w)return i.set(M,null),null;let F={cornerStiffness:T=>w.corneringStiffness(T),ayG:R.ayG,speed:R.speed,fyAxle:(T,A)=>2*w.Fy(T,A/2),tire:w};return i.set(M,F),F},b=()=>{if(s!==void 0)return s;let k=m(),R=f();if(!k||!R)return s=null;try{s=ia(R,k.massTotal*Q$*1.2)}catch{s=null}return s},g=k=>{let R=p(k).speed,M=`${R}`,S=c.get(M);if(S!==void 0)return S;let w=m(),F=f(),T=null;if(w&&F)try{T=M0(w,F,R,{steering:!1})}catch{T=null}return c.set(M,T),T},y=k=>{let R=`${k.speedKmh}|${k.ayG}|${k.axG}`,M=d.get(R);if(M!==void 0)return M;let S=null,w=m();try{let F=w?.kinFront,T=w?.kinRear;if(w&&F&&T){let A=Dx(k,w.wheelbase),C=k.speedKmh/3.6,P=yo(w,F,T,C)(k.ayG,k.axG,0,A),L={FL:P.FL.travel,FR:P.FR.travel},E=la(w,A*PT,L),_=A?E.camber:null,D={},I={};for(let O of["FL","FR","RL","RR"]){let B=O[1]==="R"?P[O].camberRoad:0-P[O].camberRoad;D[O]=B+(_?.[O]??0),I[O]=E.steer[O]/PT+(O[1]==="R"?1:-1)*P[O].bumpToe}let V=We(w,k.ayG,k.axG,C,0,A,L,P.steeringJacking);S={corners:P,rollDeg:P.FL.camberRoad-P.FL.camber,steerDeg:A,camber:D,outer:MT(k),loads:V,steer:I}}}catch{S=null}return d.set(R,S),S},x=new Map;return{operating:r,dynAvailable:!!n,poseAt:y,tyreAt:k=>{let R=`${k.speedKmh}|${k.ayG}|${k.axG}`,M=x.get(R);if(M!==void 0)return M;let S=y(k),w=m(),F=f(),T=S&&w&&F?Bx({ev:F,params:e.params,input:w,state:k,pose:S}):null;return x.set(R,T),T},operatingAt:p,dynInput:m,tyre:f,dynCtx:h,grip:b,ymd:g,ymdLimit:k=>{let R=`${p(k).speed}`,M=l.get(R);if(M!==void 0)return M;let S=g(k),w=S?iy(S):null;return l.set(R,w),w},reserves:(k,R)=>{let M=p(R),S=`${k}|${M.speed}|${M.ayG}`,w=u.get(S);if(w!==void 0)return w;let F=m(),T=h(R),A=null;if(F&&T)try{A=Rl(F,T,k,b()??void 0)}catch{A=null}return u.set(S,A),A}}}var LT=["widthLeft","widthRight","bank","mu"];function eu(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 Gx(e){let t=eu(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 qp(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),d=l.to>=c-1e-9;for(let p of LT){let m=l[p];if(m===void 0)continue;let f=s[p],h=r[p];for(let b=0;b<o&&t[b]<l.from;b++)h=f[b];for(let b=0;b<o;b++){let g=t[b];if(g<l.from||g>=l.to&&!(d&&g>=c-1e-9))continue;let y=g-l.from;f[b]=u>0&&y<u?h+(m-h)*(y/u):m}}}return s}function Qp(e,t,r){if(!t.length)return e;let n=eu(e),o=n.length,a={widthLeft:Xp(e.widthLeft,r.widthLeft),widthRight:Xp(e.widthRight,r.widthRight),bank:Xp(e.bank,r.bank),mu:Xp(e.mu,r.mu)},s={};for(let c of LT){let l=e[c];Array.isArray(l)&&l.length===o&&(s[c]=l)}let i=qp(t,n,a,s);return{...e,...i}}function Xp(e,t){return typeof e=="number"?e:t}var IT=1,DT=4,Jp=Math.PI/180,Kx=e=>e===null||!Number.isFinite(e)||e===0?0:1/e;function Hx(e){return e.kind==="arc"?Math.abs(e.radius)*Math.abs(e.angle)*Jp:e.length}function Zp(e,t){return e.kind==="straight"?0:e.kind==="arc"?Kx(e.radius):t}function ET(e){return e.kind==="straight"?0:e.kind==="arc"?Kx(e.radius):Kx(e.endRadius)}var tu=(e,t,r,n,o)=>e+t*o+(n>0?(r-t)*o*o/(2*n):0);function ru(e,t={}){let r=Math.max(.05,t.spacing??IT),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((A,C)=>A+Hx(C),0),d=Math.max(n?3:2,Math.round(u/r)),p=u>0?u/d:r,m=o.x,f=o.y,h=o.heading*Jp,b=e.length?Zp(e[0],0):0,g=0,y=p,x=(A,C,P)=>{s.push(A),i.push(C),c.push(P)};x(m,f,0);let v=(A,C,P,L,E)=>{let _=E-L;if(_<=0)return;if(Math.abs(C-A)<1e-12){let I=tu(h,A,A,P,L);if(Math.abs(A)<1e-12)m+=_*Math.cos(I),f+=_*Math.sin(I);else{let V=I+A*_;m+=(Math.sin(V)-Math.sin(I))/A,f+=-(Math.cos(V)-Math.cos(I))/A}return}let D=_/DT;for(let I=0;I<DT;I++){let V=L+I*D,O=tu(h,A,C,P,V),B=tu(h,A,C,P,V+D/2),z=tu(h,A,C,P,V+D);m+=D/6*(Math.cos(O)+4*Math.cos(B)+Math.cos(z)),f+=D/6*(Math.sin(O)+4*Math.sin(B)+Math.sin(z))}};for(let A of e){let C=Hx(A),P=Zp(A,b),L=ET(A);if(l.push({from:g,to:g+C,...A.widthLeft!==void 0?{widthLeft:A.widthLeft}:{},...A.widthRight!==void 0?{widthRight:A.widthRight}:{},...A.bank!==void 0?{bank:A.bank}:{},...A.mu!==void 0?{mu:A.mu}:{},...A.ramp!==void 0?{ramp:A.ramp}:{}}),C<=0){b=L;continue}let E=0;for(;y<=g+C+1e-9;){let _=Math.min(C,y-g);v(P,L,C,E,_),E=_,x(m,f,g+_),y+=p}v(P,L,C,E,C),h=tu(h,P,L,C,C),b=L,g+=C}let k=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?Zp(e[0],b):0,S={gap:k,headingError:Z$((h-o.heading*Jp)/Jp),curvatureError:b-M},w=[];for(let A=0;A<e.length;A++){let C=ET(e[A]),P=A+1<e.length?e[A+1]:n?e[0]:null;if(!P)continue;let L=Zp(P,C);w.push({index:A,before:C,after:L,jump:Math.abs(L-C)})}let F=qp(l,c,a);return{asset:{name:t.name??"Track",x:s,y:i,fit:"interpolate",...n?{}:{closed:!1},...F},sections:l,joints:w,closure:S,length:R}}function Z$(e){let t=e%360;return t>180&&(t-=360),t<-180&&(t+=360),t}var J$={halfWidthM:1.5,spacingM:.5};function nu(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 ${NT(e).toFixed(0)} m`}}}function NT(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 OT=e=>e.kind==="skidpad"||e.kind==="curves"&&e.closed===!0,VT=e=>e.kind==="acceleration",BT=1.5,$T=3;function eG(e,t){let r=e.offsetM,n=e.pitchM,o=Math.max(1,e.gates)*n,a=Math.max(0,e.leadInM),s=BT*n,i=h=>{let b=Math.min(1,Math.max(0,h));return b*b*b*(b*(b*6-15)+10)},c=h=>Math.min(i(h/s),i((o-h)/s)),l=r*(Math.PI/n)**2,u=l>0?Math.max(.05,Math.min(t.spacingM,1/l*($T*Math.PI/180))):t.spacingM,d=[],p=[],m=Math.max(1,Math.round(a/u));for(let h=0;h<m;h++)d.push(-a+a*h/m),p.push(0);let f=Math.max(8,Math.round(o/u));for(let h=0;h<=f;h++){let b=o*h/f;d.push(b),p.push(r*c(b)*Math.sin(Math.PI*b/n))}return{name:nu(e),x:d,y:p,closed:!1,widthLeft:t.halfWidthM,widthRight:t.halfWidthM,fit:"interpolate"}}function tG(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 zx(e,t={}){let r={...J$,...t},n=VT(e),o=tG(e);if(!o){let u=eG(e,r);return{asset:u,peakCurvature:_T(u),worstJoint:0,standingStart:n}}let a=OT(e),s=o.reduce((u,d)=>d.kind==="arc"?Math.min(u,Math.abs(d.radius)):u,1/0),i=Number.isFinite(s)?Math.max(.05,Math.min(r.spacingM,s*($T*Math.PI/180))):r.spacingM,c=ru(o,{name:nu(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:_T(c.asset),worstJoint:l.reduce((u,d)=>Math.max(u,d.jump),0),standingStart:n}}function _T(e){try{return Math.max(...Ot(e).curvature.map(Math.abs))}catch{return NaN}}var yi={courses:[{id:"c1",course:{kind:"manoeuvre",spec:{kind:"skidpad",radiusM:8.375}}}],ggvMode:"twoTrack"};function Yx(e){return e.course.kind==="project"?"the project\u2019s track":e.course.kind==="track"?e.course.name:nu(e.course.spec)}var tf=()=>({courses:yi.courses.map(e=>({...e})),ggvMode:yi.ggvMode}),GT=new WeakMap,ef=new Map;function KT(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=ef.get(n);if(o)return{...o,numerics:r};let a=zx(e.spec),s={asset:a.asset,standingStart:a.standingStart};return ef.size>64&&ef.clear(),ef.set(n,s),{...s,numerics:r}}function Wx(e,t,r={}){let n=r.lap??yi,o=r.simParams,a=r.numerics??{},s=n.courses.length?n.courses:yi.courses,i,c,l,u=new Map,d=new Map,p=new Map,m=new Map,f=v=>(v?.courseId?s.find(k=>k.id===v.courseId):void 0)??s[0],h=()=>{if(i!==void 0)return i;if(!o)return i=null;try{i={...o(e),ggvMode:n.ggvMode}}catch{i=null}return i},b=v=>{let k=f(v);if(!k)return null;let R=d.get(k.id);if(R!==void 0)return R;let M=KT(k.course,r,a),S=null;if(M)try{let w=JSON.stringify(M.numerics),F=GT.get(M.asset);F||(F=new Map,GT.set(M.asset,F));let T=F.get(w);T||(T=Ot(M.asset,M.numerics),F.set(w,T)),S={id:k.id,track:T,standingStart:M.standingStart,numerics:M.numerics,name:M.asset.name}}catch{S=null}return d.set(k.id,S),S},g=()=>{if(c!==void 0)return c;let v=h();if(!v)return c=null;try{l=ur(v),c=pn(l,!1,n.ggvMode)}catch{c=null}return c},y=v=>{let k=b(v);if(!k)return null;let R=p.get(k.id);if(R!==void 0)return R;let M=g(),S=null;if(M)try{let w=l?Ra(l,M,[k.track],k.numerics,n.ggvMode,u):void 0,F=l?wo(l,M.rows):void 0;S=er(M,k.track,k.numerics,{standingStart:k.standingStart,...w?{load:w}:{},...F?{shifts:F}:{}})}catch{S=null}return p.set(k.id,S),S};return{lapSettings:n,get lapAvailable(){return!!o&&s.some(v=>!!KT(v.course,r,a))},lapParams:h,courses:()=>s,course:b,ggv:g,lap:y,lapReserve:v=>{let k=b(v);if(!k)return null;let R=m.get(k.id);if(R!==void 0)return R;let M=y(v),S=t.dynInput(),w=t.tyre(),F=null;if(M&&S&&w)try{let T=h();F=op(S,w,pp({...M,ds:k.track.ds,rows:g()?.rows,gradient:k.track.gradient,bank:k.track.bank,mu:k.track.mu}),T?{driven:Yg(T)}:{})}catch{F=null}return m.set(k.id,F),F}}}var HT=180/Math.PI,jx={rise:0,sinPitch:0,sinRoll:0};function zT(e){let t=e.kc;return t?YT(e.vehicle,r=>t.ground0[r]):jx}function YT(e,t){let r=e.config,n=fo(r),o=0,a=0,s=0,i=0,c=0,l=0,u=0,d=0,p=0;for(let g of Zr){let y=ze(g,r),x=y.axleX-n,v=y.sideSign*ir(e,y.isFront)/2,k=t(g);if(!Number.isFinite(k))return jx;o++,a+=x,s+=v,i+=k,c+=x*x,l+=v*v,u+=x*v,d+=x*k,p+=v*k}let m=o*(c*l-u*u)-a*(a*l-u*s)+s*(a*u-c*s);if(!(Math.abs(m)>1e-9))return{rise:i/o,sinPitch:0,sinRoll:0};let f=(i*(c*l-u*u)-a*(d*l-u*p)+s*(d*u-c*p))/m,h=(o*(d*l-u*p)-i*(a*l-u*s)+s*(a*p-d*s))/m,b=(o*(c*p-d*u)-a*(a*p-d*s)+i*(a*u-c*s))/m;return{rise:f,sinPitch:h,sinRoll:-b}}function ou(e,t){let r=e.kc,n=YT(e.vehicle,o=>(r?r.ground0[o]:0)+t[o]);return re([-n.sinPitch,n.sinRoll,1])}function Ux(e,t,r,n){let o=re(Tn(e,ze(t,r)));return-Math.asin(Math.max(-1,Math.min(1,J(o,n))))*HT}function rf(e,t,r,n,o){let a=re(Tn(n,ze(t,r))),s=re([1-a[0]*a[0],-a[0]*a[1],-a[0]*a[2]]),i=le(a,s),c=m=>[J(m,s),J(m,i),J(m,a)],l=m=>oe(oe(X(s,m[0]),X(i,m[1])),X(a,m[2])),u=e.points,d=c(u.spinAxis),p=qi({uprightUpper:c(u.uprightUpper),uprightLower:c(u.uprightLower),wheelCenter:c(u.wheelCenter),spinAxis:d,tieOuter:c(u.tieOuter),loadedRadius:o.loadedRadius,patchShift:o.patchShift&&rG(o.patchShift,e.metrics.toe/HT,Math.atan2(d[0],d[1]))});return{caster:p.caster,kpi:p.kpi,scrubRadius:p.scrubRadius,mechanicalTrail:p.mechanicalTrail,scrubAtWheel:p.scrubAtWheel,trailAtWheel:p.trailAtWheel,kingpinOffset:p.kingpinOffset,casterOffset:p.casterOffset,kingpinGround:l(p.kingpinGround),contactPatch:l(p.contactPatch),elbow:l([p.contactPatch[0],p.kingpinGround[1],p.kingpinGround[2]]),kingpinAtHub:l(p.kingpinAtHub)}}function rG(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 nf(e,t){let r=zT(t);if(r===jx)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 Kr(e,t,r){let n=nf({heave:0,pitch:0,roll:0,steer:0},r);return e-ob(n,[t,0,0],fo(r.vehicle.config))}var nG=180/Math.PI;function Xx(e,t){return!e.valid||!e.ic?!1:Math.hypot(e.ic[0]-e.cp[0],e.ic[1]-e.cp[1])<=t}function Tt(e,t,r){let n=ze(t,e.vehicle.config),o=Qt(e,r),a=Sd(e,t,o[t]),s=a.at("uprightUpper"),i=a.at("uprightLower"),c=a.at("contactPatch"),l=a.at("wheelCenter"),u=C=>{let P=a.velocity(C);return[P[0],P[2]]},d=u(c),p=u(l),m=[c[0],c[2]],f=[l[0],l[2]];if(!a.solved)return{ic:null,line:null,cp:m,wc:f,road:[1,0],swingArmAngleDeg:NaN,tanTheta:NaN,tanThetaHub:NaN,valid:!1,unsolved:!0,sinAngle:0};let h=ou(e,{FL:o.FL.ground,FR:o.FR.ground,RL:o.RL.ground,RR:o.RR.ground}),b=Math.hypot(h[0],h[2]),g=[h[0]/b,h[2]/b],y=[g[1],-g[0]],x=C=>{let P=C[0]*g[0]+C[1]*g[1];return Math.abs(P)>1e-9?-(C[0]*y[0]+C[1]*y[1])/P:0},v=a.omega[1],k=Math.hypot(d[0],d[1]),R=Math.abs(v)*1e9>k?[m[0]+d[1]/v,m[1]-d[0]/v]:null,S=R?(C=>{let P=[s[0]-C[0],s[2]-C[1]],L=[i[0]-C[0],i[2]-C[1]];return Math.abs(P[0]*L[1]-P[1]*L[0])/(Math.hypot(...P)*Math.hypot(...L))})(R):0;if(!(Math.abs(d[0]*g[0]+d[1]*g[1])>1e-9))return{ic:R,line:null,cp:m,wc:f,road:y,swingArmAngleDeg:0,tanTheta:0,tanThetaHub:0,valid:!1,sinAngle:S};let w=[d[1]/k,-d[0]/k],F=R?[R[0]-m[0],R[1]-m[1]]:[n.isFront?-1:1,0],T=w[0]*F[0]+w[1]*F[1]<0?[-w[0],-w[1]]:w,A=x(d);return{ic:R,line:T,cp:m,wc:f,road:y,swingArmAngleDeg:Math.atan(A)*nG,tanTheta:A,tanThetaHub:x(p),valid:!0,sinAngle:S}}function WT(e,t,r,n){let o=r/Math.max(1e-6,n.cgHeight),a=t==="front",s=a?n.drive.front:1-n.drive.front,i=a?n.brakeBalanceFront:1-n.brakeBalanceFront,c=(a?n.drive.inboard.front:n.drive.inboard.rear)?e.tanThetaHub:e.tanTheta,l=(a?n.brakeInboard?.front:n.brakeInboard?.rear)?e.tanThetaHub:e.tanTheta,u=a?-1:1;return{brake:u*100*l*o*i,drive:u*100*c*o*s}}function of(e){let t=Math.min(1,Math.max(0,e.frontMassFrac)),r=(1-t)*e.wheelbase,n=t*e.wheelbase;return{x:e.frontAxleX-r,z:e.cgHeight,lf:r,lr:n}}function jT(e,t,r,n,o){let a=o(e.front)&&o(e.rear),s=n>1e-9?(r-t.x)/n:0,i=e.front.height+s*(e.rear.height-e.front.height),c=e.front.lateral+s*(e.rear.lateral-e.front.lateral);return{axisHeightAtCg:i,axisLateralAtCg:c,arm:t.z-i,valid:a}}function UT(e,t,r){return r>1e-9?Math.atan2(t-e,r)*180/Math.PI:Number.NaN}function XT(e,t,r){let{left:n,right:o}=e,a=(n.height+o.height)/2,s=(n.x+o.x)/2;return{axisHeight:a,axisX:s,heightAboveGround:(n.heightAboveGround+o.heightAboveGround)/2,ahead:s-t.x,arm:t.z-a,sinAngle:Math.min(n.sinAngle,o.sinAngle),valid:r(n)&&r(o)}}function qx(e,t){return e.valid?E0([e.x,e.height],e.front.cp,e.rear.cp,e.sinAngle,t):!1}function to(e,t){let r={x:0,height:0,heightAboveGround:0,stationAlongGround:0,valid:!1,sinAngle:0,front:e,rear:t};if(!e.valid||!t.valid||!e.line||!t.line)return r;let n=e.ic?[e.ic[0]-e.cp[0],e.ic[1]-e.cp[1]]:e.line,o=t.ic?[t.ic[0]-t.cp[0],t.ic[1]-t.cp[1]]:t.line,a=Math.hypot(n[0],n[1]),s=Math.hypot(o[0],o[1]),i=a>0&&s>0?Math.abs(n[0]*o[1]-n[1]*o[0])/(a*s):0,c=Ad(e.cp,n,t.cp,o);if(!c)return{...r,sinAngle:i};let l=e.cp[0]-t.cp[0],u=e.cp[1]-t.cp[1],d=Math.hypot(l,u)||1,p=l/d,m=u/d,f=(e.cp[0]+t.cp[0])/2,h=(e.cp[1]+t.cp[1])/2;return{x:c[0],height:c[1],heightAboveGround:(c[0]-t.cp[0])*-m+(c[1]-t.cp[1])*p,stationAlongGround:(c[0]-f)*p+(c[1]-h)*m,valid:!0,sinAngle:i,front:e,rear:t}}var aG=180/Math.PI,sG=Math.PI/180,Qx=.5,af=2,Zx=.25;function eP(e,t,r,n,o){let a=t.frontMassFrac;if(a===void 0||!Number.isFinite(a))return;let s=e.vehicle.config,i=s.wheelbase,c=of({wheelbase:i,frontAxleX:s.frontAxleX,frontMassFrac:a,cgHeight:t.cgHeight}),l=i>1e-9?(s.frontAxleX-c.x)/i:0,u=(m,f)=>m+l*(f-m),d={left:to(...o.left),right:to(...o.right)},p={...c,z:Kr(t.cgHeight,c.x,e)};return{roll:{height:u(r.rollCentreHeight,n.rollCentreHeight),arm:t.cgHeight-u(r.rollCentreHeightChassis,n.rollCentreHeightChassis),slope:UT(r.rollCentreHeight,n.rollCentreHeight,i),usable:r.rollCentreHeightUsable&&n.rollCentreHeightUsable},pitch:XT(d,p,m=>qx(m,i))}}var iG=e=>e.frontMassFrac!==void 0&&Number.isFinite(e.frontMassFrac);function cG(e,t,r){return{FL:Tt(e,"FL",t),FR:Tt(e,"FR",t),RL:Tt(e,"RL",r),RR:Tt(e,"RR",r)}}var lG={heave:0,pitch:0,roll:0,steer:0},uG={FL:"FR",FR:"FL",RL:"RR",RR:"RL"},sf=e=>e.ok?e.state:{...e.nearest,converged:!1};function Jx(e,t,r){return t.state?t.solved===!1?{...t.state,converged:!1}:t.state:sf(Ae(e,t.travel,t.steer,void 0,r))}var qT=new WeakMap;function QT(e,t){let r=e.ctx[t],n=qe(e.vehicle,t).config.loadedRadius,o=vr(n,e.kc,t),a=qT.get(r);a||(a=new Map,qT.set(r,a));let s=a.get(o);if(!s){let i=ho(t,e.vehicle.config,lG,e.vehicle);s=sf(Ae(r,i.travel,i.steer,void 0,o===n?void 0:{loadedRadius:o})),a.set(o,s)}return s}var yn=(e,t)=>!e||!e.lo.converged||!e.hi.converged?NaN:(t(e.hi)-t(e.lo))/(2*e.step),ZT=(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 tP(e,t,r,n,o,a){let s=e.vehicle.config,i=fs(r),c=qe(e.vehicle,r),l=ze(r,s),u=e.ctx[r],d=Qt(e,t),p=d[r],m={travel:p.travel,steer:p.steer},f=p.rigid?void 0:{loadedRadius:p.loadedRadius},h=Jx(u,p,f),b=QT(e,r),g={lo:sf(Ae(u,m.travel-Qx,m.steer,void 0,f)),hi:sf(Ae(u,m.travel+Qx,m.steer,void 0,f)),step:Qx},y=l.isFront?{lo:tt(u,h.beta,m.steer-af,void 0,f),hi:tt(u,h.beta,m.steer+af,void 0,f),step:af}:null,x=Y=>{let K=Qt(e,{...t,roll:t.roll+Y*sG})[r];return Jx(u,K,K.rigid?void 0:{loadedRadius:K.loadedRadius})},v={lo:x(-Zx),hi:x(Zx),step:Zx},k=dG(e,t,r,l.isFront,d,y),R=rt(h.points.contactPatch,l),M=rt(b.points.contactPatch,l),S=Math.abs(R[1])-Math.abs(M[1]),w=uG[r],F=d[w],T=Jx(e.ctx[w],F,F.rigid?void 0:{loadedRadius:F.loadedRadius}),A=T.converged?S+Math.abs(T.points.contactPatch[1])-Math.abs(QT(e,w).points.contactPatch[1]):NaN,C=T.converged?Math.abs(R[1])+Math.abs(T.points.contactPatch[1]):NaN,P=o??$r(e,t,i),L=wd(P,qt(c)),E=L?null:ew(P),_=Us(P),D=l.sideSign>0?P.icRight:P.icLeft,I=D?Math.hypot(D[0]-R[1],D[1]-R[2]):1/0,V=a??Tt(e,r,t),O=V.ic?Math.hypot(V.ic[0]-V.cp[0],V.ic[1]-V.cp[1]):1/0,B=WT(V,i,s.wheelbase,n),z=-yn(g,Y=>Y.points.damperLength),j=c.config.springRate,$=yn(v,Y=>Y.metrics.camber),N=ou(e,{FL:d.FL.ground,FR:d.FR.ground,RL:d.RL.ground,RR:d.RR.ground}),W=e.kc?.loadCase,Z=Y=>W?rf(Y,r,s,N,{loadedRadius:p.loadedRadius,patchShift:W.patchShift[r]}):Y.metrics,q=Z(h);return{id:r,converged:h.converged,travel:h.travel,camber:h.metrics.camber,camberRoad:Ux(h.points.spinAxis,r,s,N),toe:h.metrics.toe,caster:q.caster,kpi:q.kpi,scrubRadius:q.scrubRadius,mechanicalTrail:q.mechanicalTrail,scrubAtWheel:q.scrubAtWheel,trailAtWheel:q.trailAtWheel,kingpinOffset:q.kingpinOffset,casterOffset:q.casterOffset,steeringArm:h.metrics.steeringArm,camberGain:yn(g,Y=>Y.metrics.camber),bumpSteer:yn(g,Y=>Y.metrics.toe),trackScrubRate:yn(g,Y=>Math.abs(rt(Y.points.contactPatch,l)[1])),casterGain:yn(g,Y=>Z(Y).caster),kpiGain:yn(g,Y=>Z(Y).kpi),scrubGain:yn(g,Y=>Z(Y).scrubRadius),trailGain:yn(g,Y=>Z(Y).mechanicalTrail),...l.isFront?{camberPerSteer:ZT(y,Y=>Y.metrics.camber,Y=>Y.metrics.toe),steerJacking:-ZT(y,Y=>Y.points.contactPatch[2],Y=>Y.metrics.toe),...k!==void 0?{steerLoad:k}:{}}:{},rollCamber:$,camberRecovery:-100*l.sideSign*$,rollSteer:l.sideSign*yn(v,Y=>Y.metrics.toe),halfTrackChange:S,trackChange:A,track:C,patchX:R[0],longitudinal:R[0]-M[0],rollCentreHeight:E?E.heightAboveGround:P.heightAboveGround,rollCentreHeightChassis:(E?E.height:P.height)-Kr(0,l.axleX,e),rollCentreLateral:P.lateralAlongGround,rollCentreValid:P.valid,rollCentreUsable:L,rollCentreHeightUsable:L||E!==null,transferHeight:_?_.heightAboveGround:NaN,transferHeightChassis:_?_.height-Kr(0,l.axleX,e):NaN,rollCentreSinAngle:P.sinAngle,fvsaLength:I,svsaLength:O,swingArmAngle:V.swingArmAngleDeg,svsaUsable:Xx(V,s.wheelbase),svsaSinAngle:V.sinAngle,...i==="front"?{antiDive:B.brake,antiLift:B.drive}:{antiSquat:B.drive,antiLift:B.brake},decoupled:c.config.actuation==="decoupled",mcpherson:c.config.layout==="mcpherson",springRate:j,motionRatio:z,wheelRate:j*z*z,damperLength:h.points.damperLength,damperTravel:b.points.damperLength-h.points.damperLength,...mG(c,b.points.damperLength,h.points.damperLength,e.kc?.curve[r].spring?.law),rockerAngle:c.config.actuation==="direct"?0:(h.points.rockerAngle-b.points.rockerAngle)*aG,groundDisplacement:p.rigid?h.travel:p.ground,tyreDeflection:p.tyreDeflection,wheelLoad:p.load,loadedRadiusAt:p.loadedRadius,rideRate:p.rideRate,wheelRateAtLoad:p.wheelRateAtLoad,lifted:p.lifted,clearance:p.clearance??0,tyreRigid:p.rigid}}function mG(e,t,r,n){if(e.config.actuation==="decoupled")return{};let o=n?{droop:n.droopStated?n.droop:null,bump:n.bump}:bs(t,e.config.coilover),a=t-r;return{...o.droop!==null?{damperToExtended:a-o.droop}:{},...o.bump!==null?{damperToClosed:o.bump-a}:{}}}function dG(e,t,r,n,o,a){if(!a||!n)return;let s=im(e,t,"front"),i=e.kc;if(!s||!i)return;let c=["FL","FR"],l=[0,0],u=[0,0],d={lo:[],hi:[]},p=0;for(let h=0;h<2;h++){let b=c[h],g=o[b],y=e.ctx[b],x=g.rigid?void 0:{loadedRadius:g.loadedRadius},R=(b==="FR"?1:-1)*(r==="FR"?1:-1)*af,M=g.state?{q:[...g.state.pose.t,...g.state.pose.omega],phi:g.state.points.rockerAngle}:void 0,S=Ht(Ae(y,g.travel,g.steer-R,M,x)),w=Ht(Ae(y,g.travel,g.steer+R,M,x));if(!S||!w)return NaN;l[h]=w.points.contactPatch[2]-S.points.contactPatch[2],u[h]=Pn(i.curve[b],g.travel,w.points.damperLength)-Pn(i.curve[b],g.travel,S.points.damperLength),d.lo.push(S),d.hi.push(w),b===r&&(p=w.metrics.toe-S.metrics.toe)}let m=i.elements?.front;if(m){let h=[o.FL.travel,o.FR.travel],b=sc(m,h,[d.hi[0],d.hi[1]]),g=sc(m,h,[d.lo[0],d.lo[1]]);u[0]+=b[0]-g[0],u[1]+=b[1]-g[1]}return Math.abs(p)>1e-9?s([0,0],l,u)[r==="FL"?0:1]/p:NaN}function au(e,t,r,n,o,a){return tP(e,t,r==="front"?"FL":"RL",n,o,a)}function eR(e,t,r){let n=Math.min(Math.abs(e),Math.abs(t));return r>0?Math.atan2(n,r/2)*180/Math.PI:0}function tR(e,t,r,n){let o=iG(r)?cG(e,t,t):null,a=au(e,t,"front",r,n?.front,o?.FL),s=au(e,t,"rear",r,n?.rear,o?.RL),i=o?eP(e,r,a,s,{left:[o.FL,o.RL],right:[o.FR,o.RR]}):void 0;return{front:a,rear:s,wheelbaseChange:a.longitudinal-s.longitudinal,wheelbase:a.patchX-s.patchX,...i?{axes:i}:{}}}function cf(e,t,r){let n=e.config.actuation==="decoupled";return{decoupled:n,heave:n&&t?.design.kind==="coil"&&t.linkage&&Ho(t.linkage).kind!=="chassis"?t:void 0,roll:n&&r?.design.kind==="coil"&&r.linkage&&en(e,r.linkage,"coil")?r:void 0}}var rP=16,pG=50,fG=10,hG=4,bG=["upperArm","lowerArm","tieRod","rod","dropLink"],nP=["ballJoint","rodEnd"],rr=e=>typeof e=="number"&&Number.isFinite(e)&&e>0;function nR(e,t){let r=e?.rim;if(r&&rr(r.diameter)&&rr(r.width)&&Number.isFinite(r.offset)&&Number.isFinite(r.wall)&&r.wall>=0)return{...r,from:"typed"};let n=jM(t);return n?{...n,offset:null,wall:hG,from:"tyre"}:null}function rR(e,t){let r=e?.body;if(!r||!rr(r.bodyDiameter))return null;let n=rr(r.shaftDiameter)?r.shaftDiameter:r.bodyDiameter,o=rr(r.stroke)?Math.max(0,r.extended-r.stroke-t):1/0;return{bodyRadius:r.bodyDiameter/2,shaftRadius:n/2,bodyLength:o}}function gG(e){return e&&e.location==="outboard"&&e.packaging?{...e.packaging,effRadius:e.effRadiusMm}:null}function yG(e){if(!e?.linkage||e.design.kind==="none")return null;let t=e.design,r=Math.max(0,P0(t)??0),n=t.kind==="ubar"||t.kind==="blade"||t.kind==="torsionTube"?t.section.od/2:0,o=t.kind==="ubar"?(t.armSection?.od??t.section.od)/2:t.kind==="blade"?Math.max(t.blade.width,t.blade.thickness)/2:n;return{axle:e,armLength:r,barRadius:n,armRadius:o}}function xG(e,t){if(!rr(t)||!e.config||!e.front)return null;let r=e,n=qe(r,"FL"),o=qe(r,"FR");if(n.config.steerMode!=="rack"||o.config.steerMode!=="rack")return null;let a=rt(n.hardpoints.tieInner,ze("FL",r.config)),s=rt(o.hardpoints.tieInner,ze("FR",r.config)),i=Math.hypot(s[0]-a[0],s[1]-a[1],s[2]-a[2]),c=It(n.config);if(!(i>2*c))return null;let l=c/i,u=(d,p)=>[d[0]+(p[0]-d[0])*l,d[1]+(p[1]-d[1])*l,d[2]+(p[2]-d[2])*l];return{a:u(a,s),b:u(s,a),radius:t/2}}function RG(e,t,r){if(!r||!e.config||!r.inboard.every(Number.isFinite)||!rr(r.diameter)||!rr(r.jointDiameter)||!Number.isFinite(r.outboard))return null;let[n,o]=t==="front"?["FL","FR"]:["RL","RR"];return{inboard:{left:rt(r.inboard,ze(n,e.config)),right:rt(r.inboard,ze(o,e.config))},outboard:r.outboard,radius:r.diameter/2,reach:r.jointDiameter/2,limits:{...rr(r.innerAngle)?{innerAngle:r.innerAngle}:{},...rr(r.outerAngle)?{outerAngle:r.outerAngle}:{},...rr(r.plunge)?{plunge:r.plunge}:{}}}}var oR=e=>typeof e=="number"&&Number.isFinite(e)&&e>0&&e<90;function oP(e,t,r){let n=Object.fromEntries(bG.map(i=>[i,(rr(e?.tubes?.[i])?e.tubes[i]:rP)/2])),o=Object.fromEntries(nP.map(i=>[i,(rr(e?.housings?.[i])?e.housings[i]:pG)/2])),a=rR(t.damper,o.rodEnd),s=Object.fromEntries(nP.filter(i=>oR(e?.jointLimits?.[i])).map(i=>[i,e.jointLimits[i]]));return{tube:n,strut:a?a.bodyRadius:rP/2,housing:o,...Object.keys(s).length?{jointLimit:s}:{},uprightWall:typeof e?.uprightWall=="number"&&Number.isFinite(e.uprightWall)&&e.uprightWall>=0?e.uprightWall:fG,rim:nR(e,t.tyre),...rr(e?.tyreGrowth)?{tyreGrowth:e.tyreGrowth}:{},brake:gG(t.brake),damper:a,...vG(t,o.rodEnd,r)}}function vG(e,t,r){let n=!!e.heave?.linkage&&e.heave.design.kind!=="none",o=!!e.arb?.linkage&&e.arb.design.kind==="coil"&&(!r||!!cf(r,void 0,e.arb).roll),a=n?rR(e.heaveDamper,t):null,s=o?rR(e.rollDamper,t):null,i=[...n&&!a?["heave"]:[],...o&&!s?["roll"]:[]];return{arb:yG(e.arb),heave:a&&e.heave?{kind:"heave",axle:e.heave,damper:a}:null,roll:s&&e.arb?{kind:"roll",axle:e.arb,damper:s}:null,...i.length?{unsized:i}:{}}}function aP(e){let t=(r,n)=>r?n?"shafts":"hubs":"undriven";return{front:t(e.front>0,e.inboard.front),rear:t(e.front<1,e.inboard.rear)}}function kG(e,t={}){let r={heaveDamper:t.unitDampers?.heave??t.dampers?.front,rollDamper:t.unitDampers?.roll??t.dampers?.front},n=oP(e.parts?.front,{tyre:t.tyres?.front,brake:t.brakes?.front,damper:t.dampers?.front,arb:t.arbs?.front,heave:t.heaves?.front,...r},e.front),o=oP(e.parts?.rear,{tyre:t.tyres?.rear??t.tyres?.front,brake:t.brakes?.rear,damper:t.dampers?.rear??t.dampers?.front,arb:t.arbs?.rear,heave:t.heaves?.rear,...r},e.rear),a=(s,i)=>{let c=e.parts?.[s]?.driveshaft,l=t.drive?.[s]??"shafts",u=c&&l==="shafts"?RG(e,s,c):null;return{...i,driveshaft:u,shaftIdle:c&&l!=="shafts"?l:null}};return{front:{...a("front",n),rackHousing:xG(e,e.parts?.front?.rackHousing)},rear:a("rear",o)}}function sP(e,t,r={}){return{...e,axles:kG(t,r)}}var _a=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],ro=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],su=(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]],Hr=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]},uP=180/Math.PI,MG=[[1,0,0],[0,1,0],[0,0,1]],iP=(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]],SG=(e,t)=>[ro(e[0],t),ro(e[1],t),ro(e[2],t)];function cP(e,t,r){let n=Hr(_a(t,e)),o=Hr(su(n,_a(r,e)));return[n,su(o,n),o]}function AG(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 aR(e,t,r,n){let o=Hr(_a(t,e)),a=b=>{let g=_a(b,e),y=ro(g,o);return[g[0]-y*o[0],g[1]-y*o[1],g[2]-y*o[2]]},s=Hr(a(r)),i=Hr(a(n)),c=ro(su(s,i),o),u=ro(s,i),d=c,p=1-u,[m,f,h]=o;return[[p*m*m+u,p*m*f+d*h,p*m*h-d*f],[p*m*f-d*h,p*f*f+u,p*f*h+d*m],[p*m*h+d*f,p*f*h-d*m,p*h*h+u]]}var wG=(e,t)=>Math.acos(Math.max(-1,Math.min(1,ro(Hr(e),Hr(t)))))*uP;function CG(e,t){return{upright:AG(cP(e.uprightLower,e.tieOuter,e.wheelCenter),cP(t.uprightLower,t.tieOuter,t.wheelCenter)),uca:t.mcpherson?null:aR(t.ucaFront,t.ucaRear,e.uprightUpper,t.uprightUpper),lca:aR(t.lcaFront,t.lcaRear,e.uprightLower,t.uprightLower),rocker:t.direct?null:aR(t.rockerPivotA,t.rockerPivotB,e.rockerToPushrod,t.rockerToPushrod)}}function FG(e){let t=Hr(e[0]),r=Math.abs(t[0])<.9?[1,0,0]:[0,1,0],n=Hr(su(t,r)),o=su(t,n),a=e.map(h=>{let b=Hr(h);return[ro(b,n),ro(b,o)]}),s=h=>{let b=Math.cos(h),g=Math.sin(h),y=0,x=0;for(let v=0;v<a.length;v++){let k=Math.abs(a[v][0]*b+a[v][1]*g);k>y&&([y,x]=[k,v])}return{v:y,at:x}},i=Math.PI/180,c=0,l=1/0;for(let h=0;h<180;h++){let b=s(h*i).v;b<l&&([c,l]=[h*i,b])}let u=c-i,d=c+i,p=(Math.sqrt(5)-1)/2;for(let h=0;h<30;h++){let b=d-p*(d-u),g=u+p*(d-u);s(b).v<s(g).v?d=g:u=b}let m=s((u+d)/2),f=m.v<l?m:s(c);return{angle:Math.asin(Math.min(1,Math.min(l,m.v)))*uP,at:f.at}}function lP(e){let t=null;for(let r of e)Number.isFinite(r.angle)&&(!t||r.angle>t.angle)&&(t={angle:r.angle,joint:r.joint});return t}var TG={upright:"upright",lowerArm:"lca",upperArm:"uca"};function PG(e,t,r,n){let o=t.map(u=>CG(e,u)),a=Hr(_a(e.uprightUpper,e.uprightLower)),s=(u,d,p)=>{let m=0,f=-1;for(let h=0;h<o.length;h++){let b=o[h],g=b[u]?wG(iP(b.upright,a),iP(b[u],a)):0;g>m&&([m,f]=[g,h])}return{joint:d,group:"ballJoint",angle:m,at:f,ends:p}},i=[s("lca","lower ball joint",["uprightLower","uprightUpper"])];e.mcpherson||i.push(s("uca","upper ball joint",["uprightUpper","uprightLower"]));let c=(u,d,p)=>{let m=[_a(e[d],e[u])];for(let f=0;f<t.length;f++){let h=p(o[f]);if(!h)return null;m.push(SG(h,_a(t[f][d],t[f][u])))}return m},l=[["tie rod, inner end",c("tieInner","tieOuter",()=>MG),["tieInner","tieOuter"]],["tie rod, outer end",c("tieInner","tieOuter",u=>u.upright),["tieOuter","tieInner"]]];e.direct||l.push([`${n}, rocker end`,c("rockerToPushrod","pushrodOuter",u=>u.rocker),["rockerToPushrod","pushrodOuter"]],[`${n}, outer end`,c("rockerToPushrod","pushrodOuter",u=>u[TG[r]]),["pushrodOuter","rockerToPushrod"]]);for(let[u,d,p]of l){if(!d)continue;let m=FG(d);i.push({joint:u,group:"rodEnd",angle:m.angle,at:m.angle>0?m.at-1:-1,ends:p})}return i}function lf(e,t,r,n){let o=PG(e,t,r,n);return{ballJoint:lP(o.filter(a=>a.group==="ballJoint")),rodEnd:lP(o.filter(a=>a.group==="rodEnd"))}}function uf(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),Kr(Math.min(n.zMin,n.zMax),i,t)],max:[s,Math.max(n.yMin,n.yMax),Kr(Math.max(n.zMin,n.zMax),i,t)]}})}var Na=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Sr=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],Pt=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],Ar=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],iu=e=>Math.sqrt(Ar(e,e));function sR(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 iR(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=>Ar(r,e)>=Ar(r,t)?e:t,samples:()=>Array.from({length:41},(r,n)=>Sr(e,Pt(Na(t,e),n/40)))}}function Oa(e){let t=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0];for(let n of e)for(let o=0;o<3;o++)t[o]=Math.min(t[o],n[o]),r[o]=Math.max(r[o],n[o]);return{min:t,max:r,support:n=>{let o=e[0],a=-1/0;for(let s of e){let i=Ar(n,s);i>a&&(a=i,o=s)}return o}}}function xi(e,t,r,n){let o=Pt(t,1/(iu(t)||1)),a=n/2,s=o.map(i=>r*Math.sqrt(Math.max(0,1-i*i))+a*Math.abs(i));return{min:Na(e,s),max:Sr(e,s),support:i=>{let c=Ar(i,o),l=Na(i,Pt(o,c)),u=iu(l),d=u>1e-12?Pt(l,r/u):[0,0,0];return Sr(Sr(e,Pt(o,c>=0?a:-a)),d)},samples:()=>{let i=Math.abs(o[0])<.9?[1,0,0]:[0,1,0],c=Na(i,Pt(o,Ar(i,o))),l=Pt(c,1/iu(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]],d=[];for(let p of[-1,-.5,0,.5,1]){let m=Sr(e,Pt(o,p*a));d.push(m);let f=Math.abs(p)===1?[.5,1]:[1];for(let h of f)for(let b=0;b<72;b++){let g=b/72*2*Math.PI;d.push(Sr(m,Sr(Pt(l,h*r*Math.cos(g)),Pt(u,h*r*Math.sin(g)))))}}return d}}}function LG(e){let t=e[0],r=e.slice(1).map(c=>Na(c,t)),n=r.length;if(n===0)return{v:t,w:[1]};let o=r.map(c=>r.map(l=>Ar(c,l))),a=r.map(c=>-Ar(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 d=o[u][c]/o[c][c];for(let p=c;p<n;p++)o[u][p]-=d*o[c][p];a[u]-=d*a[c]}}let s=a.map((c,l)=>c/o[l][l]),i=t;for(let c=0;c<n;c++)i=Sr(i,Pt(r[c],s[c]));return{v:i,w:[1-s.reduce((c,l)=>c+l,0),...s]}}function DG(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=LG(a.map(c=>c.w));if(!s||s.w.some(c=>c<-1e-9))continue;let i=Ar(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 Ri(e,t,r=1e-9){let n=i=>{let c=e.support(i),l=t.support(Pt(i,-1));return{w:Na(c,l),a:c,b:l}},o=(i,c)=>{let l=[0,0,0],u=[0,0,0];return i.keep.forEach((d,p)=>{l=Sr(l,Pt(d.a,i.weights[p])),u=Sr(u,Pt(d.b,i.weights[p]))}),{distance:c,onA:l,onB:u}},a=n([1,0,0]),s={v:a.w,keep:[a],weights:[1]};for(let i=0;i<64;i++){let c=s.v,l=Ar(c,c);if(l<1e-12)return o(s,0);let u=n(Pt(c,-1));if(l-Ar(c,u.w)<=r*Math.max(1,l))return o(s,Math.sqrt(l));let d=DG([...s.keep,u]);if(d.keep.length===4)return o(d,0);if(Ar(d.v,d.v)>=l-1e-12)return o(s,Math.sqrt(l));s=d}return o(s,iu(s.v))}function EG(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 mf(e,t){let r=0;for(let n=0;n<3;n++){let o=Math.max(0,e.min[n]-t.max[n],t.min[n]-e.max[n]);r+=o*o}return Math.sqrt(r)}var pP={linkRadius:8,mountAllowance:15},IG=(e,t,r)=>e.z0+e.dzdx*t+e.dzdy*r;function _G(e,t){let r=Math.sin(e.pitch);return{z0:-e.heave+t*r,dzdx:-r,dzdy:Math.sin(e.roll)}}function fP(e){return _G(nf({heave:0,pitch:0,roll:0,steer:0},e),fo(e.vehicle.config))}var NG=[{name:"upper wishbone, front leg",inboard:"ucaFront",outboard:"uprightUpper",body:"upperArm",ends:["chassis","upright"]},{name:"upper wishbone, rear leg",inboard:"ucaRear",outboard:"uprightUpper",body:"upperArm",ends:["chassis","upright"]},{name:"lower wishbone, front leg",inboard:"lcaFront",outboard:"uprightLower",body:"lowerArm",ends:["chassis","upright"]},{name:"lower wishbone, rear leg",inboard:"lcaRear",outboard:"uprightLower",body:"lowerArm",ends:["chassis","upright"]},{name:"tie rod",inboard:"tieInner",outboard:"tieOuter",body:"tieRod",ends:["chassis","upright"]},{name:"pushrod",inboard:"rockerToPushrod",outboard:"pushrodOuter",body:"rod",ends:["rocker","rodAttach"]},{name:"strut",inboard:"damperChassis",outboard:"pushrodOuter",body:"strut",ends:["chassis","upright"]}];function cR(e){return NG.filter(t=>t.name==="strut"?e.mcpherson:t.name==="pushrod"?!e.direct:!(e.mcpherson&&t.name.startsWith("upper")))}var hP=(e,t,r)=>e.every((n,o)=>n>=t.min[o]-r&&n<=t.max[o]+r);function mP(e,t,r){let n=Na(t,e),o=iu(n);return o>1e-9?Sr(e,Pt(n,r/o)):e}function lR(e,t,r){let n=Ri(e,t),o=n.distance>0?null:EG(e,t),a=n.distance>0?n.distance-r:-((o?.depth??0)+r),s=n.distance>0?{part:mP(n.onB,n.onA,r),box:n.onA}:o?{part:mP(o.point,o.face,-r),box:o.face}:{part:n.onB,box:n.onA};return{distance:a,gap:s}}function dP(e,t){let r=null;for(let{shape:n,pad:o,part:a,pose:s}of t){if(r){let c=mf(e,n);if(c>0&&c-o>=r.distance)continue}let i=lR(e,n,o);Number.isFinite(i.distance)&&(!r||i.distance<r.distance)&&(r={distance:i.distance,part:a,corner:s.corner,travel:s.travel,rack:s.rack,gap:i.gap})}return r}function OG(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:Pt(a.reduce((c,l)=>Sr(c,l),[0,0,0]),1/a.length)}}function bP(e,t){return{...OG(e,r=>r[2]-IG(t,r[0],r[1])),road:t}}function gP(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 VG(e,t){let r=e.map(o=>({pose:o,part:`${o.corner} tyre`,pad:0,shape:xi(o.g.wheelCenter,o.g.spinAxis,o.corner[0]==="F"?t.tyreRadius.front:t.tyreRadius.rear,t.tyreWidth)})),n=e.flatMap(o=>cR(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:iR(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 BG(e,t,r){let n=sR(e.min,e.max),o=t.links.filter(a=>!hP(a.inboard,e,r.mountAllowance+r.linkRadius));return{tyre:dP(n,t.tyres),link:dP(n,o)}}function yP(e,t,r){let n=VG(t,r);return e.map(o=>({boxId:o.id,...BG(o,n,r)}))}var $G={r:[1,0,0,0,1,0,0,0,1],t:[0,0,0]},RP={r:[1,0,0,0,-1,0,0,0,1],t:[0,0,0]},Vt=(e,t)=>[e.r[0]*t[0]+e.r[1]*t[1]+e.r[2]*t[2]+e.t[0],e.r[3]*t[0]+e.r[4]*t[1]+e.r[5]*t[2]+e.t[1],e.r[6]*t[0]+e.r[7]*t[1]+e.r[8]*t[2]+e.t[2]],df=(e,t)=>[e.r[0]*t[0]+e.r[1]*t[1]+e.r[2]*t[2],e.r[3]*t[0]+e.r[4]*t[1]+e.r[5]*t[2],e.r[6]*t[0]+e.r[7]*t[1]+e.r[8]*t[2]];function vP(e){let t=[e.r[0],e.r[3],e.r[6],e.r[1],e.r[4],e.r[7],e.r[2],e.r[5],e.r[8]],r=df({r:t,t:[0,0,0]},e.t);return{r:t,t:[-r[0],-r[1],-r[2]]}}function cu(e,t){let r=[];for(let n=0;n<3;n++)for(let o=0;o<3;o++)r.push(e.r[3*n]*t.r[o]+e.r[3*n+1]*t.r[3+o]+e.r[3*n+2]*t.r[6+o]);return{r,t:Vt(e,t.t)}}function uR(e){let t=ds(e,[1,0,0]),r=ds(e,[0,1,0]),n=ds(e,[0,0,1]);return[t[0],r[0],n[0],t[1],r[1],n[1],t[2],r[2],n[2]]}function GG(e){let r=e.map(a=>[...a]),n=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];for(let a=0;a<60;a++){let s=0;for(let i=0;i<4;i++)for(let c=i+1;c<4;c++)s+=r[i][c]*r[i][c];if(s<1e-30)break;for(let i=0;i<4;i++)for(let c=i+1;c<4;c++){if(Math.abs(r[i][c])<1e-300)continue;let l=(r[c][c]-r[i][i])/(2*r[i][c]),u=Math.sign(l||1)/(Math.abs(l)+Math.sqrt(l*l+1)),d=1/Math.sqrt(u*u+1),p=u*d;for(let m=0;m<4;m++){let f=r[m][i],h=r[m][c];r[m][i]=d*f-p*h,r[m][c]=p*f+d*h}for(let m=0;m<4;m++){let f=r[i][m],h=r[c][m];r[i][m]=d*f-p*h,r[c][m]=p*f+d*h}for(let m=0;m<4;m++){let f=n[m][i],h=n[m][c];n[m][i]=d*f-p*h,n[m][c]=p*f+d*h}}}let o=0;for(let a=1;a<4;a++)r[a][a]>r[o][o]&&(o=a);return[n[0][o],n[1][o],n[2][o],n[3][o]]}var xP=e=>{let t=[0,0,0];for(let r of e)for(let n=0;n<3;n++)t[n]+=r[n]/e.length;return t};function kP(e,t){let r=Math.min(e.length,t.length);if(r===0)return{iso:$G,residuals:[]};let n=xP(e.slice(0,r)),o=xP(t.slice(0,r)),a=[0,0,0,0,0,0,0,0,0];for(let R=0;R<r;R++){let M=[e[R][0]-n[0],e[R][1]-n[1],e[R][2]-n[2]],S=[t[R][0]-o[0],t[R][1]-o[1],t[R][2]-o[2]];for(let w=0;w<3;w++)for(let F=0;F<3;F++)a[3*w+F]+=M[w]*S[F]}let[s,i,c,l,u,d,p,m,f]=a,h=[[s+u+f,d-m,p-c,i-l],[d-m,s-u-f,i+l,p+c],[p-c,i+l,-s+u-f,d+m],[i-l,p+c,d+m,-s-u+f]],b=GG(h),g=Math.hypot(b[0],b[1],b[2],b[3])||1,y=uR([b[0]/g,b[1]/g,b[2]/g,b[3]/g]),x=df({r:y,t:[0,0,0]},n),v={r:y,t:[o[0]-x[0],o[1]-x[1],o[2]-x[2]]},k=[];for(let R=0;R<r;R++){let M=Vt(v,e[R]);k.push(Math.hypot(M[0]-t[R][0],M[1]-t[R][1],M[2]-t[R][2]))}return{iso:v,residuals:k}}var qpe=Math.PI/180;function MP(e,t,r,n){let o=(Math.sqrt(5)-1)/2,a=t,s=r,i=s-o*(s-a),c=a+o*(s-a),l=e(i),u=e(c);for(;s-a>n;)l<=u?(s=c,c=i,u=l,i=s-o*(s-a),l=e(i)):(a=i,i=c,l=u,c=a+o*(s-a),u=e(c));return l<=u?{x:i,v:l}:{x:c,v:u}}var KG=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],SP=e=>Math.hypot(e[0],e[1],e[2]);var HG=(e,t,r)=>[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r,e[2]+(t[2]-e[2])*r],AP=(...e)=>e.every(t=>t.every(Number.isFinite)),zG={rocker:"rocker",lowerArm:"lowerArm",upright:"upright"};function wP(e,t,r,n,o){if(cf(t,void 0,e.axle).roll)return[];let a=XA(e.axle,t,r,e.armLength);if(!AP(a.tip,a.outer,a.root))return[];let s=o.housing.rodEnd,i={kind:"link",corner:n},c=[{...i,id:`${n} drop link`,name:"drop link",body:"dropLink",ends:["arb",zG[e.axle.linkage.attach]],a:a.tip,b:a.outer,radius:o.tube.dropLink,housing:[s,s]}];if(e.armLength>0){c.push({...i,id:`${n} anti-roll bar arm`,name:"anti-roll bar arm",body:"arb",ends:["arb","arb"],a:a.root,b:a.tip,radius:e.armRadius,housing:[0,s]});let l=[a.root[0],-a.root[1],a.root[2]];c.push({...i,id:`${n} anti-roll bar`,name:"anti-roll bar",body:"arb",ends:["chassis","chassis"],a:a.root,b:l,radius:e.barRadius,housing:[0,0],shared:!0})}return c}function CP(e,t){return{kind:"link",id:`${t} rack housing`,name:"rack housing",corner:t,body:"rackHousing",ends:["rack","rack"],a:e.a,b:e.b,radius:e.radius,housing:[0,0],shared:!0,flat:!0}}function YG(e){let t=SP(e.spinAxis)||1,r=[e.spinAxis[0]/t,e.spinAxis[1]/t,e.spinAxis[2]/t],n=e.wheelCenter[1]>=0?1:-1;return r[1]*n<0?[-r[0],-r[1],-r[2]]:r}function WG(e,t){let r=YG(e);return[e.wheelCenter[0]-r[0]*t,e.wheelCenter[1]-r[1]*t,e.wheelCenter[2]-r[2]*t]}var jG=(e,t)=>t[1]==="L"?e.inboard.left:e.inboard.right;function FP(e,t,r){let n=jG(e,r),o=WG(t,e.outboard);return AP(n,o)?{kind:"link",id:`${r} driveshaft`,name:"driveshaft",corner:r,body:"driveshaft",ends:["chassis","upright"],a:n,b:o,radius:e.radius,housing:[e.reach,e.reach]}:null}function TP(e,t,r,n,o,a,s,i){let c=SP(KG(a.p,o.p)),l=Math.min(c,s.bodyLength),u=l>=c,d=c>1e-9?HG(o.p,a.p,l/c):o.p,p={kind:"link",corner:n,body:r},m={...p,id:`${e} body`,name:`${t} body`,ends:[o.body,u?a.body:r],endCorners:[o.corner,u?a.corner:n],a:o.p,b:d,radius:s.bodyRadius,housing:[i,u?i:0],flat:!0};return u?[m]:[m,{...p,id:`${e} shaft`,name:`${t} shaft`,ends:[r,a.body],endCorners:[n,a.corner],a:d,b:a.p,radius:s.shaftRadius,housing:[0,i]}]}var vi=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],ff=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],Lo=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],mR=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],hf=e=>Math.sqrt(mR(e,e)),dR=(e,t,r)=>ff(e,Lo(vi(t,e),r));function PP(e,t,r){let n=e.diameter/2,o=Math.max(n,t),a=r/2,s=Math.min(a,e.width/2),i=(n+o)/2,c=[];for(let l=0;l<3;l++){let u=s+(a-s)*(l+1)/3;c.push({z0:-u,z1:u,r0:n+(i-n)*l/3,r1:n+(i-n)*(l+1)/3})}return c.push({z0:-a,z1:a,r0:i,r1:o}),c}function LP(e){let t=e.diameter/2,r=UG(e),n=e.width/2,o={z0:-n,z1:n,r0:r,r1:t};if(e.offset===null)return[o];let a=Math.min(n,Math.max(-n,e.offset));return[o,{z0:a,z1:n,r0:0,r1:r}]}var UG=e=>Math.max(0,e.diameter/2-e.wall);function XG(e,t){let r=vi(e,t.centre),n=mR(r,t.axis),o=vi(r,Lo(t.axis,n)),a=hf(o);if(a>1e-9)return{z:n,r:a,out:Lo(o,1/a)};let s=Math.abs(t.axis[0])<.9?[1,0,0]:[0,1,0],i=vi(s,Lo(t.axis,mR(s,t.axis)));return{z:n,r:0,out:Lo(i,1/hf(i))}}function qG(e,t,r){if(!(t>e.z0&&t<e.z1&&r<e.r1&&(e.r0>0?r>e.r0:r>=0))){let s=Math.min(e.z1,Math.max(e.z0,t)),i=Math.min(e.r1,Math.max(e.r0,r));return{d:Math.hypot(t-s,r-i),z:s,r:i}}let o=[{d:t-e.z0,z:e.z0,r},{d:e.z1-t,z:e.z1,r},{d:e.r1-r,z:t,r:e.r1}];e.r0>0&&o.push({d:r-e.r0,z:t,r:e.r0});let a=o.reduce((s,i)=>i.d<s.d?i:s);return{d:-a.d,z:a.z,r:a.r}}function lu(e,t,r){let n=XG(e,r),o={d:1/0,z:0,r:0};for(let a of t){let s=qG(a,n.z,n.r);s.d<o.d&&(o=s)}return{distance:o.d,on:ff(ff(r.centre,Lo(r.axis,o.z)),Lo(n.out,o.r))}}var pf=(Math.sqrt(5)-1)/2;function QG(e,t,r,n){let o=t,a=r,s=a-pf*(a-o),i=o+pf*(a-o),c=e(s),l=e(i);for(;a-o>n;)c<=l?(a=i,i=s,l=c,s=a-pf*(a-o),c=e(s)):(o=s,s=i,c=l,i=o+pf*(a-o),l=e(i));return c<=l?s:i}var ZG=24;function DP(e,t,r,n){let o=u=>lu(dR(e,t,u),r,n).distance,a=hf(vi(t,e))<1e-9?0:ZG,s=0,i=o(0);for(let u=1;u<=a;u++){let d=o(u/a);d<i&&(i=d,s=u)}if(a===0)return{t:0,distance:i};let c=QG(o,Math.max(0,(s-1)/a),Math.min(1,(s+1)/a),1e-4),l=o(c);return l<i?{t:c,distance:l}:{t:s/a,distance:i}}function EP(e,t,r,n,o){let{t:a}=DP(e,t,n,o),s=dR(e,t,a),i=lu(s,n,o);return{distance:i.distance-r,onPart:_P(s,i.on,r,i.distance),onWheel:i.on}}function IP(e,t,r,n){let o=null,a=i=>{let c=lu(i,r,n);(!o||c.distance<o.distance)&&(o={p:i,distance:c.distance,on:c.on})};for(let i of e)a(i);for(let i=0;i<e.length;i++)for(let c=i+1;c<e.length;c++){let l=DP(e[i],e[c],r,n);(!o||l.distance<o.distance)&&a(dR(e[i],e[c],l.t))}let s=o;return{distance:s.distance-t,onPart:_P(s.p,s.on,t,s.distance),onWheel:s.on}}function _P(e,t,r,n){let o=vi(t,e),a=hf(o);return a<1e-9||r===0?e:ff(e,Lo(o,(n>=0?r:-r)/a))}function xf(e,t,r,n,o){let a=r[0]-t[0],s=r[1]-t[1],i=r[2]-t[2],c=n[0]-t[0],l=n[1]-t[1],u=n[2]-t[2],d=e[0]-t[0],p=e[1]-t[1],m=e[2]-t[2],f=a*d+s*p+i*m,h=c*d+l*p+u*m,b=(_,D,I)=>{o[0]=_,o[1]=D,o[2]=I;let V=e[0]-_,O=e[1]-D,B=e[2]-I;return V*V+O*O+B*B};if(f<=0&&h<=0)return b(t[0],t[1],t[2]);let g=e[0]-r[0],y=e[1]-r[1],x=e[2]-r[2],v=a*g+s*y+i*x,k=c*g+l*y+u*x;if(v>=0&&k<=v)return b(r[0],r[1],r[2]);let R=f*k-v*h;if(R<=0&&f>=0&&v<=0){let _=f/(f-v);return b(t[0]+_*a,t[1]+_*s,t[2]+_*i)}let M=e[0]-n[0],S=e[1]-n[1],w=e[2]-n[2],F=a*M+s*S+i*w,T=c*M+l*S+u*w;if(T>=0&&F<=T)return b(n[0],n[1],n[2]);let A=F*h-f*T;if(A<=0&&h>=0&&T<=0){let _=h/(h-T);return b(t[0]+_*c,t[1]+_*l,t[2]+_*u)}let C=v*T-F*k;if(C<=0&&k-v>=0&&F-T>=0){let _=(k-v)/(k-v+(F-T));return b(r[0]+_*(n[0]-r[0]),r[1]+_*(n[1]-r[1]),r[2]+_*(n[2]-r[2]))}let P=1/(C+A+R),L=A*P,E=R*P;return b(t[0]+a*L+c*E,t[1]+s*L+l*E,t[2]+i*L+u*E)}function pR(e,t,r,n,o,a){let s=t[0]-e[0],i=t[1]-e[1],c=t[2]-e[2],l=n[0]-r[0],u=n[1]-r[1],d=n[2]-r[2],p=e[0]-r[0],m=e[1]-r[1],f=e[2]-r[2],h=s*s+i*i+c*c,b=l*l+u*u+d*d,g=l*p+u*m+d*f,y=S=>S<0?0:S>1?1:S,x=0,v=0;if(h<=1e-12&&b<=1e-12)x=0,v=0;else if(h<=1e-12)v=y(g/b);else{let S=s*p+i*m+c*f;if(b<=1e-12)x=y(-S/h);else{let w=s*l+i*u+c*d,F=h*b-w*w;x=F>1e-12?y((w*g-S*b)/F):0,v=(w*x+g)/b,v<0?(v=0,x=y(-S/h)):v>1&&(v=1,x=y((w-S)/h))}}o[0]=e[0]+x*s,o[1]=e[1]+x*i,o[2]=e[2]+x*c,a[0]=r[0]+v*l,a[1]=r[1]+v*u,a[2]=r[2]+v*d;let k=o[0]-a[0],R=o[1]-a[1],M=o[2]-a[2];return k*k+R*R+M*M}function JG(e,t,r,n,o,a){let s=t[0]-e[0],i=t[1]-e[1],c=t[2]-e[2],l=n[0]-r[0],u=n[1]-r[1],d=n[2]-r[2],p=o[0]-r[0],m=o[1]-r[1],f=o[2]-r[2],h=i*f-c*m,b=c*p-s*f,g=s*m-i*p,y=l*h+u*b+d*g,x=Math.sqrt((s*s+i*i+c*c)*(l*l+u*u+d*d)*(p*p+m*m+f*f));if(Math.abs(y)<=1e-12*x)return!1;let v=1/y,k=e[0]-r[0],R=e[1]-r[1],M=e[2]-r[2],S=(k*h+R*b+M*g)*v;if(S<0||S>1)return!1;let w=R*d-M*u,F=M*l-k*d,T=k*u-R*l,A=(s*w+i*F+c*T)*v;if(A<0||S+A>1)return!1;let C=(p*w+m*F+f*T)*v;return C<0||C>1?!1:(a[0]=e[0]+C*s,a[1]=e[1]+C*i,a[2]=e[2]+C*c,!0)}function Rf(e,t,r,n,o,a,s){if(JG(e,t,r,n,o,s))return a[0]=s[0],a[1]=s[1],a[2]=s[2],0;let i=[0,0,0],c=[0,0,0],l=xf(e,r,n,o,s);a[0]=e[0],a[1]=e[1],a[2]=e[2];let u=(d,p,m)=>{d>=l||(l=d,a[0]=p[0],a[1]=p[1],a[2]=p[2],s[0]=m[0],s[1]=m[1],s[2]=m[2])};return u(xf(t,r,n,o,c),t,c),u(pR(e,t,r,n,i,c),i,c),u(pR(e,t,n,o,i,c),i,c),u(pR(e,t,o,r,i,c),i,c),l}function hR(e,t,r,n){let o=e.box,a=6*t,s=0;for(let i=0;i<3;i++){let c=Math.max(0,o[a+i]-n[i],r[i]-o[a+3+i]);s+=c*c}return s}function fR(e,t,r){for(let n of r){let o=0;for(let a=0;a<3;a++){let s=Math.max(Math.abs(n.c[a]-e[t+a]),Math.abs(e[t+3+a]-n.c[a]));o+=s*s}if(o<=n.r*n.r)return!0}return!1}function vf(e,t,r,n,o){let a=n;if(!e.nodes)return a;let s=[0],i=[t(0)];for(;s.length;){let c=s.pop();if(i.pop()>=a||o.length&&fR(e.box,6*c,o))continue;if(e.right[c]<0){let f=e.start[c]+e.size[c];for(let h=e.start[c];h<f;h++){let b=r(h,a);if(b<a&&(a=b),a<=0)return 0}continue}let u=c+1,d=e.right[c],p=t(u),m=t(d);p<=m?(m<a&&(s.push(d),i.push(m)),p<a&&(s.push(u),i.push(p))):(p<a&&(s.push(u),i.push(p)),m<a&&(s.push(d),i.push(m)))}return a}function VP(e,t,r){let n=[Math.min(t[0],r[0]),Math.min(t[1],r[1]),Math.min(t[2],r[2])],o=[Math.max(t[0],r[0]),Math.max(t[1],r[1]),Math.max(t[2],r[2])],a=r[0]-t[0],s=r[1]-t[1],i=r[2]-t[2],c=a*a+s*s+i*i,l=e.box;return u=>{let d=6*u,p=(l[d]+l[d+3])/2,m=(l[d+1]+l[d+4])/2,f=(l[d+2]+l[d+5])/2,h=(l[d+3]-l[d])/2,b=(l[d+4]-l[d+1])/2,g=(l[d+5]-l[d+2])/2,y=c>1e-12?((p-t[0])*a+(m-t[1])*s+(f-t[2])*i)/c:0;y=y<0?0:y>1?1:y;let x=p-t[0]-y*a,v=m-t[1]-y*s,k=f-t[2]-y*i,R=Math.sqrt(x*x+v*v+k*k)-Math.sqrt(h*h+b*b+g*g);return Math.max(R,Math.sqrt(hR(e,u,n,o)))}}var Ut=(e,t,r)=>{let n=9*t+3*r;return[e.tri[n],e.tri[n+1],e.tri[n+2]]};function uu(e,t,r,n=1/0,o=[]){let a=VP(e,t,r),s=[0,0,0],i=[0,0,0],c=null,l=vf(e,a,(u,d)=>{let p=1/0;return no(Ut(e,u,0),Ut(e,u,1),Ut(e,u,2),o,(m,f,h)=>{let b=Math.sqrt(Rf(t,r,m,f,h,s,i));b<p&&(p=b),b<d&&(!c||b<c.distance)&&(c={distance:b,onMesh:[...i],onPart:[...s]})}),p},n,o);return c&&c.distance===l?c:null}function kf(e,t,r,n,o,a=1/0,s=[]){let i=xi(t,r,n,o),c=Math.hypot(r[0],r[1],r[2])||1,l=r[0]/c,u=r[1]/c,d=r[2]/c,p=o/2,m=[t[0]-p*l,t[1]-p*u,t[2]-p*d],f=[t[0]+p*l,t[1]+p*u,t[2]+p*d],h=e.box,b=VP(e,m,f),g=R=>{let M=6*R,S=(h[M]+h[M+3])/2,w=(h[M+1]+h[M+4])/2,F=(h[M+2]+h[M+5])/2,T=(h[M+3]-h[M])/2,A=(h[M+4]-h[M+1])/2,C=(h[M+5]-h[M+2])/2,P=(S-t[0])*l+(w-t[1])*u+(F-t[2])*d,L=Math.abs(l)*T+Math.abs(u)*A+Math.abs(d)*C,E=Math.max(0,Math.abs(P)-L-p);return Math.max(E,b(R)-n,Math.sqrt(hR(e,R,i.min,i.max)))},y=[0,0,0],x=[0,0,0],v=null,k=vf(e,g,(R,M)=>{let S=1/0;return no(Ut(e,R,0),Ut(e,R,1),Ut(e,R,2),s,(w,F,T)=>{let A=Math.min(M,S),C=(w[0]-t[0])*l+(w[1]-t[1])*u+(w[2]-t[2])*d,P=(F[0]-t[0])*l+(F[1]-t[1])*u+(F[2]-t[2])*d,L=(T[0]-t[0])*l+(T[1]-t[1])*u+(T[2]-t[2])*d;if(Math.max(0,Math.min(C,P,L)-p,-p-Math.max(C,P,L))>=A||Math.sqrt(Rf(m,f,w,F,T,y,x))-n>=A)return;let _=Ri(Oa([w,F,T]),i,1e-6);if(_.distance<A)if(_.distance>0)v={distance:_.distance,onMesh:_.onA,onPart:_.onB};else{let D=[0,0,0];xf(t,w,F,T,D),v={distance:0,onMesh:D,onPart:D}}_.distance<S&&(S=_.distance)}),S},a,s);return v&&v.distance===k?v:null}var bR=(e,t,r)=>uu(e,t,t,r)!==null,bf=(e,t)=>{let r=e[0]-t.c[0],n=e[1]-t.c[1],o=e[2]-t.c[2];return r*r+n*n+o*o<=t.r*t.r},ki=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2,(e[2]+t[2])/2],Mi=(e,t)=>(e[0]-t[0])**2+(e[1]-t[1])**2+(e[2]-t[2])**2,eK=1,tK=6;function no(e,t,r,n,o,a=0){if(!n.length)return o(e,t,r);let s=[0,0,0],i=n.filter(p=>xf(p.c,e,t,r,s)<=p.r*p.r);if(!i.length)return o(e,t,r);for(let p of i)if(bf(e,p)&&bf(t,p)&&bf(r,p))return;if(Math.sqrt(Math.max(Mi(e,t),Mi(t,r),Mi(r,e)))<=Math.max(eK,Math.min(...i.map(p=>p.r))/8)||a>=tK){let p=[(e[0]+t[0]+r[0])/3,(e[1]+t[1]+r[1])/3,(e[2]+t[2]+r[2])/3];i.some(m=>bf(p,m))||o(e,t,r);return}let l=ki(e,t),u=ki(t,r),d=ki(r,e);no(e,l,d,i,o,a+1),no(l,t,u,i,o,a+1),no(d,u,r,i,o,a+1),no(l,u,d,i,o,a+1)}function rK(e,t,r,n){let o=[];return no(e,t,r,n,(a,s,i)=>o.push([a,s,i])),o}var nK=e=>[Math.min(e[0][0],e[1][0],e[2][0]),Math.min(e[0][1],e[1][1],e[2][1]),Math.min(e[0][2],e[1][2],e[2][2]),Math.max(e[0][0],e[1][0],e[2][0]),Math.max(e[0][1],e[1][1],e[2][1]),Math.max(e[0][2],e[1][2],e[2][2])];function gR(e,t,r=1/0,n=[]){let o=null,a=vf(e,s=>Math.sqrt(hR(e,s,t.min,t.max)),(s,i)=>{let c=1/0;return no(Ut(e,s,0),Ut(e,s,1),Ut(e,s,2),n,(l,u,d)=>{let p=Oa([l,u,d]),m=Math.min(i,c),f=0;for(let b=0;b<3;b++){let g=Math.max(0,p.min[b]-t.max[b],t.min[b]-p.max[b]);f+=g*g}if(Math.sqrt(f)>=m)return;let h=Ri(p,t,1e-6);if(h.distance<m)if(h.distance>0)o={distance:h.distance,onMesh:h.onA,onPart:h.onB};else{let b=[(l[0]+u[0]+d[0])/3,(l[1]+u[1]+d[1])/3,(l[2]+u[2]+d[2])/3];o={distance:0,onMesh:b,onPart:b}}h.distance<c&&(c=h.distance)}),c},r,n);return o&&o.distance===a?o:null}function oK(e,t,r,n,o,a,s,i){let c=[0,0,0],l=[0,0,0],u=1/0,d=(f,h,b)=>{f>=u||(u=f,s[0]=h[0],s[1]=h[1],s[2]=h[2],i[0]=b[0],i[1]=b[1],i[2]=b[2])},p=[e,t,r],m=[n,o,a];for(let f=0;f<3;f++)if(d(Rf(p[f],p[(f+1)%3],n,o,a,c,l),c,l),u===0)return 0;for(let f=0;f<3;f++)if(d(Rf(m[f],m[(f+1)%3],e,t,r,c,l),l,c),u===0)return 0;return u}var aK=.002;function yR(e,t,r,n=1/0,o=[]){if(!e.nodes||!t.nodes)return null;let a=new Float64Array(6*t.nodes).fill(NaN),s=x=>{let v=6*x;if(!Number.isNaN(a[v]))return v;let k=1/0,R=1/0,M=1/0,S=-1/0,w=-1/0,F=-1/0;for(let T=0;T<8;T++){let A=Vt(r,[t.box[v+(T&1?3:0)],t.box[v+1+(T&2?3:0)],t.box[v+2+(T&4?3:0)]]);A[0]<k&&(k=A[0]),A[0]>S&&(S=A[0]),A[1]<R&&(R=A[1]),A[1]>w&&(w=A[1]),A[2]<M&&(M=A[2]),A[2]>F&&(F=A[2])}return a.set([k,R,M,S,w,F],v),v},i=(x,v)=>{let k=6*x,R=s(v),M=0;for(let S=0;S<3;S++){let w=Math.max(0,e.box[k+S]-a[R+3+S],a[R+S]-e.box[k+3+S]);M+=w*w}return Math.sqrt(M)},c=(x,v)=>(x[v+3]-x[v])**2+(x[v+4]-x[v+1])**2+(x[v+5]-x[v+2])**2,l=(x,v,k)=>{let R=[Ut(x,v,0),Ut(x,v,1),Ut(x,v,2)];return k?R.map(M=>Vt(k,M)):R},u=new Map,d=new Map,p=(x,v,k,R)=>{let M=R.get(v);if(!M){M=[];let S=x.start[v]+x.size[v];for(let w=x.start[v];w<S;w++)for(let F of rK(...l(x,w,k),o))M.push({t:F,box:nK(F)});R.set(v,M)}return M},m=n,f=n,h=null,b=[0,0,0],g=[0,0,0],y=[[0,0,i(0,0)]];for(;y.length;){let[x,v,k]=y.pop();if(k>=f||o.length&&(fR(e.box,6*x,o)||fR(a,s(v),o)))continue;let R=e.right[x]<0,M=t.right[v]<0;if(R&&M){let A=p(t,v,r,d);if(!A.length)continue;for(let C of p(e,x,null,u))for(let P of A){let L=0;for(let _=0;_<3;_++){let D=Math.max(0,C.box[_]-P.box[3+_],P.box[_]-C.box[3+_]);L+=D*D}if(L>=f*f)continue;let E=Math.sqrt(oK(C.t[0],C.t[1],C.t[2],P.t[0],P.t[1],P.t[2],b,g));if(E<m&&(m=E,f=E*(1-aK),h={distance:E,onA:[...b],onB:[...g]},m<=0))return h}continue}let w=!R&&(M||c(e.box,6*x)>=c(a,s(v)))?[[x+1,v],[e.right[x],v]]:[[x,v+1],[x,t.right[v]]],F=w.map(([A,C])=>i(A,C)),T=F[0]<=F[1]?[1,0]:[0,1];for(let A of T)F[A]<f&&y.push([w[A][0],w[A][1],F[A]])}return h}function gf(e,t){let r=e[0]-t.centre[0],n=e[1]-t.centre[1],o=e[2]-t.centre[2],a=r*t.axis[0]+n*t.axis[1]+o*t.axis[2],s=r-a*t.axis[0],i=n-a*t.axis[1],c=o-a*t.axis[2];return[a,Math.sqrt(s*s+i*i+c*c)]}function NP(e,t,r,n,o){let a=1/0;for(let s of o){let i=Math.max(0,s.z0-t,e-s.z1),c=Math.max(0,s.r0-n,r-s.r1),l=Math.hypot(i,c);l<a&&(a=l)}return a}var yf=8;function BP(e,t,r,n=1/0,o=[]){if(!r.length)return null;let a=e.box,s=m=>{let f=6*m,h=1/0,b=-1/0,g=0;for(let y=0;y<8;y++){let[x,v]=gf([a[f+(y&1?3:0)],a[f+1+(y&2?3:0)],a[f+2+(y&4?3:0)]],t);x<h&&(h=x),x>b&&(b=x),v>g&&(g=v)}return NP(h,b,0,g,r)},i=m=>lu(m,r,t),c=null,l=(m,f)=>{let h=i(m),b=Math.max(0,h.distance);return b<f&&(!c||b<c.distance)&&(c={distance:b,onMesh:m,onPart:b>0?h.on:m}),b},u=(m,f,h)=>{let b=T=>i([m[0]+(f[0]-m[0])*T,m[1]+(f[1]-m[1])*T,m[2]+(f[2]-m[2])*T]).distance,g=0,y=1/0;for(let T=1;T<yf;T++){let A=b(T/yf);A<y&&(y=A,g=T)}let x=(g-1)/yf,v=(g+1)/yf,k=(Math.sqrt(5)-1)/2,R=v-k*(v-x),M=x+k*(v-x),S=b(R),w=b(M);for(;v-x>.001;)S<=w?(v=M,M=R,w=S,R=v-k*(v-x),S=b(R)):(x=R,R=M,S=w,M=x+k*(v-x),w=b(M));let F=S<=w?R:M;return l([m[0]+(f[0]-m[0])*F,m[1]+(f[1]-m[1])*F,m[2]+(f[2]-m[2])*F],h)},d=(m,f,h,b,g)=>{let y=gf(m,t),x=gf(f,t),v=gf(h,t);if(NP(Math.min(y[0],x[0],v[0]),Math.max(y[0],x[0],v[0]),0,Math.max(y[1],x[1],v[1]),r)>=b)return 1/0;if(Math.max(Mi(m,f),Mi(f,h),Mi(h,m))>OP*OP&&g<4){let S=ki(m,f),w=ki(f,h),F=ki(h,m),T=1/0;for(let[A,C,P]of[[m,S,F],[S,f,w],[F,w,h],[S,w,F]])T=Math.min(T,d(A,C,P,Math.min(b,T),g+1));return T}let M=1/0;for(let S of[m,f,h])M=Math.min(M,l(S,Math.min(b,M)));return M=Math.min(M,u(m,f,Math.min(b,M)),u(f,h,Math.min(b,M)),u(h,m,Math.min(b,M))),M},p=vf(e,s,(m,f)=>{let h=1/0;return no(Ut(e,m,0),Ut(e,m,1),Ut(e,m,2),o,(b,g,y)=>{h=Math.min(h,d(b,g,y,Math.min(f,h),0))}),h},n,o);return c&&c.distance===p?c:null}var OP=25;var vR=["upright","wheel","upperArm","lowerArm","rocker","damperBody"],kR={upright:"upright",wheel:"wheel",upperArm:"upper wishbone",lowerArm:"lower wishbone",rocker:"rocker",damperBody:"damper body"},iK=.5;function MR(e,t,r){let n=[];switch(t){case"upright":case"wheel":e.mcpherson||n.push("uprightUpper"),n.push("uprightLower","tieOuter"),(e.mcpherson||r==="upright")&&n.push("pushrodOuter");break;case"upperArm":if(e.mcpherson)return[];n.push("ucaFront","ucaRear","uprightUpper"),r==="upperArm"&&n.push("pushrodOuter");break;case"lowerArm":n.push("lcaFront","lcaRear","uprightLower"),r==="lowerArm"&&!e.mcpherson&&n.push("pushrodOuter");break;case"rocker":if(e.direct)return[];n.push("rockerPivotA","rockerPivotB","rockerToPushrod","rockerToDamper");break;case"damperBody":if(e.decoupled||e.mcpherson)return[];n.push("damperChassis",e.direct?"pushrodOuter":"rockerToDamper");break}return n.filter(o=>e[o].every(Number.isFinite))}var cK=e=>e[1]==="L"?"left":"right",lK=e=>[e[0],-e[1],e[2]];function $P(e,t,r,n,o){let a=MR(r,t,o).filter(f=>e.placedOn[f]?.every(Number.isFinite)),s=cK(n)!==e.side,i=a.map(f=>s?lK(e.placedOn[f]):e.placedOn[f]),c=a.map(f=>r[f]),l=s?RP:null;if(t==="damperBody"){if(a.length<2)return null;let f=Mf(Si(i[1],i[0])),h=Mf(Si(c[1],c[0])),b=uR(Uu(f,h)),g=Vt({r:b,t:[0,0,0]},i[0]),y={r:b,t:Si(c[0],g)};return{iso:l?cu(y,l):y,worst:null}}if(a.length<3)return null;let u=kP(i,c),d=Math.max(...u.residuals),p=0,m=-1;for(let f=0;f<a.length;f++){let h=0;for(let b=0;b<a.length;b++)b!==f&&(h+=Math.abs(RR(Si(i[f],i[b]))-RR(Si(c[f],c[b]))));h>m&&([p,m]=[f,h])}return{iso:l?cu(u.iso,l):u.iso,worst:{key:a[p],by:d}}}var GP=e=>!!e&&(!e.worst||e.worst.by<=iK);var uK=1,xR=.5;function mK(e,t,r=uK){let n=Mf(t.axis),o=Math.abs(n[0])<.9?[1,0,0]:[0,1,0],a=Mf(Si(o,KP(n,mu(o,n)))),s=fK(n,a),i=Math.floor(e.length/9),c=new Float64Array(9*i),l=1/0,u=-1/0;for(let h=0;h<3*i;h++){let b=[e[3*h]-t.centre[0],e[3*h+1]-t.centre[1],e[3*h+2]-t.centre[2]],g=mu(b,n);c[3*h]=mu(b,a),c[3*h+1]=mu(b,s),c[3*h+2]=g,g<l&&(l=g),g>u&&(u=g)}if(!i)return[];let d=Math.max(1,Math.ceil((u-l)/r)),p=new Float64Array(d).fill(1/0),m=new Float64Array(d).fill(-1/0);for(let h=0;h<i;h++){let b=[0,1,2].map(k=>[c[9*h+3*k],c[9*h+3*k+1],c[9*h+3*k+2]]),g=Math.min(b[0][2],b[1][2],b[2][2]),y=Math.max(b[0][2],b[1][2],b[2][2]),x=Math.max(0,Math.min(d-1,Math.floor((g-l)/r))),v=Math.max(0,Math.min(d-1,Math.floor((y-l)/r)));for(let k=x;k<=v;k++){let R=dK(b,l+k*r,l+(k+1)*r);if(!R.length)continue;let M=0;for(let w of R)M=Math.max(M,Math.hypot(w[0],w[1]));let S=pK(R);S<p[k]&&(p[k]=S),M>m[k]&&(m[k]=M)}}let f=[];for(let h=0;h<d;h++){if(!(m[h]>=0))continue;let b=p[h]<xR?0:p[h],g=f[f.length-1],y=l+h*r;g&&Math.abs(g.z1-y)<1e-9&&Math.abs(g.r0-b)<=xR&&Math.abs(g.r1-m[h])<=xR?(g.z1=y+r,g.r0=Math.min(g.r0,b),g.r1=Math.max(g.r1,m[h])):f.push({z0:y,z1:y+r,r0:b,r1:m[h]})}return f}function dK(e,t,r){let n=(o,a)=>{let s=[];for(let i=0;i<o.length;i++){let c=o[i],l=o[(i+1)%o.length],u=a(c),d=a(l);if(u>=0&&s.push(c),u>=0!=d>=0){let p=u/(u-d);s.push([c[0]+(l[0]-c[0])*p,c[1]+(l[1]-c[1])*p,c[2]+(l[2]-c[2])*p])}}return s};return n(n(e,o=>o[2]-t),o=>r-o[2])}function pK(e){let t=!1,r=!1,n=1/0;for(let o=0;o<e.length;o++){let a=e[o],s=e[(o+1)%e.length],i=a[0]*s[1]-a[1]*s[0];i>1e-12?t=!0:i<-1e-12&&(r=!0);let c=s[0]-a[0],l=s[1]-a[1],u=c*c+l*l,d=u>1e-18?Math.max(0,Math.min(1,-(a[0]*c+a[1]*l)/u)):0;n=Math.min(n,Math.hypot(a[0]+d*c,a[1]+d*l))}return t!==r?0:n}var Si=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],mu=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],fK=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],RR=e=>Math.sqrt(mu(e,e)),KP=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],Mf=e=>KP(e,1/(RR(e)||1));function HP(e,t,r){if(!e.bands){let n=e.tree.tri,o=new Float64Array(n.length);for(let a=0;a+2<n.length;a+=3){let s=Vt(t,[n[a],n[a+1],n[a+2]]);o[a]=s[0],o[a+1]=s[1],o[a+2]=s[2]}e.bands=mK(o,r)}return e.bands}var UP=25,ft=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],wr=e=>Math.hypot(e[0],e[1],e[2]),br=(e,t,r)=>[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r,e[2]+(t[2]-e[2])*r],AR={lowerArm:"lowerArm",upperArm:"upperArm",upright:"upright"},hK=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],Ba=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],du=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],zr=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],Sf=e=>zr(e,1/(wr(e)||1)),bK={"upper wishbone, front leg":{tube:"upperArm",joints:["ballJoint","ballJoint"]},"upper wishbone, rear leg":{tube:"upperArm",joints:["ballJoint","ballJoint"]},"lower wishbone, front leg":{tube:"lowerArm",joints:["ballJoint","ballJoint"]},"lower wishbone, rear leg":{tube:"lowerArm",joints:["ballJoint","ballJoint"]},"tie rod":{tube:"tieRod",joints:["rodEnd","rodEnd"]},pushrod:{tube:"rod",joints:["rodEnd","rodEnd"]},strut:{tube:"strut",joints:["ballJoint","ballJoint"]}},gK=(e,t)=>e.axles?.[t[0]==="F"?"front":"rear"]??null;function yK(e,t){let r=Sf(e.spinAxis),n=ft(e.uprightUpper,e.uprightLower),o=Sf(ft(n,zr(r,Ba(n,r)))),a=hK(r,o);a[0]<0&&(a=zr(a,-1));let s=t.discDiameter/2+t.caliperHeight,i=Math.max(0,Math.min(t.discDiameter/2,2*t.effRadius-t.discDiameter/2)),c=t.caliperAngle*Math.PI/180,l=Math.min(Math.PI/2,t.caliperLength/2/Math.max(1,s)),u=(p,m,f)=>du(du(e.wheelCenter,zr(r,f)),du(zr(o,m*Math.cos(p)),zr(a,m*Math.sin(p)))),d=[];for(let p of[t.discOffset-t.caliperWidth/2,t.discOffset+t.caliperWidth/2]){for(let m of[-1,-.5,0,.5,1])d.push(u(c+m*l,s,p));for(let m of[-1,1])d.push(u(c+m*l,i,p))}return d}function xK(e,t){let r=[];return e.mcpherson||r.push(e.uprightUpper),r.push(e.uprightLower,e.tieOuter),(e.mcpherson||t==="upright")&&r.push(e.pushrodOuter),r.filter(n=>n.every(Number.isFinite))}function XP(e,t,r,n,o){let a=[],s=gK(n,t),i=vK(s,e,t,r),c=!!s?.rackHousing&&t[0]==="F";for(let f of cR(e)){if(f.body==="upperArm"&&i.has("upperArm")||f.body==="lowerArm"&&i.has("lowerArm"))continue;let h=e[f.inboard],b=e[f.outboard];if(![...h,...b].every(Number.isFinite))continue;let g=[c&&f.name==="tie rod"?"rack":f.ends[0],f.ends[1]==="rodAttach"?AR[r]:f.ends[1]],y=bK[f.name],x=!s||!y?n.linkRadius:y.tube==="strut"?s.strut:s.tube[y.tube],v=s&&y?[s.housing[y.joints[0]],s.housing[y.joints[1]]]:[n.jointAllowance,n.jointAllowance];a.push({kind:"link",id:`${t} ${f.name}`,name:f.name,corner:t,body:f.body,ends:g,a:h,b,radius:x,housing:v})}let l=s?.damper;if(l&&!e.decoupled&&!e.mcpherson){let f=e.damperChassis,h=e.direct?e.pushrodOuter:e.rockerToDamper,b=e.direct?AR[r]:"rocker";if([...f,...h].every(Number.isFinite)){let g=TP(`${t} damper`,"damper","damper",t,{p:f,body:"chassis",corner:t},{p:h,body:b,corner:t},l,s.housing.rodEnd);a.push(...i.has("damperBody")?g.filter(y=>y.id!==`${t} damper body`):g)}}s?.arb&&o&&a.push(...wP(s.arb,o.def,o.r,t,s)),s?.rackHousing&&t[0]==="F"&&a.push(CP(s.rackHousing,t));let u=s?.driveshaft?FP(s.driveshaft,e,t):null;u&&a.push(u);let d={centre:e.wheelCenter,axis:Sf(e.spinAxis)},p=t[0]==="F"?n.tyreRadius.front:n.tyreRadius.rear;a.push({kind:"tyre",id:`${t} tyre`,name:"tyre",corner:t,body:"wheel",centre:e.wheelCenter,axis:e.spinAxis,radius:p,width:n.tyreWidth,section:s?.rim?PP(s.rim,p,n.tyreWidth):null});let m=i.get("wheel");if(m?a.push({kind:"rim",id:`${t} rim`,name:"rim",corner:t,body:"wheel",frame:d,bands:HP(m.live,m.fit.iso,d),model:!0}):s?.rim&&a.push({kind:"rim",id:`${t} rim`,name:"rim",corner:t,body:"wheel",frame:d,bands:LP(s.rim)}),s){let f=xK(e,r);f.length&&!i.has("upright")&&a.push({kind:"hull",id:`${t} upright`,name:"upright",corner:t,body:"upright",points:f,radius:s.uprightWall}),s.brake&&a.push({kind:"hull",id:`${t} caliper`,name:"caliper",corner:t,body:"upright",points:yK(e,s.brake),radius:0})}for(let[f,h]of i)f!=="wheel"&&a.push(SK(f,h.live,h.fit,e,t,r,n,s));return a}var RK={upright:"upright",upperArm:"upperArm",lowerArm:"lowerArm",rocker:"rocker",damperBody:"damper"};function vK(e,t,r,n){let o=new Map;if(!e?.models)return o;for(let a of vR){let s=e.models[a];if(!s)continue;let i=$P(s,a,t,r,n);GP(i)&&o.set(a,{live:s,fit:i})}return o}var kK=["ucaFront","ucaRear","lcaFront","lcaRear","uprightUpper","uprightLower"];function MK(e,t,r,n){switch(t){case"uprightUpper":return e==="upright"?"upperArm":"upright";case"uprightLower":return e==="upright"?"lowerArm":"upright";case"tieOuter":return"tieRod";case"pushrodOuter":return e==="damperBody"?AR[n]:r.mcpherson?"strut":"rod";case"rockerToPushrod":return"rod";case"rockerToDamper":return e==="rocker"?"damper":"rocker";default:return"chassis"}}function SK(e,t,r,n,o,a,s,i){let c=MR(n,e,a).map(l=>({key:l,p:n[l],on:MK(e,l,n,a),reach:i?i.housing[kK.includes(l)?"ballJoint":"rodEnd"]:s.jointAllowance}));return{kind:"model",id:`${o} ${kR[e]} model`,name:`${kR[e]} model`,corner:o,body:RK[e],piece:e,tree:t.tree,iso:r.iso,inverse:vP(r.iso),ends:[...new Set(c.map(l=>l.on))],joints:c}}function AK(e,t,r){let n=e.ends[t];if(n==="chassis")return!1;let o=e.endCorners?.[t]??e.corner;return r.body===n&&r.corner===o||r.ends.some((a,s)=>a===n&&(r.endCorners?.[s]??r.corner)===o)}var zP=(e,t)=>(e.body==="rod"||e.body==="dropLink")&&e.ends[1]===t.body&&(e.endCorners?.[1]??e.corner)===t.corner,YP=(e,t)=>e.body==="damper"&&e.ends[1]===t.body;function CR(e,t,r){return e.find(({parts:[n,o]})=>n===t.name&&o===r.name||n===r.name&&o===t.name)}function qP(e,t,r=[]){let n=[],o=(d,p,m,f,h=!1)=>{let b=f?void 0:CR(r,d,p);n.push({a:d,b:p,name:`${d.name} / ${p.name}`,trim:m,skip:b?"ignored":f,...b?{reason:b.reason}:{},...h?{fixed:h}:{}})},a=e.filter(d=>d.kind==="link");for(let d=0;d<a.length;d++)for(let p=d+1;p<a.length;p++){let m=wK(a[d],a[p],r);m&&n.push(m)}let s=e.find(d=>d.kind==="tyre"&&d.section!==null),i=e.find(d=>d.kind==="rim");for(let d of a)s&&o(d,s,[0,0,0,0],null),i&&o(d,i,[0,0,0,0],null);let c=e.filter(d=>d.kind==="hull");for(let d of c)i&&o(d,i,[0,0,0,0],null,!0);let l=c.find(d=>d.name==="caliper");if(l)for(let d of a)o(d,l,[d.ends[0]==="upright"?d.housing[0]:0,d.ends[1]==="upright"?d.housing[1]:0,0,0],null);let u=e.filter(d=>d.kind==="model");for(let d=0;d<u.length;d++){let p=u[d];for(let m of a){let f=CK(p,m,r);f&&n.push(f)}s&&p.body!=="upright"&&o(p,s,[0,0,0,0],null),i&&o(p,i,[0,0,0,0],null,p.body==="upright"),l&&p.body!=="upright"&&o(p,l,[0,0,0,0],null);for(let m=d+1;m<u.length;m++)o(p,u[m],[0,0,0,0],null)}for(let d of t)for(let p of e)p.kind==="tyre"||p.kind==="model"||p.kind==="link"&&!p.shared?o(d,p,[0,0,0,0],null):p.kind==="link"&&p.corner[1]==="L"&&d.kind==="volume"&&o(d,p,[0,0,0,0],null,!0);return n}function wK(e,t,r=[]){if(e.body===t.body&&e.corner===t.corner)return null;let n=(i,c,l)=>AK(i,c,l)?i.housing[c]:0,o=[n(e,0,t),n(e,1,t),n(t,0,e),n(t,1,e)],a=zP(e,t)||zP(t,e)?"rod on arm":YP(e,t)||YP(t,e)?"damper on arm":null,s=a?void 0:CR(r,e,t);return{a:e,b:t,name:`${e.name} / ${t.name}`,trim:o,skip:s?"ignored":a,...s?{reason:s.reason}:{},...e.shared&&t.shared?{fixed:!0}:{}}}function CK(e,t,r=[]){if(t.body===e.body&&t.corner===e.corner)return null;let n=i=>{let c=t.ends[i];return c==="chassis"?0:(t.endCorners?.[i]??t.corner)===e.corner&&(c===e.body||e.ends.includes(c))?t.housing[i]:0},a=(t.body==="rod"||t.body==="dropLink")&&t.ends[1]===e.body&&(t.endCorners?.[1]??t.corner)===e.corner?"rod on arm":t.body==="damper"&&t.ends[1]===e.body?"damper on arm":null,s=a?void 0:CR(r,e,t);return{a:e,b:t,name:`${e.name} / ${t.name}`,trim:[0,0,n(0),n(1)],skip:s?"ignored":a,...s?{reason:s.reason}:{}}}function pu(e,t,r,n){let o=wr(ft(t,e));if(o<=r+n){let a=br(e,t,.5);return[a,a]}return[br(e,t,r/o),br(e,t,1-n/o)]}function xn(e,t,r){let n=ft(t,e),o=wr(n);return o>1e-9?br(e,t,r/o):e}function WP(e,t,r,n){let o=ft(r,t),a=wr(o),s=a>1e-12?zr(o,1/a):[1,0,0],i=Ba(ft(e,t),s),c=ft(ft(e,t),zr(s,i)),l=wr(c),u=Math.max(0,Math.min(a,i)),d=l>n?zr(c,n/l):c,p=du(du(t,zr(s,u)),d);return{distance:wr(ft(e,p)),on:p}}function QP(e,t,r,n){let o=ft(t,e),a=ft(n,r),s=ft(e,r),i=Ba(o,o),c=Ba(a,a),l=Ba(a,s),u=b=>Math.max(0,Math.min(1,b));if(i<=1e-12&&c<=1e-12)return{s:0,t:0};if(i<=1e-12)return{s:0,t:u(l/c)};let d=Ba(o,s);if(c<=1e-12)return{s:u(-d/i),t:0};let p=Ba(o,a),m=i*c-p*p,f=m>1e-12?u((p*l-d*c)/m):0,h=(p*f+l)/c;return h<0?(h=0,f=u(-d/i)):h>1&&(h=1,f=u((p-d)/i)),{s:f,t:h}}function FK(e,t,r,n,o){let{s:a,t:s}=QP(r,n,e,t);if(a>1e-9&&a<1-1e-9){let p=br(r,n,a),m=br(e,t,s),f=wr(ft(m,p));if(f>=o)return{distance:f-o,onSeg:m,onCyl:xn(p,m,o)}}let i=p=>WP(br(e,t,p),r,n,o).distance,l=[0,wr(ft(t,e))<1e-12?0:MP(i,0,1,1e-7).x,1].reduce((p,m)=>i(m)<i(p)?m:p),u=br(e,t,l),d=WP(u,r,n,o);return{distance:d.distance,onSeg:u,onCyl:d.on}}function wR(e,t,r){let n=ft(r,t),o=wr(n);return!e.flat||o<1e-9?{shape:iR(t,r),pad:e.radius}:{shape:xi(br(t,r,.5),zr(n,1/o),e.radius,o),pad:0}}function jP(e,t,r){let n=wR(e.part,e.p0,e.p1),o="part"in t?wR(t.part,t.p0,t.p1):t,a="part"in t?t.part.radius:t.radius,s=n.pad+o.pad;if(mf(n.shape,o.shape)-s>=r)return null;let i=-(e.part.radius+a);if("part"in t&&e.part.flat!==t.part.flat){let[l,u]=e.part.flat?[t,e]:[e,t],d=FK(l.p0,l.p1,u.p0,u.p1,u.part.radius),[p,m]=e.part.flat?[d.onCyl,d.onSeg]:[d.onSeg,d.onCyl];if(d.distance<=1e-9)return{distance:i,onA:p,onB:m};let f=l.part.radius;return e.part.flat?{distance:d.distance-f,onA:p,onB:xn(m,p,f)}:{distance:d.distance-f,onA:xn(p,m,f),onB:m}}if("part"in t&&e.part.flat&&t.part.flat){let{s:l,t:u}=QP(e.p0,e.p1,t.p0,t.p1),d=p=>p>1e-9&&p<1-1e-9;if(d(l)&&d(u)){let p=br(e.p0,e.p1,l),m=br(t.p0,t.p1,u),f=wr(ft(m,p));if(f>=e.part.radius+t.part.radius)return{distance:f-e.part.radius-t.part.radius,onA:xn(p,m,e.part.radius),onB:xn(m,p,t.part.radius)}}}let c=Ri(n.shape,o.shape,e.part.flat||"part"in t&&t.part.flat?1e-6:1e-9);return c.distance<=0?{distance:i,onA:c.onA,onB:c.onB}:{distance:c.distance-s,onA:xn(c.onA,c.onB,n.pad),onB:xn(c.onB,c.onA,o.pad)}}var TK=["chassis","rack"];function PK(e,t,r,n){let o,a=!1;if(t.kind==="link"){let i=[0,0];for(let d of[0,1])TK.includes(t.ends[d])&&bR(e.tree,d===0?t.a:t.b,r.mountAllowance)&&(i[d]=t.housing[d],a=!0);let[c,l]=pu(t.a,t.b,i[0],i[1]),u=wr(ft(l,c));if(!t.flat||u<1e-9){let d=uu(e.tree,c,l,n+t.radius);o=d&&{...d,distance:d.distance-t.radius,onPart:d.distance>1e-9?xn(d.onPart,d.onMesh,t.radius):d.onPart}}else o=kf(e.tree,br(c,l,.5),ft(l,c),t.radius,u,Math.max(0,n))}else o=kf(e.tree,t.centre,t.axis,t.radius,t.width,Math.max(0,n));if(!o)return null;let s=o.distance<=0;return{distance:s?0:o.distance,onA:o.onMesh,onB:s?o.onMesh:o.onPart,...s?{touches:!0}:{},...a?{mounted:!0}:{}}}function ZP(e,t,r=1/0){let{a:n,b:o}=e;if(n.kind==="model"||o.kind==="model")return DK(e,t,r);if(n.kind==="mesh"&&(o.kind==="link"||o.kind==="tyre"))return PK(n,o,t,r);if(n.kind==="link"&&o.kind==="link"){let[a,s]=pu(n.a,n.b,e.trim[0],e.trim[1]),[i,c]=pu(o.a,o.b,e.trim[2],e.trim[3]);return jP({part:n,p0:a,p1:s},{part:o,p0:i,p1:c},r)}if(n.kind==="volume"&&(o.kind==="link"||o.kind==="tyre")){let a=sR(n.box.min,n.box.max),s=o.kind==="link"?wR(o,o.a,o.b):null,i=s?s.shape:xi(o.centre,o.axis,o.radius,o.width),c=s?s.pad:0,l=mf(a,i);if(l>0&&l-c>=r)return null;let u=lR(a,i,c);return{distance:u.distance,onA:u.gap.box,onB:u.gap.part}}if(n.kind==="link"&&(o.kind==="rim"||o.kind==="tyre"&&o.section)){let a=o.kind==="rim"?o.bands:o.section,s=o.kind==="rim"?o.frame:{centre:o.centre,axis:o.axis},i=EP(n.a,n.b,n.radius,a,s);return{distance:i.distance,onA:i.onPart,onB:i.onWheel}}if(n.kind==="hull"&&o.kind==="rim"){let a=IP(n.points,n.radius,o.bands,o.frame);return{distance:a.distance,onA:a.onPart,onB:a.onWheel}}if(n.kind==="link"&&o.kind==="hull"){let[a,s]=pu(n.a,n.b,e.trim[0],e.trim[1]);return jP({part:n,p0:a,p1:s},{shape:Oa(o.points),pad:o.radius,radius:o.radius},r)}return null}function Va(e,t,r,n=!1){let o=e<=0;return{distance:o?0:e,onA:t,onB:o?t:r,...o?{touches:!0}:{},...n?{mounted:!0}:{}}}var LK=(e,t)=>e.joints.filter(r=>t.joints.some(n=>n.key===r.key)).map(r=>({c:r.p,r:2*r.reach})),SR=(e,t)=>t.map(r=>({c:Vt(e.inverse,r.c),r:r.r}));function DK(e,t,r){let{a:n,b:o}=e,a=(s,i)=>Vt(s.iso,i);if(n.kind==="model"&&o.kind==="link"){let[s,i]=pu(o.a,o.b,e.trim[2],e.trim[3]),c=SR(n,[0,1].filter(m=>e.trim[2+m]>0).map(m=>({c:m===0?o.a:o.b,r:e.trim[2+m]+o.radius}))),l=Vt(n.inverse,s),u=Vt(n.inverse,i),d=wr(ft(u,l));if(!o.flat||d<1e-9){let m=uu(n.tree,l,u,r+o.radius,c);if(!m)return null;let f=m.distance>1e-9?xn(m.onPart,m.onMesh,o.radius):m.onPart;return Va(m.distance-o.radius,a(n,m.onMesh),a(n,f))}let p=kf(n.tree,br(l,u,.5),ft(u,l),o.radius,d,Math.max(0,r),c);return p&&Va(p.distance,a(n,p.onMesh),a(n,p.onPart))}if(n.kind==="model"&&o.kind==="model"){let s=yR(n.tree,o.tree,cu(n.inverse,o.iso),Math.max(0,r),SR(n,LK(n,o)));return s&&Va(s.distance,a(n,s.onA),a(n,s.onB))}if(n.kind==="model"&&(o.kind==="rim"||o.kind==="tyre"&&o.section)){let s=o.kind==="rim"?o.bands:o.section,i=o.kind==="rim"?o.frame:{centre:o.centre,axis:o.axis},c={centre:Vt(n.inverse,i.centre),axis:df(n.inverse,Sf(i.axis))},l=BP(n.tree,c,s,Math.max(0,r));return l&&Va(l.distance,a(n,l.onMesh),a(n,l.onPart))}if(n.kind==="model"&&o.kind==="hull"){let s=SR(n,n.joints.filter(l=>l.on==="upright").map(l=>({c:l.p,r:l.reach}))),i=gR(n.tree,Oa(o.points.map(l=>Vt(n.inverse,l))),r+o.radius,s);if(!i)return null;let c=i.distance>1e-9?xn(i.onPart,i.onMesh,o.radius):i.onPart;return Va(i.distance-o.radius,a(n,i.onMesh),a(n,c))}if(n.kind==="volume"&&o.kind==="model"){let{min:s,max:i}=n.box,c=[];for(let u=0;u<8;u++)c.push(Vt(o.inverse,[u&1?i[0]:s[0],u&2?i[1]:s[1],u&4?i[2]:s[2]]));let l=gR(o.tree,Oa(c),Math.max(0,r));return l&&Va(l.distance,a(o,l.onPart),a(o,l.onMesh))}if(n.kind==="mesh"&&o.kind==="model"){let s=o.joints.filter(l=>l.on==="chassis"),i=s.some(l=>bR(n.tree,l.p,t.mountAllowance)),c=yR(n.tree,o.tree,o.iso,Math.max(0,r),s.map(l=>({c:l.p,r:2*l.reach})));return c&&Va(c.distance,c.onA,c.onB,i)}return null}var tL=152,rL={travelSteps:9,rackSteps:5};function IK(e){let t=(r,n)=>{let o=vr(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 FR(e,t){let r=Im(t);return{...pP,tyreRadius:IK(e),tyreWidth:r!==null?r*1e3:tL}}var JP={front:["FL","FR"],rear:["RL","RR"]},_K=e=>e.a.kind!=="volume"&&e.a.kind!=="mesh"&&(e.b.kind==="tyre"||e.b.kind==="rim"||e.b.kind==="hull");function NK(e,t,r,n,o){let a=null,s=(i,c)=>{for(let l of qP(XP(i,r,n,o),[])){if(l.skip||!_K(l)||!!l.fixed!==c)continue;let u=ZP(l,o,a?.distance??1/0);u&&(!a||u.distance<a.distance)&&(a={distance:u.distance,pair:l.name})}};s(e,!0);for(let i of t)s(i,!1);return a}var eL=(e,t,r)=>r<=1||t===e?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function TR(e,t,r,n,o=rL,a={}){let s=e.vehicle,[i]=JP[t],c=kd(e,i,0,0)?.geometry;if(!c)return null;let l=uf(s.chassis?.boxes??[],{vehicle:s,kc:e.kc}),u=t==="front"?It(s.front.config):0,d=u>0?eL(-u,u,Math.max(3,o.rackSteps|1)):[0],p=eL(Math.min(0,r.min),Math.max(0,r.max),Math.max(2,o.travelSteps)),m=[];for(let v of l.length?JP[t]:[i])for(let k of p)for(let R of d){let M=kd(e,v,k,R)?.geometry;M&&m.push({corner:v,travel:k,rack:R,g:M})}let f=null;if(l.length){for(let v of yP(l,m,FR(e,n)))for(let k of[v.tyre,v.link])k&&(!f||k.distance<f.distance)&&(f={distance:k.distance,part:k.part,boxId:v.boxId});f??={distance:NaN,part:"",boxId:""}}let h=s[t].config,b=m.filter(v=>v.corner===i).map(v=>v.g),g=lf(c,b,h.pushrodAttach,h.rodType==="pull"?"pullrod":"pushrod"),y=sP({...FR(e,n),jointAllowance:UP},s,{...a,tyres:{front:n,rear:n}}),x=y.axles[t].rim?NK(c,b,i,h.pushrodAttach,y):null;return{chassis:f,wheel:x,...g}}var $a=Math.PI/180,Ai={travelSteps:9,heaveSteps:5,rollSteps:4,rackSteps:6},fu={travelMin:-25,travelMax:25,rollMaxDeg:3,rollAtLimitDeg:2.5};function OK(e){let t=e.params,r=t.cg_height?jt({...t,surveyedRadiusFront:e.vehicle.front.config.loadedRadius,surveyedRadiusRear:e.vehicle.rear.config.loadedRadius}):null;return{cgHeight:r?r.cgHeight:300,...Ug(t),drive:qm(t),...r?{frontMassFrac:r.frontMassFrac}:{}}}function PR(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 LR(e,t=Ai,r=fu,n){let o=null,a=(D,I)=>(o||(o={violation:D,reason:I}),null),s=e.vehicle,i=D=>D==="front"?s.front:s.rear,c=null,l=null,u=()=>{if(c)return c;if(n)try{let D=n();if(D)return c=pr(s,D.kc),l=D.cgHeight,c}catch{a(500,"the car could not be stood on its tyre: its rates did not assemble")}return c=pr(s)},d=D=>D==="front"?"FL":"RL",p=D=>{let I=u();if(!I.kc)return;let V=i(D).config.loadedRadius,O=vr(V,I.kc,d(D));return O===V?void 0:{loadedRadius:O}},m=(D,I)=>-ic(u(),d(D),I),f=new Map,h=new Map,b=new Map,g=new Map,y=new Map,x=new Map,v,k=new Map,R=new Map,M=new Map,S=new Map,w=new Map,F=null,T=()=>{if(F)return F;u();let D=OK(e);return F=l!==null&&Number.isFinite(l)?{...D,cgHeight:l}:D},A,C=()=>{let D=eR(r.travelMin,r.travelMax,s.config.wheelbase),I=2*Math.max(2,t.rollSteps)-1;return Array.from({length:I},(V,O)=>-D+2*D*O/(I-1))},P,L=()=>{if(P!==void 0)return P;let D=pm(u().ctx.FL,It(s.front.config));return P=D?fm(D):null,P},E=(D,I,V)=>{if(D.has(I))return D.get(I)??null;let O=V();return D.set(I,O),O};return{car:e,density:t,envelope:r,get failure(){return o},axisLength:(D,I)=>{let V=i(D),O=V.hardpoints;return I==="uca"&&V.config.layout==="mcpherson"?NaN:I==="uca"?Pe(O.ucaFront,O.ucaRear):Pe(O.lcaFront,O.lcaRear)},linkLength:D=>{let I=i(D).hardpoints;return Pe(I.tieInner,I.tieOuter)},compliance:D=>E(h,D,()=>qb(i(D))??null),sweep:D=>E(f,D,()=>{let I;try{I=ct(i(D),{travelMin:r.travelMin,travelMax:r.travelMax,steps:t.travelSteps})}catch{return a(500,`the ${D} travel sweep threw`)}if(!I.covered){let O=I.samples.map(j=>j.travel),B=Math.max(...O)-Math.min(...O),z=r.travelMax-r.travelMin;return a(Math.max(0,z-B),`the ${D} linkage reaches only ${B.toFixed(0)} mm of the ${z.toFixed(0)} mm travel range`)}if(I.fold)return a(200,`the ${D} travel(beta) folds \u2014 the suspension goes over centre in range`);let V=I.samples.filter(O=>!O.converged).length;if(V>0)return a(100+10*V,`${V} of ${I.samples.length} ${D} travel solves did not converge`);if(D==="front"&&i("front").config.steerMode==="rack"){let O=L();if(O)return a(O.violation,O.reason)}return I}),rcHeave:D=>E(b,D,()=>{let I=[],V=[],O=Math.max(2,t.heaveSteps);try{for(let z=0;z<O;z++){let j=r.travelMin+(r.travelMax-r.travelMin)*z/(O-1);I.push(j),V.push($r(u(),{heave:m(D,j),pitch:0,roll:0,steer:0},D))}}catch{return a(500,`the ${D} roll-centre construction threw in heave`)}let B=PR(V,z=>Math.abs(I[z]-I[z-1]));return B>0?a(300,`the ${D} roll-centre construction lands on another branch at ${I[B].toFixed(0)} mm of travel`):{at:I,rc:V}}),rcRoll:D=>E(g,D,()=>{let I=[],V=[],O=Math.max(2,t.rollSteps);try{for(let z=0;z<O;z++){let j=r.rollMaxDeg*z/(O-1);I.push(j),V.push($r(u(),{heave:0,pitch:0,roll:j*$a,steer:0},D))}}catch{return a(500,`the ${D} roll-centre construction threw in roll`)}let B=PR(V,z=>Math.abs(V[z].cpLeft?.[0]??0)*Math.abs(I[z]-I[z-1])*$a);return B>0?a(300,`the ${D} roll-centre construction lands on another branch at ${I[B].toFixed(1)}\xB0 of roll`):{at:I,rc:V}}),rcPitch:D=>E(y,D,()=>{let I=C(),V=[];try{for(let B of I)V.push($r(u(),{heave:0,pitch:-B*$a,roll:0,steer:0},D))}catch{return a(500,`the ${D} roll-centre construction threw in pitch`)}let O=PR(V,B=>Math.abs(I[B]-I[B-1])*$a*s.config.wheelbase);return O>0?a(300,`the ${D} roll-centre construction lands on another branch at ${I[O].toFixed(2)}\xB0 of pitch`):{at:I,rc:V}}),pcHeave:()=>E(x,"heave",()=>{let D=[],I=[],V=Math.max(2,t.heaveSteps);try{for(let O=0;O<V;O++){let B=r.travelMin+(r.travelMax-r.travelMin)*O/(V-1);D.push(B);let z={heave:m("front",B),pitch:0,roll:0,steer:0},j={heave:m("rear",B),pitch:0,roll:0,steer:0},$=u();I.push({left:to(Tt($,"FL",z),Tt($,"RL",j)),right:to(Tt($,"FR",z),Tt($,"RR",j))})}}catch{return a(500,"the pitch-centre construction threw in heave")}return{at:D,pc:I}}),pcPitch:()=>E(x,"pitch",()=>{let D=C(),I=[];try{for(let V of D){let O={heave:0,pitch:-V*$a,roll:0,steer:0},B=u();I.push({left:to(Tt(B,"FL",O),Tt(B,"RL",O)),right:to(Tt(B,"FR",O),Tt(B,"RR",O))})}}catch{return a(500,"the pitch-centre construction threw in pitch")}return{at:D,pc:I}}),cg:()=>{if(v!==void 0)return v;let D=T();if(D.frontMassFrac===void 0||!Number.isFinite(D.frontMassFrac))return v=null;let I=s.config,V=of({wheelbase:I.wheelbase,frontAxleX:I.frontAxleX,frontMassFrac:D.frontMassFrac,cgHeight:D.cgHeight});return v={...V,z:Kr(D.cgHeight,V.x,u())}},roadUnder:D=>{let I=k.get(D);return I===void 0&&(I=Kr(0,ze(d(D),s.config).axleX,u()),k.set(D,I)),I},steer:()=>{if(A!==void 0)return A;try{A=Lb(u(),{steerMax:It(s.front.config),steps:t.rackSteps})}catch{A=a(500,"the steering sweep threw")}let D=A?.filter(I=>!I.converged).length??0;if(A&&D>0){let I=L();A=I?a(I.violation,I.reason):a(100+10*D,`${D} of ${A.length} steering solves did not converge`)}return A??null},solveAt:(D,I,V=0)=>E(R,`${D}:${I}:${V}`,()=>{try{let O=Ae(u().ctx[d(D)],I,V,void 0,p(D));return O.ok?O.state:O.why==="unconverged"?a(100,`the ${D} corner did not solve at ${I.toFixed(0)} mm of travel`):a(100+Math.abs(O.travelMiss),`the ${D} corner reaches only ${(I+O.travelMiss).toFixed(0)} of ${I.toFixed(0)} mm of travel`)}catch{return a(150,`the ${D} corner solve threw at ${I.toFixed(0)} mm of travel`)}}),readout:D=>E(S,`${D.heave}:${D.pitch}:${D.roll}:${D.steer}`,()=>{try{return tR(u(),D,T())}catch{return a(500,"the derived readout threw")}}),readoutAtTravel:(D,I)=>E(w,`${D}:${I}`,()=>{try{return au(u(),{heave:m(D,I),pitch:0,roll:0,steer:0},D,T())}catch{return a(500,`the ${D} readout threw at ${I.toFixed(0)} mm of travel`)}}),travelAtRoll:(D,I)=>{let V=i(D).hardpoints.wheelCenter[1]*Math.sin(I*$a),O=u();if(!O.kc)return V;try{let B=Qt(O,{heave:0,pitch:0,roll:I*$a,steer:0}),z=D==="front"?Math.max(B.FL.travel,B.FR.travel):Math.max(B.RL.travel,B.RR.travel);return Number.isFinite(z)?z:V}catch{return a(500,`the ${D} axle could not be rolled on its tyre`),V}},onTyre:()=>!!u().kc,contexts:u,keepOuts:D=>E(M,D,()=>{try{let I=e.params,V=D==="front"?I.tireModel:I.tireModelRear??I.tireModel,O={min:r.travelMin,max:r.travelMax},B={brakes:I.brakeModel,dampers:{front:I.damperModel,rear:I.damperModelRear??I.damperModel},drive:aP(qm(I))};return TR(u(),D,O,V,void 0,B)??a(100,`the ${D} corner did not solve at its design ride`)}catch{return a(500,`the ${D} keep-outs threw`)}})}}var VK=Yy();function DR(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=Rp(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,d=a.track?Gl([c],a.track,a.numerics,Nl(s),a.settings,VK)[0]:Cl(c,s,{numerics:a.numerics,standingStart:l,lapCounts:u});o={};for(let p of s.metrics)Iu(p)&&(o[p.key]=p.value(d,void 0))}}catch{o=null}return r.set(n,o),o}}}var Af=.01;function BK(e,t){return t.bump!==null&&e>t.bump-Af?{at:"closed",past:Math.max(0,e-t.bump)}:t.droopStated&&e<t.droop+Af?{at:"toppedOut",past:Math.max(0,t.droop-e)}:t.seat!==null&&e<t.seat+Af?{at:"unseated",past:Math.max(0,t.seat-e)}:{at:"free",past:0}}var nL=e=>({droop:e.droop,droopStated:e.droopStated,bump:e.bump,seat:e.holdsLoad&&Number.isFinite(e.free)?e.free:null}),$K=[["front","FL","FR"],["rear","RL","RR"]];function IR(e,t){let r=[];for(let[n,o,a]of $K){let s=[t[o],t[a]];for(let d of[o,a]){let p=e.curve[d],m=p.spring?.law;if(!p.spring||!m)continue;let f=mb(p,t[d]);f===null||!Number.isFinite(f)||r.push(ER(d,n,n,f,p.spring.length0-f,nL(m),!0))}let i=e.elements?.[n];if(!i)continue;let c=i.heave?.law;if(c){let d=Ik(i,s),p=i.read.heave?.span0,m=n==="front"?"heaveFront":"heaveRear";r.push(ER(m,m,n,d,p!==void 0?p-d:null,nL(c),i.carriesLoad))}let l=i.rollStop,u=l?_k(i,s):null;if(l&&u!==null){let d=l.length0-u,p=n==="front"?"rollFront":"rollRear",m={droop:l.droop??-1/0,droopStated:l.droop!==null,bump:l.bump,seat:null};r.push(ER(p,p,n,d,u,m,i.carriesLoad))}}return r}function ER(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,...BK(n,a),bumpStated:a.bump!==null,bounds:s}}var sL=Math.PI/180;function _R(e,t,r,n){let o=t.speedKmh/3.6,a=jh(e,o,t.axG,po(e,t.ayG,0));if(!a||!e.aero)return null;let s=e.wheelbase,i=ms(e.aero,s),c=(h,b)=>Math.atan((b-h)/s)/sL,l={},u={};for(let h of Zr)l[h]=r.corners[h].travel,u[h]=r.corners[h].ground;let d=n.kc?IR(n.kc,l):[],p=e.aero.model,m=a.downFront+a.downRear,f=p?{balance:Math.abs(m)>1e-9?100*a.downFront/m:NaN,clA:(a.clFront+a.clRear)*a.area,cdA:a.cd*a.area,loopMargin:1-a.gain,dataMargin:iL(p,s,a.hFront,a.hRear)}:null;return{front:{height:a.hFront,...oL(d,"front")},rear:{height:a.hRear,...oL(d,"rear")},rakeDeg:c(a.hFront,a.hRear),pitchDeg:c(a.hFront,a.hRear)-c(i.hFront,i.hRear),rollDeg:Math.abs(r.rollDeg),aero:f,clearance:GK(n,u)}}function oL(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 iL(e,t,r,n){let o=(a,[s,i])=>Math.min(a-s,i-a);if(Fv(e)){let{x:a,y:s}=is(e),i=[a[0],a[a.length-1]],c=[s[0],s[s.length-1]];return uo(e)?aL(e.frame,t,i,c,r,n):Math.min(o(r,i),o(n,c))}return $u(e)?aL(e.frame,t,e.range.h,e.range.pitch,r,n):Math.min(o(r,e.range.hFront),o(n,e.range.hRear))}function aL(e,t,r,n,o,a){let s=cs(e,t,o,a),i=l=>t*Math.tan(l*sL),c=a-o;return Math.min(s.h-r[0],r[1]-s.h,c-i(n[0]),i(n[1])-c)}function GK(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=ir(e.vehicle,!0)/2,c=ir(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]],d=[0,0,0];for(let b of Zr){let g=[1,l[b][0],l[b][1]];for(let y=0;y<3;y++){d[y]+=g[y]*t[b];for(let x=0;x<3;x++)u[y][x]+=g[y]*g[x]}}let p=gP(u,d);if(!p)return null;let m=fP(n),f={z0:m.z0+p[0],dzdx:m.dzdx+p[1],dzdy:m.dzdy+p[2]},h=null;for(let b of uf(r,n)){let g=bP(b,f);(!h||g.height<h.height)&&(h={height:g.height,volume:b.name})}return h}function wf(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 KK={front:"front",rear:"rear",heaveFront:"front",heaveRear:"rear",rollFront:"front",rollRear:"rear"};function hu(e,t,r,n){let o=Dd(e,t);return Rd.some(s=>{if(KK[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 NR(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 Cf=Math.PI/180,Ff=1e-6;function lL(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 bu(e){let t=e.measured;if(t)return lL(t.travel,t.camber);let r=re(e.config.spinAxis);return-Math.asin(Math.max(-1,Math.min(1,r[2])))/Cf}function gu(e){let t=e.measured;if(t)return lL(t.travel,t.toe);let[r,n]=e.config.spinAxis;return Math.atan2(r,n)/Cf}function OR(e,t){let r=Math.abs(t.camber)>=Ff,n=Math.abs(t.toe)>=Ff;if(!r&&!n)return e;let o=e.measured;if(o)return{...e,measured:{...o,...r?{camber:o.camber.map(m=>m+t.camber)}:{},...n?{toe:o.toe.map(m=>m+t.toe)}:{}}};let[a,s]=e.config.spinAxis,i=Math.hypot(a,s);if(!(i>0))return e;let c=(bu(e)+t.camber)*Cf,l=(gu(e)+t.toe)*Cf,[u,d]=n?[Math.sin(l),Math.cos(l)]:[a/i,s/i],p=[u*Math.cos(c),d*Math.cos(c),-Math.sin(c)];return{...e,config:{...e.config,spinAxis:p}}}function Tf(e){let t=e&&typeof e=="object"?e.value:void 0;return typeof t=="number"&&Number.isFinite(t)?t:void 0}function HK(e,t){let r=t;return{front:Tf(r.camber_front_deg)??bu(e.front),rear:Tf(r.camber_rear_deg)??bu(e.rear)}}function zK(e,t){let r=t;return{front:Tf(r.toe_front_deg)??gu(e.front),rear:Tf(r.toe_rear_deg)??gu(e.rear)}}function YK(e){return{camber:{front:bu(e.front),rear:bu(e.rear)},toe:{front:gu(e.front),rear:gu(e.rear)}}}var cL=new WeakMap;function WK(e,t){let r=YK(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)<Ff&&Math.abs(u.toe)<Ff;if(o(n.front)&&o(n.rear))return e;let a=`${t.camber.front}|${t.camber.rear}|${t.toe.front}|${t.toe.rear}`,s=cL.get(e),i=s?.get(a);if(i)return i;let c=e.corners?Object.fromEntries(Object.entries(e.corners).map(([u,d])=>[u,d&&OR(d,n[fs(u)])])):void 0,l={...e,front:OR(e.front,n.front),rear:OR(e.rear,n.rear),...c?{corners:c}:{}};return s||cL.set(e,s=new Map),s.size>=16&&s.clear(),s.set(a,l),l}function wi(e,t){return t?WK(e,{camber:HK(e,t),toe:zK(e,t)}):e}var jK=9.81;function Ci(e){let t=jo(e),r=Math.max(0,e.unsprungPerCorner)*jK,n=a=>{let s=a==="FL"||a==="FR",i=s?"front":"rear",c=yt(e,i),l=c>0?c:1/0,u=Ch(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:Mr(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 d=!i&&!!l&&(l.gap>0||!l.bothWays);(s?.heave||s?.roll||i||d)&&(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 uL=new WeakMap;function UK(e){let t=wi(e.vehicle,e.params);if(t===e.vehicle)return e;let r=uL.get(e);return(!r||r.vehicle!==t)&&uL.set(e,r={...e,vehicle:t}),r}function Do(e,t={}){let r=UK(e),n=$x(r,t),o=t.assemble?()=>{let d=n.dynInput();if(!d)throw new Error("the car did not assemble");return{kc:Ci(d),cgHeight:d.cgHeight}}:void 0,a=LR(r,t.density,t.envelope,o),s=Wx(r,n,t),i=DR(r,t),c=t.states??[],l=new Map;return{...a,...n,...s,...i,get failure(){return a.failure},values:new Map,states:c,stateOf:d=>d===void 0?c[0]??null:c.find(p=>p.id===d)??null,platformAt:d=>{let p=`${d.speedKmh}|${d.ayG}|${d.axG}`,m=l.get(p);if(m!==void 0)return m;let f=n.poseAt(d),h=n.dynInput(),b=null;if(f&&h)try{b=_R(h,d,f,a.contexts())}catch{b=null}return l.set(p,b),b}}}var XK=["x","y","z"],qK=/^(line|plane)\((-?\d+),(-?\d+)\)([uv]?)$/,mL=Math.PI/18e3,dL=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],pL=(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]],QK=e=>Math.hypot(e[0],e[1],e[2]),VR=(e,t)=>[e[0]*t,e[1]*t,e[2]*t];function BR(e){let t=QK(e);return t>1e-9?VR(e,1/t):null}function ZK(e,t){let r=e*mL,n=t*mL;return[Math.cos(n)*Math.cos(r),Math.cos(n)*Math.sin(r),Math.sin(n)]}function Cr(e){let t=e.lastIndexOf(".");if(t<0)return null;let r=qK.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:ZK(Number(r[2]),Number(r[3]))},coord:n==="line"?"along":r[4]}}function fL(e){let t=BR(pL([0,0,1],e))??[1,0,0];(t[0]<-1e-9||Math.abs(t[0])<=1e-9&&t[1]<0)&&(t=VR(t,-1));let r=BR(pL(e,t))??[0,1,0];return(r[2]<-1e-9||Math.abs(r[2])<=1e-9&&r[1]<0)&&(r=VR(r,-1)),[t,r]}function $R(e){if(e.coord==="along")return e.shape.dir;let[t,r]=fL(e.shape.dir);return e.coord==="u"?t:r}function hL(e,t){let r=Cr(t);if(!r)return;let n=XK.map(u=>e[`${r.point}.${u}`]);if(n.some(u=>!u))return;let o=$R(r),a=[0,1,2].filter(u=>Math.abs(o[u])>1e-12),s=u=>n.map(d=>d.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=>dL(s(u),o),write:(u,d)=>{let p=s(u),m=d-dL(p,o),f=u;for(let h of a)f=n[h].write(f,p[h]+m*o[h]);return f},...c?{supersededBy:c}:{}}}var Fi=["x","y","z"];var JK=/^(?:hp\.(?:front|rear)\.\w+|(?:heave|roll)\.(?:front|rear)\.(?:outer|inner|anchor))$/;function Ga(e){let t=e.lastIndexOf("."),r=e.slice(0,t);if(t<0||!JK.test(r))return null;let n=e.slice(t+1);if(n==="x"||n==="y"||n==="z")return{point:r,axis:n};let o=Cr(e);return o?{point:r,axis:o.coord}:null}var yu="*";function GR(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 KR=e=>e?.reads==="speed"||e?.reads==="operating",HR=e=>e?.reads==="lateral"||e?.reads==="operating";function Ka(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 Pf(e,t){return e?.appliesAt?t.find(r=>!e.appliesAt(r)):t[0]}function Ti(e,t,r){let n=r?.stateId?e.stateOf(r.stateId):Pf(t,e.states)??null;return n&&!t.appliesAt?.(n)?n:null}function Rt(e,t,r){let n=`${t.id}@${Ka(r)}`,o=e.values.get(n);if(o!==void 0)return o;let a;try{a=r?.courseId===yu&&t.reads==="course"?eH(e,t,r):r?.stateId===gn&&t.reads==="state"?tH(e,t,r):t.read(e,r)}catch{a=NaN}return e.values.set(n,a),a}function eH(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:Rt(e,t,i),length:e.course(i)?.track.length??NaN}});if(o.some(s=>!Number.isFinite(s.v)))return NaN;if(t.across==="sum")return o.reduce((s,i)=>s+i.v,0);if(t.across==="min")return Math.min(...o.map(s=>s.v));if(t.across==="max")return Math.max(...o.map(s=>s.v));let a=o.reduce((s,i)=>s+i.length,0);return a>0?t.across==="harmonic"?a/o.reduce((s,i)=>s+i.length/i.v,0):o.reduce((s,i)=>s+i.v*i.length,0)/a:NaN}function tH(e,t,r){let n=t.appliesAt?e.states.filter(i=>!t.appliesAt(i)):e.states;if(!t.acrossStates||!n.length)return NaN;let o=n.map(i=>({v:Rt(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 zR(e){let t={mean:"weighted mean",max:"highest",min:"lowest",span:"span"};return e?.acrossStates?`every state, ${t[e.acrossStates]}`:"every state"}function ht(e){return`${e.quantity??e.groupShort??e.group} \xB7 ${e.label}`}var rH={front:"Front",rear:"Rear"},Ha={heave:0,pitch:0,roll:0,steer:0},bL="RC height (chassis) [mm]";function gL(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 AL(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 Rn=e=>e.length?Math.max(...e)-Math.min(...e):NaN;function yL(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 xL(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 Li(e,t,r){let n=e.stateOf(t?.stateId),o=n?e.poseAt(n):null;return o?r(o):NaN}var xu=(e,t)=>`${e==="front"?"F":"R"}${t}`,RL=e=>e==="L"?"R":"L";function vL(e){let t=rH[e],r=R=>`kin.${e}.${R}`,n=(R,M)=>{let S=R.sweep(e);return S?{x:S.samples.map(w=>w.travel),y:S.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 d(R){let M=s(R);return M&&M.design.kind!=="none"?null:`${i} has no roll element`}function p(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 m=R=>{if(u(R.car))return null;let M=R.sweep(e);return M?bb(o(R.car),a(R.car).linkage,M.samples):null},f=R=>{if(p(R.car))return null;let M=R.sweep(e);if(!M)return null;let S=s(R.car),w=pb(o(R.car),S.linkage,S.design.kind,M.samples),F=w.atDesign<0?-1:1;return{travel:w.travel,ratio:w.ratio.map(T=>T*F),atDesign:w.atDesign*F}},h=R=>R.readout(Ha)?.[e],b=R=>R.readoutAtTravel(e,R.envelope.travelMax),g=R=>{let M=n(R,S=>S.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,S=>S.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?AL(M.at,M.rc.map(S=>S.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:bL,x:M.at,y:M.rc.map(S=>S.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?Rn(M.rc.map(S=>S.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:bL,x:M.at,y:M.rc.map(S=>S.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?Rn(M.rc.map(S=>S.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(S=>S.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),S=R.rcRoll(e);return!M||!S?NaN:Math.min(...M.rc.map(w=>w.sinAngle),...S.rc.map(w=>w.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(S=>S.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=>h(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=>h(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=>h(R)?.rollCamber??NaN},{id:r("rollCamberRecovery"),group:`${t} camber & toe`,label:"camber recovery in roll",unit:"%",scale:20,scope:e,cost:"readout",read:R=>h(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=>h(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=>h(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,S=>S.metrics.toe);return M.x.length?gL(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,S=>S.metrics.camber);return M.x.length?gL(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=>Rn(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=>Rn(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)),S=R.solveAt(e,0);return!M||!S?NaN:Math.abs(M.metrics.camber-S.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)=>Li(R,M,S=>S.camber[xu(e,S.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)=>Li(R,M,S=>S.camber[xu(e,RL(S.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)=>Li(R,M,S=>S.corners[xu(e,S.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=>h(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=>h(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=>h(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=>h(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?xL(M.samples.map(S=>S.travel),M.samples.map(S=>S.metrics.motionRatio??NaN))??NaN:NaN},curve:R=>{if(c(R.car))return null;let M=n(R,S=>S.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 S=M.samples.map(F=>F.metrics.motionRatio??NaN).filter(Number.isFinite);if(!S.length)return NaN;let w=S.reduce((F,T)=>F+T,0)/S.length;return w>0?(Math.max(...S)-Math.min(...S))/w:NaN}},{id:r("wheelRate"),group:`${t} rates`,label:"wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:c,read:R=>{if(c(R.car))return NaN;let M=R.sweep(e);return M?xL(M.samples.map(S=>S.travel),M.samples.map(S=>S.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=>m(R)?.atDesign??NaN,curve:R=>{let M=m(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=>yL(m(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:Qs(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:p,read:R=>f(R)?.atDesign??NaN,curve:R=>{let M=f(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:p,read:R=>yL(f(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:d,read:R=>d(R.car)||!R.sweep(e)?NaN:Pd(R.car.vehicle,R.car.params)[e].element??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(Ha)?.[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)=>Li(R,M,S=>S.corners[xu(e,S.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)=>Li(R,M,S=>S.corners[xu(e,RL(S.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:Rn(n(R,M=>M.metrics.damperLength).y),curve:R=>{if(c(R.car))return null;let M=n(R,S=>S.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=>h(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=>h(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(Ha)?.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(Ha)?.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(Ha)?.rear.antiLift??NaN});let v=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 ${v(R.group)}`}))}function kL(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 nH=[{id:"kin.front.ackermannCentre",group:"Steering",label:"Ackermann near centre",unit:"%",scale:25,scope:"front",cost:"cheap",read:e=>kL(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=>kL(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}}],oH=[{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)=>Li(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}}],Pi=(e,t)=>e.left.valid&&e.right.valid?(t(e.left)+t(e.right))/2:NaN,YR=(e,t)=>{let r=e.readout(Ha)?.axes?.pitch;return r?.valid?t(r):NaN},ML=(e,t)=>{let r=e.readout(Ha)?.axes?.roll;return r?.usable?t(r):NaN},aH=e=>(e.roadUnder("front")+e.roadUnder("rear"))/2;function SL(e){let t=e.rcRoll("front"),r=e.rcRoll("rear"),n=e.cg();if(!t||!r||!n)return null;let o=e.car.vehicle.config,a=t.rc.map((s,i)=>jT({front:s,rear:r.rc[i]},n,o.frontAxleX,o.wheelbase,()=>!0).arm);return{at:t.at,arm:a}}var sH="PC height (chassis) [mm]",iH=[{id:"kin.car.pcHeight",group:"Pitch axis",label:"pitch-centre height at design",unit:"mm",scale:30,scope:"car",cost:"readout",read:e=>YR(e,t=>t.heightAboveGround)},{id:"kin.car.pcAhead",group:"Pitch axis",label:"pitch centre ahead of the CG at design",unit:"mm",scale:300,scope:"car",cost:"readout",read:e=>YR(e,t=>t.ahead)},{id:"kin.car.pitchArm",group:"Pitch axis",label:"pitch arm at design",unit:"mm",scale:30,scope:"car",cost:"readout",read:e=>YR(e,t=>t.arm)},{id:"kin.car.pcHeaveWorst",group:"Pitch axis",label:"worst height migration vs travel",unit:"mm/mm",scale:.5,scope:"car",cost:"cheap",read:e=>{let t=e.pcHeave();return t?AL(t.at,t.pc.map(r=>Pi(r,n=>n.height))):NaN},curve:e=>{let t=e.pcHeave();if(!t)return null;let r=aH(e);return{key:"kin.car.pcHeaveWorst",title:"Pitch-centre height vs wheel travel",xLabel:"travel [mm]",yLabel:sH,x:t.at,y:t.pc.map(n=>Pi(n,o=>o.height)-r)}}},{id:"kin.car.pcPitchSpan",group:"Pitch axis",label:"height span over the pitch envelope",unit:"mm",scale:15,scope:"car",cost:"cheap",read:e=>{let t=e.pcPitch();return t?Rn(t.pc.map(r=>Pi(r,n=>n.heightAboveGround))):NaN},curve:e=>{let t=e.pcPitch();return t?{key:"kin.car.pcPitchSpan",title:"Pitch-centre height vs body pitch",xLabel:"pitch [\xB0, + nose down]",yLabel:"PC height above road [mm]",x:t.at,y:t.pc.map(r=>Pi(r,n=>n.heightAboveGround))}:null}},{id:"kin.car.pcAheadSpan",group:"Pitch axis",label:"fore-aft migration over the pitch envelope",unit:"mm",scale:300,scope:"car",cost:"cheap",read:e=>{let t=e.pcPitch();return t?Rn(t.pc.map(r=>Pi(r,n=>n.x))):NaN},curve:e=>{let t=e.pcPitch(),r=e.cg();return!t||!r?null:{key:"kin.car.pcAheadSpan",title:"Pitch centre ahead of the CG vs body pitch",xLabel:"pitch [\xB0, + nose down]",yLabel:"PC ahead of CG [mm]",x:t.at,y:t.pc.map(n=>Pi(n,o=>o.x)-r.x)}}},{id:"kin.car.pcMinSinAngle",group:"Pitch axis",label:"construction conditioning (min sinAngle)",unit:"-",scale:.01,scope:"car",cost:"cheap",read:e=>{let t=e.pcHeave(),r=e.pcPitch();return!t||!r?NaN:Math.min(...[...t.pc,...r.pc].map(n=>Math.min(n.left.sinAngle,n.right.sinAngle)))}},{id:"kin.car.rollArm",group:"Roll axis",label:"roll arm at design",unit:"mm",scale:30,scope:"car",cost:"readout",read:e=>ML(e,t=>t.arm)},{id:"kin.car.rollAxisSlope",group:"Roll axis",label:"slope at design (+ rising rearward)",unit:"\xB0",scale:.5,scope:"car",cost:"readout",read:e=>ML(e,t=>t.slope)},{id:"kin.car.rollArmSpan",group:"Roll axis",label:"roll-arm span over the roll envelope",unit:"mm",scale:15,scope:"car",cost:"cheap",read:e=>{let t=SL(e);return t?Rn(t.arm):NaN},curve:e=>{let t=SL(e);return t?{key:"kin.car.rollArmSpan",title:"Roll arm vs body roll",xLabel:"roll [\xB0]",yLabel:"roll arm [mm]",x:t.at,y:t.arm}:null}}],WR=[...vL("front"),...vL("rear"),...nH,...oH,...iH];var cH={front:"Front",rear:"Rear"};function FL(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 lH(e,t,r){let n=r==="front"?t.tireModel:t.tireModelRear??t.tireModel;return nR(e.parts?.[r],n)?null:`The ${r} axle states no rim, so its tyre and rim are not measured; state one under Kinematics \u203A Linkage \u203A Wheel`}function wL(e,t,r){let n=e.parts?.[t]?.jointLimits?.[r];return oR(n)?n:void 0}function CL(e){let t=cH[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=>FL(s.vehicle),read:s=>o(s,i=>i.chassis?.distance)},{...a,id:r("wheelClearance"),label:`least clearance inside the wheel ${n}`,unit:"mm",scale:5,unavailable:s=>lH(s.vehicle,s.params,e),read:s=>o(s,i=>i.wheel?.distance)},{...a,id:r("ballJointAngle"),label:`largest ball-joint angle ${n}`,unit:"\xB0",scale:1,read:s=>o(s,i=>i.ballJoint?.angle),statedLimit:s=>wL(s.vehicle,e,"ballJoint")},{...a,id:r("rodEndAngle"),label:`largest rod-end angle ${n}`,unit:"\xB0",scale:1,read:s=>o(s,i=>i.rodEnd?.angle),statedLimit:s=>wL(s.vehicle,e,"rodEnd")}]}var jR=[...CL("front"),...CL("rear")];var EL={front:"Front",rear:"Rear"},TL=e=>Ia("side",e),uH=e=>Ia("drive",e)&&Ia("brake",e)?"neither brakes nor drives":null;function mH(e,t,r,n){let o=Ti(e,t,r),a=o?e.tyreAt(o):null;return a?n(a):NaN}function Di(e,t){let r={...e,read:(n,o)=>mH(n,r,o,t)};return r}var PL=e=>e?100*e.lossCamber:NaN,LL=e=>e&&!e.lifted?e.camber-e.wants:NaN;function DL(e){let t=EL[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:TL,unavailable:s=>Up(s.params,e)},a=[Di({...o,id:r("camberErrorOuter"),label:"camber error at the outer wheel",unit:"\xB0",scale:.5},s=>LL(s.side(e)?.wheels[0])),Di({...o,id:r("camberErrorInner"),label:"camber error at the inner wheel",unit:"\xB0",scale:.5},s=>LL(s.side(e)?.wheels[1])),Di({...o,id:r("sideLossCamber"),label:"side grip lost to camber",unit:"%",scale:1},s=>PL(s.side(e))),Di({...n,appliesAt:TL,id:r("sideLossToe"),label:"side grip lost to the toe split",unit:"%",scale:1},s=>100*s.toeLoss(e)),Di({...n,appliesAt:uH,unavailable:s=>Vx(s.params,e),id:r("longLossCamber"),label:"drive and brake grip lost to camber",unit:"%",scale:1},s=>PL(s.long(e)))];return e==="front"&&a.push(Di({...n,appliesAt:s=>Ia("ackermann",s),id:r("ackermannError"),label:"Ackermann against the tyre",unit:"%",scale:25},s=>s.ackermann())),a}var UR=[...DL("front"),...DL("rear")],dH=/^tyre\.(front|rear)\.(camberErrorOuter|camberErrorInner|sideLossCamber|longLossCamber)$/;function XR(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=dH.exec(a.id);if(!i)continue;let c=i[1],l=i[2]==="longLossCamber",u=s?.stateId==="*"?e.states.filter(d=>!a.appliesAt?.(d)):[Ti(e,a,s)].filter(d=>!!d);for(let d of u){let p=`${c}|${d.id}|${l}`;if(r.has(p))continue;let m=e.tyreAt(d),f=m?l?m.long(c):m.side(c):null;if(!f)continue;let{lo:h,hi:b,stated:g}=f.range,y=g?`the ${o(h)} \u2026 ${o(b)} its data covers`:`the \xB1${b.toFixed(0)}\xB0 read without a stated range`,x=M=>l?M===0?"left":"right":M===0?"outer":"inner",v=f.wheels.findIndex(M=>M.atEdge),k=f.wheels.findIndex(M=>M.outside&&!M.lifted),R=[];v>=0&&R.push(`the ${EL[c].toLowerCase()} ${x(v)} tyre wants ${o(f.wheels[v].wants)}, the edge of ${y}, and may want more`),k>=0&&R.push(`the ${x(k)} wheel has ${o(f.wheels[k].camber)}, past it, and is read at ${o(f.wheels[k].read)}`),R.length&&r.set(p,`In the ${n(d)} ${R.join("; ")}.`)}}return[...r.values()]}function qR(e,t){let r=e.appliesAt?.(t);return r?`is read at ${t.name}, which ${r}`:null}var pH={front:"Front",rear:"Rear"};function fH(e,t,r,n){let o=Ti(e,t,r),a=o?e.platformAt(o):null;return(a?n(a):null)??NaN}function Fr(e,t){let r={...e,read:(n,o)=>fH(n,r,o,t)};return r}var QR={cost:"cheap",reads:"state"},hH={unavailable:e=>wf(e.params)};function IL(e){let t=pH[e],r=o=>`platform.${e}.${o}`,n={...QR,group:`${t} platform`,quantity:`${t} \xB7 Platform`,scope:e};return[Fr({...n,id:r("rideHeight"),label:"ride height at a state",unit:"mm",scale:5,acrossStates:"min"},o=>o[e].height),Fr({...n,id:r("toBumpStop"),label:"travel left to the bump stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>hu(o.vehicle,o.params,e,"bump")},o=>o[e].toBump),Fr({...n,id:r("toDroopStop"),label:"travel left to the droop stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>hu(o.vehicle,o.params,e,"droop")},o=>o[e].toDroop)]}var Lf={...QR,group:"Platform",scope:"car"},Ru={...QR,...hH,group:"Aero platform",groupShort:"Aero",scope:"car"},ZR=[...IL("front"),...IL("rear"),Fr({...Lf,id:"platform.rake",label:"rake at a state",unit:"\xB0",scale:.2,acrossStates:"span"},e=>e.rakeDeg),Fr({...Lf,id:"platform.pitch",label:"pitch at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.pitchDeg),Fr({...Lf,id:"platform.roll",label:"body roll at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.rollDeg),Fr({...Lf,id:"platform.groundClearance",label:"ground clearance at a state",unit:"mm",scale:5,acrossStates:"min",unavailable:e=>NR(e.vehicle)},e=>e.clearance?.height),Fr({...Ru,id:"platform.balance",label:"balance at a state",unit:"%",scale:1,acrossStates:"span"},e=>e.aero?.balance),Fr({...Ru,id:"platform.clA",label:"downforce Cl\xB7A at a state",unit:"m\xB2",scale:.1,acrossStates:"mean"},e=>e.aero?.clA),Fr({...Ru,id:"platform.cdA",label:"drag Cd\xB7A at a state",unit:"m\xB2",scale:.05,acrossStates:"mean"},e=>e.aero?.cdA),Fr({...Ru,id:"platform.dataMargin",label:"margin to the model\u2019s data",unit:"mm",scale:5,acrossStates:"min"},e=>e.aero?.dataMargin),Fr({...Ru,id:"platform.loopMargin",label:"aero-elastic margin, 1 \u2212 loop gain",unit:"-",scale:.1,acrossStates:"min"},e=>e.aero?.loopMargin)];var _L={understeer:"operating",yawFreq:"speed",yawZeta:"speed",yawStiffness:"operating",steeringTorque:"operating",steeringTorqueGradient:"operating"};function Lt(e,t,r,n="cheap"){let o=cy[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,..._L[e]?{reads:_L[e]}:{},read:(a,s)=>{let i=a.dynInput(),c=a.dynCtx(s);return i&&c?o.compute(i,c):NaN}}}function NL(e,t){let r=e.dynInput();if(!r)return null;let n=t("front"),o=t("rear");if(!n||!o||n.rc.length!==o.rc.length)return null;let a=e.roadUnder("front"),s=e.roadUnder("rear"),i=n.rc.map((c,l)=>{let u=Us(c),d=Us(o.rc[l]);if(!u||!d)return NaN;let p=nM(r,u.height-a,d.height-s);return 100*oM(r,{rcFront:u.heightAboveGround,rcRear:d.heightAboveGround,arm:p})});return{at:n.at,share:i}}function JR(e,t,r,n,o){let a=`dyn.${e}`;return{id:a,group:"Handling \u2014 balance",label:t,unit:"%",scale:1,scope:"car",cost:"cheap",read:s=>{let i=NL(s,o(s));return i?Rn(i.share):NaN},curve:s=>{let i=NL(s,o(s));return i?{key:a,title:r,xLabel:n,yLabel:"TLLTD front [%]",x:i.at,y:i.share}:null}}}var bH=[Lt("understeer","Handling \u2014 balance",.1),Lt("tlltdFront","Handling \u2014 balance",5),JR("tlltdHeaveSpan","TLLTD span over the travel","TLLTD vs wheel travel","travel [mm]",e=>t=>e.rcHeave(t)),JR("tlltdPitchSpan","TLLTD span over the pitch envelope","TLLTD vs body pitch","pitch [\xB0, + nose down]",e=>t=>e.rcPitch(t)),JR("tlltdRollSpan","TLLTD span over the roll envelope","TLLTD vs body roll","roll [\xB0]",e=>t=>e.rcRoll(t)),Lt("rollStiffFront","Handling \u2014 balance",5)],gH=[Lt("yawFreq","Handling \u2014 response",.5),Lt("yawZeta","Handling \u2014 response",.2),Lt("stabilitySpeed","Handling \u2014 response",50),Lt("yawStiffness","Handling \u2014 response",2e4,"trim")],yH=[Lt("steeringTorque","Steering feel",1,"trim"),Lt("steeringTorqueGradient","Steering feel",2,"trim")],xH=[Lt("rollGradient","Ride & body",.5),Lt("pitchGradient","Ride & body",.5),Lt("rideFreqFront","Ride & body",.5),Lt("rideFreqRear","Ride & body",.5),Lt("rollFreq","Ride & body",.5),Lt("pitchFreq","Ride & body",.5),Lt("zetaFront","Ride & body",.2),Lt("zetaRear","Ride & body",.2)],RH=[{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}],vH=[{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}],e1=[...bH,...gH,...yH,...xH,...RH,...vH];function kH(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 t1=[{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)=>kH(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 MH(e,t){let r=/^(.*?)\s*\(([^)]+)\)\s*$/.exec(e);return r?{label:r[1],unit:r[2]}:{label:e,unit:t?"s":""}}function SH(e){return e==="s"||e==="kWh"?.1:e==="km/h"?2:1}var OL=new WeakMap;function Df(e){let t=OL.get(e);return t||(t=e.metrics.filter(Iu).map(r=>{let{label:n,unit:o}=MH(r.label,r.format==="time");return{id:`event.${e.id}.${r.key}`,group:`Events \xB7 ${e.label}`,groupShort:"Events",label:n,unit:o,scale:SH(o),scope:"car",cost:"session",read:a=>a.session(e.id)?.[r.key]??NaN}}),OL.set(e,t),t)}var r1=ui.flatMap(Df);var Ef=[...WR,...jR,...UR,...ZR,...e1,...t1,...r1],Ei=Object.fromEntries(Ef.map(e=>[e.id,e]));var VL={all:Ef,byId:Ei},BL=new WeakMap;function gr(e=[]){if(e.length===0)return VL;let t=BL.get(e);if(t)return t;let r=_y(e).filter(n=>!mi(n.id)).flatMap(Df);return t=r.length?{all:[...Ef,...r],byId:{...Ei,...Object.fromEntries(r.map(n=>[n.id,n]))}}:VL,BL.set(e,t),t}var wH=9.81;function If(e,t=e.tireModel,r=e.tireModelRear){if(!t)return e;e=CH(e,t,r);let n=e.m.value*wH/4,o=ha(e,t,r),a=Ke(o.front).rollingRadius(n),s=o.rear===o.front?a:Ke(o.rear).rollingRadius(n),i=FH(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 CH(e,t,r){let n=ha(e,t,r),o=Ke(n.front).verticalStiffness(),a=n.rear===n.front?o:Ke(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 ${$L(o)}, rear ${$L(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 $L=e=>Math.round(e*10)/10;function FH(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 vu=180/Math.PI,Ii=Math.PI/180,TH=.2;function _f(e,t){let r=H(t,e);return re(r[0]<0?Xh(r):r)}var Nf=e=>({side:Math.atan2(e[2],e[0])*vu,plan:Math.atan2(e[1],e[0])*vu}),Of=(e,t)=>re([1,Math.tan(t*Ii),Math.tan(e*Ii)]),ku=e=>Math.abs(e[0])>=TH,Vf=(e,t)=>Math.atan(t/Math.max(e,1))*vu,Bf=(e,t)=>Math.tan(t*Ii)*Math.max(e,1);var Eo=["side","plan","clock","len"],yr={uca:{fore:"ucaFront",aft:"ucaRear",ball:"uprightUpper"},lca:{fore:"lcaFront",aft:"lcaRear",ball:"uprightLower"}},Mu={uca:"upper arm",lca:"lower arm"},PH=1,GL=(e,t)=>_f(e[yr[t].fore],e[yr[t].aft]);function KL(e){let t=re(H(Uh,X(e,J(Uh,e))));return{e1:t,e2:le(e,t)}}function n1(e,t){let r=GL(e,t);if(!ku(r))return`the ${Mu[t]}'s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it`;let n=yr[t],o=Fn(e[n.ball],e[n.fore],r);return Math.hypot(...H(o,e[n.ball]))>=PH?null:`the ${Mu[t]}'s ball joint sits on its own pivot axis, so the arm has no length to swing on`}function oo(e,t){let r=yr[t],n=e[r.ball],o=GL(e,t),a=Fn(n,e[r.fore],o),s=H(a,n),i=Math.hypot(s[0],s[1],s[2]),{e1:c,e2:l}=KL(o),u=i>0?X(s,1/i):c;return{...Nf(o),clock:Math.atan2(J(u,l),J(u,c))*vu,len:i,sFront:J(H(e[r.fore],a),o),sRear:J(H(e[r.aft],a),o)}}function o1(e,t){let r=Of(e.side,e.plan),{e1:n,e2:o}=KL(r),a=oe(X(n,Math.cos(e.clock*Ii)),X(o,Math.sin(e.clock*Ii))),s=oe(t,X(a,e.len));return{fore:oe(s,X(r,e.sFront)),aft:oe(s,X(r,e.sRear))}}function HL(e,t,r,n){let o=yr[t],a={...oo(e,t),[r]:n},{fore:s,aft:i}=o1(a,e[o.ball]);return{...e,[o.fore]:s,[o.aft]:i}}function zL(e,t){return t==="clock"?e.len:Math.abs(e.sFront-e.sRear)/2}function $f(e,t,r){return t==="len"?r:Vf(zL(e,t),r)}function a1(e,t,r){return t==="len"?r:Bf(zL(e,t),r)}var za=["side","plan","atY","atZ"],vn={fore:"rockerPivotA",aft:"rockerPivotB"},LH=5,YL=e=>_f(e.rockerPivotA,e.rockerPivotB);function _i(e){return Math.hypot(...H(e.rockerPivotB,e.rockerPivotA))<LH?"the rocker\u2019s two pivots are the same point, so there is no axis to describe":ku(YL(e))?null:"the rocker\u2019s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it"}function Io(e){let t=YL(e),r=ku(t)?t:[1,0,0],n=e.rockerPivotA,o=oe(n,X(r,-n[0]/r[0]));return{...Nf(r),atY:o[1],atZ:o[2],sA:J(H(n,o),r),sB:J(H(e.rockerPivotB,o),r)}}function s1(e){let t=Of(e.side,e.plan),r=[0,e.atY,e.atZ];return{a:oe(r,X(t,e.sA)),b:oe(r,X(t,e.sB))}}function WL(e,t,r){if(_i(e))return e;let{a:n,b:o}=s1({...Io(e),[t]:r});return{...e,rockerPivotA:n,rockerPivotB:o}}var jL=e=>Math.abs(e.sA-e.sB)/2;function i1(e,t,r){return t==="side"||t==="plan"?Vf(jL(e),r):r}function c1(e,t,r){return t==="side"||t==="plan"?Bf(jL(e),r):r}var Wr={front:"Front",rear:"Rear"},Yr=["x","y","z"],st=(e,t)=>t==="front"?e.front:e.rear,Su=(e,t,r)=>t==="front"?{...e,front:r}:{...e,rear:r},UL=[{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"}]}],XL={damperChassis:"strut top mount",pushrodOuter:"strut lower mount"},Ya=30;function DH(e){let t=[];for(let r of["front","rear"]){let n=st(e.vehicle,r).config.layout==="mcpherson";for(let o of UL)for(let{key:a,label:s}of o.keys){let i=n&&XL[a]||s;for(let c=0;c<3;c++)t.push({id:`hp.${r}.${a}.${Yr[c]}`,group:`${Wr[r]} hardpoints \u2014 ${o.kind}`,label:`${i} ${Yr[c]}`,scope:Wr[r],unit:"mm",defaultSpan:Ya,read:l=>st(l.vehicle,r).hardpoints[a][c],write:(l,u)=>{let d=st(l.vehicle,r),p=[...d.hardpoints[a]];p[c]=u;let m={...d.hardpoints,[a]:p};return{...l,vehicle:Su(l.vehicle,r,{...d,hardpoints:m})}}})}}return t}var EH={side:"axis side-view angle",plan:"axis plan-view angle",clock:"arm clock angle",len:"effective arm length"},IH={side:"\xB0",plan:"\xB0",clock:"\xB0",len:"mm"};function _H(e){let t=[];for(let r of["front","rear"]){let n=st(e.vehicle,r).config.layout==="mcpherson";for(let o of["uca","lca"]){let a=st(e.vehicle,r).hardpoints,s=n1(a,o)?null:oo(a,o);for(let i of Eo)t.push({id:`arm.${r}.${o}.${i}`,group:`${Wr[r]} ${n?"arm axes":"wishbone axes"}`,label:`${Mu[o]} \u2014 ${EH[i]}`,scope:Wr[r],unit:IH[i],defaultSpan:s?$f(s,i,Ya):Ya,read:c=>oo(st(c.vehicle,r).hardpoints,o)[i],write:(c,l)=>{let u=st(c.vehicle,r),d=HL(u.hardpoints,o,i,l);return{...c,vehicle:Su(c.vehicle,r,{...u,hardpoints:d})}}})}}return t}var NH={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"},OH={side:"\xB0",plan:"\xB0",atY:"mm",atZ:"mm"};function VH(e){let t=[];for(let r of["front","rear"]){let n=st(e.vehicle,r).hardpoints,o=_i(n)?null:Io(n);for(let a of za)t.push({id:`rocker.${r}.${a}`,group:`${Wr[r]} rocker axis`,label:`rocker \u2014 ${NH[a]}`,scope:Wr[r],unit:OH[a],defaultSpan:o?i1(o,a,Ya):Ya,read:s=>Io(st(s.vehicle,r).hardpoints)[a],write:(s,i)=>{let c=st(s.vehicle,r),l=WL(c.hardpoints,a,i);return{...s,vehicle:Su(s.vehicle,r,{...c,hardpoints:l})}}})}return t}var Gf={front:"heaveFrontDesign",rear:"heaveRearDesign"},l1={front:"arbFrontDesign",rear:"arbRearDesign"};function BH(e,t){return{heave:e.config.actuation==="decoupled"?"heave element":"third spring",roll:t?.design.kind==="coil"?"roll shock":"anti-roll bar"}}var Kf=e=>/^(heave|roll)\.(front|rear)\.(outer|inner|anchor)\.[xyz]$/.test(e);function $H(e){let t=[];for(let r of["front","rear"]){let n=st(e.vehicle,r),o=e.params[Gf[r]],a=e.params[l1[r]],s=BH(n,a),i=f=>f.params[Gf[r]],c=f=>f.params[l1[r]],l=(f,h)=>({...f,params:{...f.params,[Gf[r]]:h}}),u=(f,h)=>({...f,params:{...f.params,[l1[r]]:h}}),d={group:`${Wr[r]} heave & roll elements`,scope:Wr[r]},p=(f,h,b,g,y)=>{for(let x of b)t.push({...d,id:`${f}.${Yr[x]}`,label:`${h} ${Yr[x]}`,unit:"mm",defaultSpan:Ya,read:v=>g(v)[x],write:(v,k)=>{let R=[...g(v)];return R[x]=k,y(v,R)}})},m=(f,h,b,g,y)=>{t.push({...d,id:f,label:h,unit:"N/mm",defaultSpan:Math.max(5,b*.4),read:g,write:y})};if(o?.design.kind==="coil"){if(o.linkage){let f=b=>i(b).linkage;p(`heave.${r}.outer`,`${s.heave} eye`,[0,1,2],b=>f(b).outer,(b,g)=>l(b,{...i(b),linkage:{...f(b),outer:g}})),o.linkage.mount?.kind==="chassis"&&p(`heave.${r}.anchor`,`${s.heave} chassis anchor`,[0,2],b=>f(b).mount.anchor,(b,g)=>l(b,{...i(b),linkage:{...f(b),mount:{kind:"chassis",anchor:g}}}))}if(typeof o.design.rate=="number"){let f=h=>i(h).design;m(`heave.${r}.rate`,`${s.heave} spring rate (@element)`,o.design.rate,h=>f(h).rate,(h,b)=>l(h,{...i(h),design:{...f(h),rate:b}}))}}if(a&&a.design.kind!=="none"){if(a.linkage&&a.design.kind!=="direct"){let h=x=>c(x).linkage,b=en(n,a.linkage,a.design.kind),[g,y]=b?["left arm eye","right arm eye"]:["drop-link pickup","arm tip"];p(`roll.${r}.outer`,`${s.roll} ${g}`,[0,1,2],x=>h(x).outer,(x,v)=>u(x,{...c(x),linkage:{...h(x),outer:v}})),p(`roll.${r}.inner`,`${s.roll} ${y}`,[0,1,2],x=>h(x).inner,(x,v)=>u(x,{...c(x),linkage:{...h(x),inner:v}}))}let f=a.design;if(f.kind==="coil"&&typeof f.rate=="number"){let h=b=>c(b).design;m(`roll.${r}.rate`,`${s.roll} spring rate (@element)`,f.rate,b=>h(b).rate,(b,g)=>u(b,{...c(b),design:{kind:"coil",rate:g}}))}else f.kind==="direct"&&m(`roll.${r}.wheelRate`,`${s.roll} rate (@wheel)`,f.wheelRate,h=>c(h).design.wheelRate,(h,b)=>u(h,{...c(h),design:{kind:"direct",wheelRate:b}}))}}return t}var GH=[{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 KH(e){let t=[];for(let r of["front","rear"]){let n=st(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:Wr[r],unit:"N/mm",defaultSpan:Math.max(500,l*.4),read:u=>i(st(u.vehicle,r).compliance??{})??l,write:(u,d)=>{let p=st(u.vehicle,r),m={...p,compliance:c(p.compliance??{},Math.max(1,d))};return{...u,vehicle:Su(u.vehicle,r,m)}}})};for(let a of["ucaFront","ucaRear","lcaFront","lcaRear","tieRod","pushRod"])o(`link.${a}`,`${HH[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}`,`${zH[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 HH={ucaFront:"UCA front leg",ucaRear:"UCA rear leg",lcaFront:"LCA front leg",lcaRear:"LCA rear leg",tieRod:"tie rod",pushRod:"push/pull rod"},zH={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 YH(){return GH.map(e=>({id:`cfg.${e.axle}.${e.field}`,group:e.group,label:e.label,scope:Wr[e.axle],unit:e.unit,defaultSpan:e.span(e.fallback),read:t=>st(t.vehicle,e.axle).config[e.field]??e.fallback,write:(t,r)=>{let n=st(t.vehicle,e.axle),o={...n,config:{...n.config,[e.field]:r}};return{...t,vehicle:Su(t.vehicle,e.axle,o)}}}))}function WH(e){let t=Qo(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=>Qo(c.params.steeringSystem)[n],write:(c,l)=>({...c,params:{...c.params,steeringSystem:Qo({...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 jH(e){let t=fa(e.params),r=[];for(let n of["front","rear"]){if(t[n]!=="diff")continue;let o=pa(e.params.driveline?.[n]);if(o?.kind!=="clutch"&&o?.kind!=="torsen")continue;let a=(s,i)=>{let c=Nd[`${n}.${s}`];return{id:`driveline.${n}.${s}`,group:"Differential",label:c.label.charAt(0).toLowerCase()+c.label.slice(1),scope:Wr[n],unit:c.unit===": 1"?"":c.unit??"",defaultSpan:i,read:l=>pa(l.params.driveline?.[n])?.[s],write:(l,u)=>({...l,params:{...l.params,driveline:_d({...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 UH(e){if(Bc(e.params)!=="hydraulic")return[];let t=[{id:"brakeSetup.barFront",group:"Brakes",label:`${e0("barFront").toLowerCase()}, front share`,unit:"-",defaultSpan:.05,read:a=>On(a.params.brakeSetup).barFront,write:(a,s)=>({...a,params:{...a.params,brakeSetup:On({...On(a.params.brakeSetup),barFront:s})}})}];if(!e.params.brakeModel)return t;let r=an(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:Jg(a.circuit?`${a.circuit}.${String(a.key)}`:a.key),unit:s,defaultSpan:i,read:c=>n(an(c.params.brakeModel),a),write:(c,l)=>{let u=an(c.params.brakeModel),d=a.circuit?{...u,[a.circuit]:{...u[a.circuit],[a.key]:l}}:{...u,[a.key]:l};return{...c,params:{...c.params,brakeModel:an(d)}}}});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 qL=e=>!!e&&typeof e=="object"&&"value"in e&&"label"in e;function QL(e){let t={...e};for(let r of Object.keys(t)){let n=t[r];qL(n)&&(t[r]={...n})}return t}function XH(e){let t=[];for(let r of Cw(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 qL(s)?s.value:NaN},write:(a,s)=>{let i=QL(a.params);return Js(i,n.label,s),{...a,params:i}}})}return t}function ZL(e){let t={};for(let i of["front","rear"]){if(!st(e.vehicle,i).measured)continue;let l="this axle is described by measured curves, so its linkage is not solved";for(let u of UL)for(let{key:d}of u.keys)for(let p of Yr)t[`hp.${i}.${d}.${p}`]={why:l};for(let u of["uca","lca"])for(let d of Eo)t[`arm.${i}.${u}.${d}`]={why:l};for(let u of za)t[`rocker.${i}.${u}`]={why:l};for(let u of["heave.outer","heave.anchor","roll.outer","roll.inner"]){let[d,p]=u.split(".");for(let m of Yr)t[`${d}.${i}.${p}.${m}`]={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(st(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 Yr)t[`hp.${i}.${l}.${u}`]={why:c};for(let l of za)t[`rocker.${i}.${l}`]={why:c}}for(let i of["front","rear"]){let c=st(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 d of Yr)t[`hp.${i}.${u}.${d}`]={why:l,useInstead:`heave.${i}.outer.${d}`};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=st(e.vehicle,i),l=e.params[Gf[i]]?.linkage;if(c.measured||!l||l.attach!=="rocker"||l.mount?.kind==="chassis")continue;let u=c.hardpoints,d=[0,1,2].map(m=>u.rockerPivotB[m]-u.rockerPivotA[m]),p=Math.hypot(d[0],d[1],d[2]);if(p>0)for(let m=0;m<3;m++)Math.abs(d[m]/p)<1-1e-12||(t[`heave.${i}.outer.${Yr[m]}`]={why:`the rocker shaft runs along ${Yr[m]} \u2014 this only slides the eye along it`})}for(let i of["front","rear"]){let c=st(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 d of Yr)t[`hp.${i}.${u}.${d}`]={why:l,useInstead:`hp.${i}.damperChassis.${d}`};for(let u of Eo)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=st(e.vehicle,i);if(c.measured)continue;for(let u of["uca","lca"]){if(u==="uca"&&c.config.layout==="mcpherson")continue;let d=n1(c.hardpoints,u);if(d)for(let p of Eo)t[`arm.${i}.${u}.${p}`]={why:d,useInstead:`hp.${i}.${yr[u].fore}.z`}}let l=_i(c.hardpoints);if(l&&c.config.actuation!=="direct")for(let u of za)t[`rocker.${i}.${u}`]={why:l,useInstead:`hp.${i}.${vn.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,d]of n){let p=e.params[i];if(!p?.design||p.design.kind==="none")continue;let m=p.design.kind==="direct"?`${d}.${u}.wheelRate`:`${d}.${u}.rate`;t[c]={why:`computed from ${l}`,useInstead:m}}let o=e.params.aeroModelId||e.params.aeroModel?G0:K0;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(Vd))t[`param.${i}`]={why:c};for(let[i,c]of Object.entries(Bd(e.params)))t[`param.${i}`]={why:c};let a={...If(e.params).readouts,...e.sessionAir?{rho:Ep}:{}};for(let[i,c]of Object.entries(a)){let l=`param.${i}`;!(l in t)&&!(l in eD)&&(t[l]={why:c})}for(let[i,c]of Object.entries(H0(e.params)))t[`param.${i}`]={why:c};let s=Bc(e.params)==="hydraulic";for(let[i,c]of Object.entries(Qm(e.params)))t[`param.${i}`]=s?{why:c,useInstead:"brakeSetup.barFront"}:{why:c};return t}function JL(e){let t={...eD,...ZL(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[...DH(e),..._H(e),...VH(e),...$H(e),...YH(),...WH(e),...UH(e),...jH(e),...KH(e),...XH(e.params)].map(r)}var qH={spring_front:"cfg.front.springRate",spring_rear:"cfg.rear.springRate"},eD=Object.fromEntries(Object.entries($0).map(([e,t])=>[`param.${e}`,{why:t,useInstead:qH[e]}])),ut=e=>e.scope?`${e.scope} \xB7 ${e.label}`:e.label;function bt(e){let t={};for(let n of JL(e))t[n.id]=n;let r=(n,o)=>{if(typeof o!="string")return;let a=hL(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 u1=e=>e.step!==void 0&&Number.isFinite(e.step)&&e.step>0?e.step:0,m1=e=>u1(e)>0||(e.values?.length??0)>0,d1=e=>e.some(m1),tD=e=>1e-9*Math.max(1,Math.abs(e.lo),Math.abs(e.hi));function rD(e,t){if(!Number.isFinite(t))return t;if(e.values?.length){let s=e.values[0];for(let i of e.values)Math.abs(i-t)<Math.abs(s-t)&&(s=i);return s}let r=u1(e);if(!r||!Number.isFinite(e.start))return t;let n=tD(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 nD=(e,t)=>t.map((r,n)=>e[n]&&m1(e[n])?rD(e[n],r):r);function p1(e,t=1e3){if(e.values?.length)return e.values.length;let r=u1(e);if(!r||!Number.isFinite(e.start))return 1/0;let n=tD(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 f1(e,t,r){let n=nD(e.variables,t),o=n.every((a,s)=>a===t[s]);return{x:n,score:o?r:In(e,n)}}function g1(e,t){if(!e.variables.some(oD))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(aD(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 oD=e=>!!(e.fixed||e.around||e.follows)||aD(e),aD=e=>!!e.values?.length&&(e.lo!==Math.min(...e.values)||e.hi!==Math.max(...e.values));function Bt(e,t){if(!t.variables.some(oD))return t;let r=bt(e);return g1(t,n=>{let o=r[n];if(!o)return NaN;try{return o.read(e)}catch{return NaN}})}var zf=()=>({variables:[],constraints:[],objectives:[],watches:[],density:{...Ai},envelope:{...fu},operating:{...gi},lap:tf()});function jr(e){return[...e.objectives,...e.constraints,...e.watches??[]]}var Yf=e=>(e.metrics??gr()).byId;function y1(e,t){t=Bt(e,t);let r=bt(e),n=[];for(let o of t.variables){let a=r[o.id];a&&n.push({id:a.id,name:ut(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 Ni(e,t,r){t=Bt(e,t);let n=bt(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]))}),v1(e,o,t.followers,n)}function x1(e,t,r={}){let n=t.states??[],o=n.some(c=>c.follows);if(!o&&!t.envelopeFollows)return t;let a=Do(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=Lx(n,c,JH(r)))}catch{s=n}let i=t.envelope;if(t.envelopeFollows&&s.length){let c=s.map(h=>a.poseAt(h)).filter(h=>h!==null),l=Yf(r),u=R1(t,l),d=jr(t).map(h=>({r:h,m:l[h.metricId]})).filter(({m:h})=>h&&h.id.startsWith("kin.")&&h.reads!=="state"&&(h.scope==="car"||u.includes(h.scope))),p=h=>{let b=Do(e,{density:t.density,envelope:h,assemble:r.assemble,numerics:r.numerics});return d.every(({r:g,m:y})=>Number.isFinite(Rt(b,y,g.at)))},m=c.length===s.length?ZH(e,Ex(c,u),u):null,f=m&&d.length?QH(m,p):m;f&&!Ix(f,t.envelope)&&(i=f)}return s===n&&i===t.envelope?t:{...t,states:s,envelope:i}}var Hf=3;function QH(e,t){let r=(c,l)=>t({...e,travelMin:c,travelMax:l}),n=e.travelMin-Hf,o=e.travelMax+Hf;if(r(n,o))return e;let a=(c,l,u)=>{for(;Math.abs(l-c)>1;){let d=Math.round((c+l)/2);u(d)?c=d:l=d}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+Hf)),i=Math.max(1,Math.min(e.travelMax,o-Hf));return s===e.travelMin&&i===e.travelMax?e:{...e,travelMin:s,travelMax:i}}function R1(e,t){let r=new Set;for(let n of jr(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 ZH(e,t,r){if(!t)return null;let n=wi(e.vehicle,e.params),{travelMin:o,travelMax:a}=t;for(let s of r.map(i=>n[i]))try{let i=ct(s,{travelMin:o,travelMax:a,steps:Ai.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 JH(e){let t=e.projectTrack?.();if(!t)return null;try{return Px(Ot(t.asset,t.numerics))}catch{return null}}function v1(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 _o(e,t){if(!Number.isFinite(t))return NaN;if(e.op==="max")return t-e.limit;if(e.op==="min")return e.limit-t;let r=e.limit2??e.limit;return Math.max(e.limit-t,t-r)}var sD=(e,t="")=>t&&t!=="-"?`${e} ${t}`:`${e}`;function iD(e,t,r){let n=t??Ei[e.metricId],o=(n?ht(n):e.metricId)+Wa(e.at,n,r),a=s=>sD(s,n?.unit);return e.op==="max"?`${o} \u2264 ${a(e.limit)}`:e.op==="min"?`${o} \u2265 ${a(e.limit)}`:`${o} between ${e.limit} and ${a(e.limit2??e.limit)}`}function Wa(e,t,r){if(!e&&t?.reads!=="state")return"";e??={};let n=[];if(t?.reads==="state")if(e.stateId===gn)n.push(zR(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&&KR(t)&&n.push(`${(e.speed*3.6).toFixed(0)} km/h`),e.ayG!==void 0&&HR(t)&&n.push(`${e.ayG.toFixed(2)} g`),e.courseId===yu&&t?.reads==="course")n.push(GR(t));else if(e.courseId&&t?.reads==="course"){let o=r?.lap.courses.find(a=>a.id===e.courseId);o&&n.push(Yx(o))}return n.length?` @ ${n.join(", ")}`:""}function cD(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 lD=5e-4;function uD(e,t){return e.cost!=="lap"&&e.cost!=="session"?0:Number.isFinite(t)?lD*Math.abs(t):0}function Wf(e,t,r={}){return Do(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 ja(e,t,r={}){t=Bt(e,t);let n=y1(e,t),o=bt(e),a=Yf(r),s=t.constraints.map(d=>({spec:d,metric:a[d.metricId]})).filter(d=>!!d.metric),i=s.filter(d=>d.metric.cost==="geometry"),c=s.filter(d=>d.metric.cost!=="geometry"),l=t.objectives.map(d=>({spec:d,metric:a[d.metricId]})).filter(d=>!!d.metric),u=(d,p)=>{let m=0,f=[];for(let{spec:h,metric:b}of d){let g=Rt(p,b,h.at);if(!Number.isFinite(g))return{ok:!1,violation:p.failure?.violation??400,reason:p.failure?.reason??`${ht(b)} could not be computed`};let y=_o(h,g);y>0&&(m+=y/b.scale,f.push(`${iD(h,b,t)} (${sD(g.toFixed(3),b.unit)})`))}return f.length===0?Cc:{ok:!1,violation:m,reason:f.join("; ")}};return{name:"study",variables:n,build:d=>{let p=e;return t.variables.forEach((m,f)=>{let h=o[m.id];h&&(p=h.write(p,d[f]))}),p=v1(e,p,t.followers,o),{car:p,ev:Wf(p,t,r)}},feasible:({ev:d})=>{let p=u(i,d);if(!p.ok)return p;for(let{spec:m,metric:f}of c)Rt(d,f,m.at);for(let{spec:m,metric:f}of l)Rt(d,f,m.at);return d.failure?{ok:!1,violation:d.failure.violation,reason:d.failure.reason}:u(c,d)},terms:({ev:d})=>l.map(({spec:p,metric:m})=>{let f=Rt(d,m,p.at);return{name:ht(m)+Wa(p.at,m,t),raw:f,unit:m.unit,weight:p.weight,contribution:cD(p,m,f),resolution:Math.abs(p.weight)*uD(m,f)/m.scale}})}}function h1(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 mD(e,t){if(e.variables.some(o=>o.id===t))return!0;let r=Ga(t);if(!r||!Fi.includes(r.axis))return!1;if(e.variables.some(o=>Cr(o.id)?.point===r.point))return!0;let n=h1(t);return!!n&&e.variables.some(o=>/^(arm|rocker)\./.test(o.id)&&h1(o.id)===n)}function e4(e,t){let r=e.followers??[],n=new Map(r.map(i=>[i.id,i.follows])),o=i=>{let c=t[i],l=Ga(i);return c&&l&&Fi.includes(l.axis)?{name:ut({...c,label:c.label.replace(/ [xyz]$/,"")}),axis:l.axis}:{name:c?ut(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),d=o(i.follows),p=m=>m&&m!=="x, y, z"?` in ${m}`:"";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,m=>`${u.name}${p(m)} cannot be moved: ${c.supersededBy.why}.`),!l)s(`no-lead:${u.name}:${i.follows}`,u.axis,m=>`${u.name}${p(m)} 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,m=>`${u.name}${p(m)} cannot move with itself.`);else if(l.unit!==c.unit)s(`unit:${u.name}:${d.name}`,u.axis,m=>`${u.name}${p(m)} moves with ${d.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 m=o(n.get(i.follows));s(`chain:${u.name}:${d.name}`,u.axis,f=>`${u.name}${p(f)} moves with ${d.name}, which itself moves with ${m.name}. Link it to ${m.name}.`)}else mD(e,i.follows)||s(`still:${u.name}:${d.name}`,u.axis,m=>`${u.name}${p(m)} moves with ${d.name}, which the study does not move${p(m)}. Free that one, or give this its own bound.`)}return[...a.values()].map(i=>i.text(i.axes.join(", ")))}function k1(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=Bt(e,t);let a=bt(e),s=[],i=Yf(r),c=jr(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 d=jr(t).filter(y=>i[y.metricId]?.reads==="state");if(d.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(v=>v.id),gn]);for(let v of d){let k=i[v.metricId];if(v.at?.stateId&&!x.has(v.at.stateId))s.push(`${ht(k)} names a state this study no longer has. Point it at one of the states under Conditions.`);else if(v.at?.stateId===gn&&!k.acrossStates)s.push(`${ht(k)} is read at one state at a time, not over every state.`);else if(k.appliesAt){let R=v.at?.stateId&&v.at.stateId!==gn?y.find(S=>S.id===v.at.stateId):void 0,M=R?qR(k,R):null;M?s.push(`${ht(k)} ${M}. Point it at a state that does.`):!R&&!Pf(k,y)&&s.push(`${ht(k)} has no state to be read at: ${k.appliesAt(y[0])} in every state of this study.`)}}}r.assemble||s.push("This study reads targets at a state, and nothing here can assemble the car to find its pose.")}for(let y of t.states??[])(!(y.speedKmh>=0)||!Number.isFinite(y.ayG)||!Number.isFinite(y.axG))&&s.push(`The state \u201C${y.name}\u201D needs a speed of zero or more and finite accelerations.`),y.weight>0||s.push(`The state \u201C${y.name}\u201D needs a weight above zero.`);if(l&&!r.assemble&&s.push("This study reads whole-car metrics, and nothing here can assemble the car to read them from."),u&&!r.simParams&&s.push("This study reads lap metrics, and nothing here can prepare the car for a lap."),u&&!t.lap.courses.length&&s.push("This study reads lap metrics and has no course to drive. Add one under \u201CWhat the car drives\u201D."),u&&t.lap.courses.some(y=>y.course.kind==="project")&&!r.projectTrack?.()&&s.push("This study laps the project\u2019s track, and the project has none. Pick a manoeuvre, or load a track."),u)for(let y of t.lap.courses)y.course.kind==="track"&&!r.libraryTrack?.(y.course.trackId)&&s.push(`This study drives ${y.course.name}, which is not in the project\u2019s tracks, or has not loaded yet.`);let p=new Set([...t.lap.courses.map(y=>y.id),yu]);for(let y of jr(t))if(y.at?.courseId&&!p.has(y.at.courseId)){let x=i[y.metricId];s.push(`${x?ht(x):y.metricId} names a course this study no longer has. Point it at one of the courses below.`)}u&&t.lap.ggvMode==="fast"&&t.variables.some(x=>/arb_|spring|heave_|front_mass_diss|cg_height|chassis_torsion|^hp\.|^roll\./.test(x.id.replace("param.","")))&&s.push("The fast grip envelope is a point mass: no load transfer, no trim. It cannot see bars, springs, roll centres, the chassis\u2019s twist or where the mass sits, and this study moves at least one of those."),n?s.push(o?"Every variable is fixed or moves with another \u2014 there is nothing to search.":"Every variable is fixed \u2014 there is nothing to search."):t.variables.length===0&&s.push("No variables selected \u2014 there is nothing to search."),t.objectives.length===0&&s.push("No objective selected. Constraints alone say which designs are legal, not which is better.");for(let y of t.variables){let x=a[y.id];if(!x){s.push(`\u201C${y.id}\u201D is not a variable this car has.`);continue}if(y.values&&y.values.length<2?s.push(`${ut(x)}: list two values or more, or fix it where it is.`):y.hi>y.lo?y.step!==void 0&&p1({...y,start:x.read(e)})<2&&s.push(`${ut(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(`${ut(x)}: the upper bound must be above the lower one (${y.lo} to ${y.hi}).`),x.supersededBy){let k=x.supersededBy.useInstead?a[x.supersededBy.useInstead]:void 0,R=k?ut(k):void 0;s.push(`${ut(x)} cannot be searched: ${x.supersededBy.why}.`+(R?` Use ${R} instead.`:""))}let v=x.read(e);Number.isFinite(v)&&(v<y.lo||v>y.hi)&&s.push(`${ut(x)} starts at ${v.toFixed(1)} ${x.unit}, outside its own bounds.`)}let m=t.followers??[],f=new Map;for(let y of[...t.variables.map(x=>x.id),...m.map(x=>x.id)]){let x=h1(y);if(!x)continue;let v=f.get(x);v||f.set(x,v={arms:[],coords:[]}),(/^(arm|rocker)\./.test(y)?v.arms:v.coords).push(y)}for(let[y,x]of f){if(x.arms.length===0||x.coords.length===0)continue;let v=R=>a[R]?ut(a[R]):R,k=y.endsWith("rocker")?"rocker":`${y.endsWith("uca")?"upper":"lower"} arm`;s.push(`${y.startsWith("front")?"The front":"The rear"} ${k} is being moved two ways at once \u2014 as an axis (${x.arms.map(v).join(", ")}) and as pivot coordinates (${x.coords.map(v).join(", ")}). They describe the same ${k}, so whichever is applied second overwrites the other. Keep one.`)}let h=new Map,b=new Set(m.map(y=>y.id));for(let y of[...t.variables.map(x=>x.id),...b]){let x=Ga(y);if(!x)continue;let v=Cr(y),k=b.has(y)?"with":v?`${v.shape.kind}:${y.slice(y.lastIndexOf(".")+1).replace(/[uv]$/,"")}`:"axes",R=h.get(x.point);R||h.set(x.point,R=new Set),R.add(k)}for(let[y,x]of h){if(x.size<2||x.size===2&&x.has("axes")&&x.has("with"))continue;let v=[...x].map(w=>w.split(":")[0]),k=w=>v.filter(F=>F===w).length,R=[k("axes")?"in its axes":"",k("line")===1?"along a line":k("line")>1?"along two lines":"",k("plane")===1?"in a plane":k("plane")>1?"in two planes":"",k("with")?"with another point":""].filter(Boolean),M=a[`${y}.x`],S=M?ut({...M,label:M.label.replace(/ x$/,"")}):y;s.push(`${S} 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(...e4(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(`${ht(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 jr(t))if(y.at?.speed!==void 0&&!(y.at.speed>0)){let x=i[y.metricId];s.push(`${x?ht(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 jr(t)){let x=i[y.metricId],v=x?.unavailable?.(e);!x||!v||g.has(x.id)||(g.add(x.id),s.push(`${ht(x)} cannot be read on this car: ${v}.`))}for(let y of t.objectives)i[y.metricId]?y.weight>0?y.goal==="target"&&!Number.isFinite(y.target)?s.push(`${ht(i[y.metricId])}: \u201Chit a value\u201D needs a value.`):y.goal==="target"&&y.tolerance!==void 0&&!(y.tolerance>=0)&&s.push(`${ht(i[y.metricId])}: the tolerance must be zero or more.`):s.push(`${ht(i[y.metricId])}: weight must be positive.`):s.push(`\u201C${y.metricId}\u201D is not a metric.`);return s}var dD=.1,pD=2e3,b1=3;function M1(e,t,r={},n=pD){t=Bt(e,t);let o=ja(e,t,r),a=Yf(r),s=bt(e),i=o.variables.map(A=>A.start),c=A=>{let C=o.build(A);return o.feasible(C).ok&&o.terms(C),C},l=c(i),u=o.feasible(l),d=[...t.objectives,...t.constraints],p=(A,C=d)=>{let P={};for(let L of C){let E=a[L.metricId];E&&(P[`${L.metricId}@${Ka(L.at)}`]=Rt(A.ev,E,L.at))}return P},m=A=>d.map(C=>A[`${C.metricId}@${Ka(C.at)}`]).map(C=>Number.isFinite(C)?C.toFixed(9):"x").join("|"),f=p(l,jr(t)),h=m(f),b=[],g=[],y={},x=[],v=0;t.variables.forEach((A,C)=>{let P=s[A.id];if(!P)return;if(x.length>=b1&&v>n){g.push(P);return}let L=[...i];L[C]=i[C]+(A.hi-i[C])*.25||A.hi;let E=performance.now(),_=c(L),D=performance.now()-E;v+=D,x.push(D);let I=p(_);y[P.id]=I,m(I)===h&&b.push(P)});let k=t.variables[0],R=k?t.variables.indexOf(k):-1;for(let A=0;k&&x.length>0&&x.length<b1;A++){let C=[...i];C[R]=i[R]+(k.hi-i[R])*(.4+.15*A)||k.hi;let P=performance.now();c(C),x.push(performance.now()-P)}let M=[...x].sort((A,C)=>A-C),S=M.length?M[M.length>>1]:0,w=[],F=jr(t).map(A=>A.metricId);if(F.some(A=>A.startsWith("dyn.trim")||A==="dyn.ymdMaxAy")){let A=l.ev.ymdLimit();A?.onGridEdge&&w.push("The yaw-moment diagram peaks on the edge of its swept grid, so the trim readings are where the sweep stopped rather than where the car does. Widen the \u03B2/\u03B4 envelope before trusting them."),!A&&l.ev.dynAvailable&&w.push("The yaw-moment diagram found no trim point, so anything read off the limit is unavailable.")}if(F.some(A=>A==="dyn.steeringTorque"||A==="dyn.steeringTorqueGradient")){let A=l.ev.tyre()?.model,C=A?bo(A):null;C==="assumed"?w.push("This tyre carries no explicit Mz coefficient block. Its steering-aligning contribution uses Magic Formula defaults, so optimise the curve only as a qualitative placeholder until Mz is imported or fitted."):C==="none"&&w.push("This tyre model has no aligning-moment curve. Steering metrics contain contact-patch force and jacking, but not the pneumatic-trail signal that normally warns the driver at the tyre limit.")}let T=["lap.minStabil","lap.understeerFrac"];if(F.some(A=>T.includes(A))){let C=l.ev.lapReserve()?.beyondFrac;if(C!==void 0&&Number.isFinite(C)){let P=(C*100).toFixed(0);C>=dD?w.push(`Over ${P} % of this course, some wheel is asked for more longitudinal force than its own tyre ellipse allows \u2014 the speed profile and the per-wheel reconstruction disagree that far. A reserve read there is the two models disagreeing rather than the car having nothing left, and a search pointed at one will optimise the disagreement. It concentrates in high-speed braking, so a shorter straight into the first corner is the usual cure.`):C>0&&w.push(`${P} % of this course is beyond the per-wheel tyre ellipse, which is the usual level of disagreement between the speed profile and the reconstruction. Reserves are readable; treat small differences between designs as smaller than they look.`)}}return w.push(...XR(l.ev,jr(t).map(A=>({m:a[A.metricId],at:A.at})).filter(A=>!!A.m))),{msPerEval:S,values:f,samples:x.length,times:x,dead:b,moves:y,unprobed:g,warnings:w,beyondFrac:F.some(A=>T.includes(A))?l.ev.lapReserve()?.beyondFrac:void 0,startFeasible:u.ok,startReason:u.reason}}var r4=[{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:n4.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 n4=["setup:m","characteristics:peak_power","characteristics:power_to_weight","characteristics:cla","characteristics:cda","characteristics:pack_energy","characteristics:maxAy","characteristics:top_speed"];var yge=new Set(r4.map(e=>e.kind));var fD={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 S1=["FL","FR","RL","RR"],nr=(e,t,r)=>({input:e,from:r?r[0]:fD[e].from,to:r?r[1]:fD[e].to,n:t}),kge=[{id:"sides",name:"Inside and outside",cards:[{id:"camber-roll",form:"curves",title:"Camber to the road through roll",sweep:nr("roll",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"toe-rack",form:"curves",title:"Wheel angle against the rack",sweep:nr("steer",25),wheels:["FL","FR"],y:["toe"]},{id:"camber-rack",form:"curves",title:"Camber to the road through the steer",sweep:nr("steer",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"load-roll",form:"curves",title:"Wheel loads through roll",sweep:nr("roll",25),wheels:S1,y:["wheelLoad"]},{id:"travel-roll",form:"curves",title:"Wheel travel through roll",sweep:nr("roll",25),wheels:S1,y:["travel"]},{id:"toe-roll",form:"curves",title:"Roll steer, all four",sweep:nr("roll",25),wheels:S1,y:["toe"]}]},{id:"maps",name:"Travel and steer together",cards:[{id:"camber-map",form:"surface",title:"Camber over travel and rack",sweep:nr("travel",17),second:nr("steer",13),wheels:["FL"],y:["camber"]},{id:"bump-steer-map",form:"map",title:"Bump steer over travel and rack",sweep:nr("travel",17),second:nr("steer",13),wheels:["FL"],y:["bumpSteer"]},{id:"bump-steer-family",form:"curves",title:"Bump steer through travel, at five rack positions",sweep:nr("travel",25),second:nr("steer",5,[-20,20]),wheels:["FL"],y:["bumpSteer"]},{id:"scrub-map",form:"surface",title:"Scrub radius over travel and rack",sweep:nr("travel",17),second:nr("steer",13),wheels:["FL"],y:["scrubRadius"]}]}];function A1(e){let t=Number(e);return Number.isFinite(t)?Math.min(kg,Math.max(vg,t)):lr}var bD=6e4;var k0e=[{within:60*6e4,every:bD},{within:1440*6e4,every:60*6e4},{within:720*60*6e4,every:1440*6e4},{within:1/0,every:10080*6e4}];var gD=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);var C1=e=>e==null;function h4(e,t){return e===t||C1(e)&&C1(t)?!0:typeof e=="number"&&typeof t=="number"&&Number.isNaN(e)&&Number.isNaN(t)}function Au(e,t){if(h4(e,t))return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!Au(e[r],t[r]))return!1;return!0}if(gD(e)&&gD(t)){for(let r of Object.keys(e))if(!Au(e[r],t[r]))return!1;for(let r of Object.keys(t))if(!(r in e)&&!C1(t[r]))return!1;return!0}return!1}var b4=new Set(["color","visible","source","origin"]),L0e=["id",...b4];var RD=.18/1.18,vD={induction:{kind:"natural"}},kD=e=>e.breathing??vD;function jf(e){switch(e?.kind){case"sae-j1349":return Kl(99e3,25);case"measured":return Kl(e.hPa*100,e.tempC);default:return Kl(101325,20)}}var y4=jf(void 0);function MD(e,t){let r=jf(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 SD(e,t){let r=e.induction;if(r.kind==="table"){let o=s=>et(r.densityAltitudeM,r.powerPct,s),a=o(jf(e.rated).densityAltitudeM);return a>0?Math.max(0,o(t.densityAltitudeM)/a):0}let n=e.frictionShare??RD;return Math.max(0,(MD(e,t)-n)/(1-n))}var xD=new WeakMap;function F1(e,t){let r=e.asRated??e,n=`${t.p}|${t.pDry}|${t.T}`,o=xD.get(r);o||xD.set(r,o=new Map);let a=o.get(n);if(a)return a;let s=SD(kD(r),t),i={...r,torque:r.torque.map(c=>c*s),asRated:r};return o.set(n,i),i}function k4(e){return JSON.parse(T1(P1(e,"public/laptime/index.json"),"utf8")).tracks}var M4=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 AD(e,t=new Map,r=M4){let n=k4(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(!Xl(o.address))throw new Error(`"${o.address}" is not a catalogue address`);if(!Ul(o.link))throw new Error("This track is linked to a source this version does not read from.");i=await hx(await r(o.link),o.link,o.address)}else if(o.kind==="catalogue"){if(!Xl(o.address))throw new Error(`"${o.address}" is not a catalogue address`);let c=JSON.parse(T1(P1(e,"public/catalogue",gx(o.address)),"utf8"));i=await xx(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(T1(P1(e,"public/laptime",c),"utf8"))}return t.set(a,i),structuredClone(i)}}var S4=1e-6;function wD(e,t,r){let n=e.cgReference;if(!n||!e.cg_height)return e;let o=xw(e,t,r);if(o===void 0||Math.abs(o-n.standingRadius)<S4)return e;let a=n.typed??e.cg_height.value;return{...e,cg_height:{...e.cg_height,value:Zs(e.cg_height.value,n.standingRadius,o)},cgReference:{...n,standingRadius:o,typed:a}}}function CD(e,t,r){let n=e.rcRoad,o=e.rc_front,a=e.rc_rear;if(!n||!o||!a)return e;let s=Id(e,t,r),i=Un(o.value,n.gainFront,n.radiusFront,s.front),c=Un(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 FD=e=>({brakeFade:e.brakeFade,airTempC:e.airTempC,diffYaw:e.diffYaw,...Ca(e.air)?{air:e.air}:{}});var Ua=(e,t)=>t?e.find(r=>r.id===t)?.model:void 0;function Xa(e){return{tire:t=>Ua(e.tires,t),motor:t=>Ua(e.motors,t),aero:t=>Ua(e.aeros,t),battery:t=>Ua(e.batteries,t),brake:t=>Ua(e.brakes??[],t),damper:t=>Ua(e.dampers??[],t),suspensionOf:t=>wi(L1(e,t),t)}}function L1(e,t){let r=Ua(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 qa(e,t,r){let n={front:t.tire(e.tireModelId),rear:t.tire(e.tireModelIdRear)};return D1(dw(t.suspensionOf(e),e,n),t,r)}function A4(e){return Ca(e.air)?UF(e.air,e.airTempC??lr):void 0}function w4(e,t){return t?{...e,rho:{...e.rho,value:t.rho},readouts:{...e.readouts,rho:Ep}}:e}function C4(e,t,r){if(!r)return{rho:e.rho,motorModel:t,readouts:e.readouts};let{rho:n,readouts:o}=w4(e,r);return{rho:n,motorModel:t&&kt(t)?F1(t,r):t,air:r,readouts:o}}function D1(e,t,r){let n=t.tire(e.tireModelId),o=t.tire(e.tireModelIdRear),a=CD(wD(If(Mw(Rw(Dw(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}=C4(a,t.motor(e.motorModelId),A4(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),...rl(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 L4=e=>e!==!1,D4=(e,t,r)=>r&&t>0?(e%t+t)%t:Math.min(Math.max(e,0),t);function E4(e,t,r){let n=e.points.filter(o=>Number.isFinite(o.at)&&Number.isFinite(o.z)).map(o=>({...o,at:D4(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 I4(e,t,r){let n=E4(e,t,r),o=n.length;if(o===0)return[];let a=m=>m<o-1?n[m+1].at-n[m].at:r?n[0].at+t-n[m].at:1/0,s=m=>m<o-1?(n[m+1].z-n[m].z)/a(m):r&&o>1?(n[0].z-n[m].z)/a(m):0,i=n.map(m=>Math.max(0,Number.isFinite(m.curve)?m.curve:0)/2),c=(m,f,h)=>i[m]+i[f]>h?h*i[m]/(i[m]+i[f]):i[m],l=m=>m<o-1||r?c(m,m<o-1?m+1:0,a(m)):Math.max(0,t-n[m].at),u=m=>m>0?c(m,m-1,a(m-1)):r?c(m,o-1,a(o-1)):n[m].at,d=m=>m>0?s(m-1):r&&o>1?s(o-1):n[m].at<=1e-9?s(m):0,p=m=>!r&&m===o-1&&o>1&&n[m].at>=t-1e-9?s(m-1):s(m);return n.map((m,f)=>{let h=l(f),b=u(f),g=Math.min(i[f],h,b),y=!r&&g<i[f]&&(f===o-1&&g===h||f===0&&g===b);return{at:m.at,z:m.z,gIn:d(f),gOut:p(f),half:g,asked:i[f],atEnd:y}})}function _4(e,t,r,n){let o=t-e.at;return n&&r>0?o-r*Math.round(o/r):o}function N4(e,t,r,n){for(let s of e){let i=_4(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 TD(e,t,r,n){let o=L4(n),a=I4(e,r,o);return a.length?t.map(s=>N4(a,s,r,o)):t.map(()=>0)}function wu(e,t){if(!t?.points.length)return e;let r=eu(e),{zSmoothing:n,...o}=e;return{...o,z:TD(t,r,Gx(e),e.closed)}}var Uf={widthLeft:1.5,widthRight:1.5,bank:0,mu:1};function PD(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 Cu(e,t){let r=PD(e.source);return LD(e,r?await t(r):void 0)}function LD(e,t){let{source:r}=e;if(r.kind==="segments"){let{segments:i,closed:c,spacing:l}=r,{asset:u}=ru(i,{name:e.name,closed:c,spacing:l,base:Uf});return wu(u,r.profile)}let n=r.sections??[];if(r.kind==="inline")return wu(Qp(r.asset,n,Uf),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 wu(Qp({...t,...o!==void 0?{widthLeft:o}:{},...a!==void 0?{widthRight:a}:{},...s!==void 0?{closed:s}:{}},n,Uf),r.profile)}var tRe=1/500;var rRe=5*Math.PI/180;var mRe=1/3;var $4=[4,2,1,.5,.25,.125];function DD(e,t,r={}){let n=[...r.steps??$4].sort((g,y)=>y-g),o=Nt(r.numerics),a=r.tolPct??.5,s=ur(e),i=e.ggvMode??"twoTrack",c=pn(s,!1,i),l={...o,dsTarget:n[0]??o.dsTarget},u=n.length?Ra(s,c,[Ot(t,l)],l,i):void 0,d=wo(s,c.rows),p=n.map((g,y)=>{let x={...o,dsTarget:g},v=Date.now(),k=Ot(t,x),R=er(c,k,x,{...u?{load:u}:{},...d?{shifts:d}:{}});return r.onStep?.(y+1,n.length),{dsTarget:g,npts:k.npts,lapTime:R.laptime,ms:Date.now()-v}}),m=p[p.length-1]?.lapTime??NaN,f=p.map(g=>{let y=g.lapTime-m;return{...g,delta:y,deltaPct:m?100*y/m:NaN}}),h=f.filter(g=>Math.abs(g.deltaPct)<=a),b=h.length?Math.max(...h.map(g=>g.dsTarget)):null;return{points:f,reference:m,recommended:b,tolPct:a}}function ao(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:A1(t.airTempC??r.airTempC),...Ca(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:Nt(r.numerics)}}async function Xf(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 Cu(r,t)}}function I1(e,t){let r=structuredClone(e);for(let[n,o]of Object.entries(t))if(!Js(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 E1=(e,t)=>{let r=e?.name;return typeof r=="string"&&r?r:t};function H4(e,t){let r={};for(let n of To){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:E1(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:E1(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:E1(i.model,i.id),byFallback:!0}:null;continue}r[n.doc]=null}return r}function z4(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 ED(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 _1=e=>e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`;async function qf(e,t,r={}){let n=ao(e,r.settings),{entry:o,asset:a}=await Xf(e,t),s=Xa(e),i=r.vehicleIds?.length?r.vehicleIds.map(f=>{let h=e.vehicles.find(b=>b.id===f);if(!h)throw new Error(`this project holds no vehicle "${f}"`);return h}):e.vehicles.filter(f=>f.visible);if(!i.length)throw new Error("no vehicle is visible in this project \u2014 name some in vehicleIds");let c=i.map(f=>{let h=r.overrides?.[f.id]?I1(f.params,r.overrides[f.id]):f.params;return qa(structuredClone(h),s,n)}),l=Nl(Aa(e.meta.rulesetId,e.rulesets)),u=Gl(c,a,n.numerics,l,{racingLine:n.racingLine,standingStart:n.standingStart,lapCounts:n.lapCounts}),d={};i.forEach((f,h)=>{d[f.id]=u[h]});let{scores:p,field:m}=Wy(l,d);return{rulesetId:e.meta.rulesetId,track:o.name,settings:{ggvMode:n.ggvMode,quasiTransient:n.quasiTransient,motorThermal:n.motorThermal,brakeFade:n.brakeFade,airTempC:n.airTempC,...n.air?{air:n.air}:{},diffYaw:n.diffYaw,racingLine:n.racingLine,standingStart:n.standingStart},fleetScored:p!==null,vehicles:i.map((f,h)=>({id:f.id,name:u[h].name||String(f.params.name??f.id),events:z4(u[h]),metrics:jy(l,u[h],m?.[f.id]),fitted:H4(e,f.params),...p?.[f.id]?{score:{total:p[f.id].total,parts:{...p[f.id].parts}}}:{}})),raw:{results:d,scores:p,field:m}}}async function ID(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=ao(e),{asset:a}=await Xf(e,t),s=qa(structuredClone(n.params),Xa(e),o);return DD(s,a,{...r.steps?{steps:r.steps}:{},numerics:o.numerics,...r.tolPct!==void 0?{tolPct:r.tolPct}:{},...r.onStep?{onStep:r.onStep}:{}})}var mve=Math.PI/180;var N1=["param.arb_front","roll.front.rate","roll.front.wheelRate"],ND="dyn.tlltdFront",O1=1e-6;function Qf(e){let t=bt(e),r=t["param.arb_front"];if(!r)return{why:"the car states no front anti-roll bar"};let n=r.supersededBy,o=n?n.useInstead:r.id,a=o?t[o]:void 0;if(!a||a.supersededBy)return{why:`its front bar is ${(n?.why??"computed elsewhere").replace(/^computed from /,"")}, whose rate is not one number to re-solve`};let s=a.read(e);return s>0?{id:a.id,def:a,now:s}:{why:"the car has no front bar to re-solve: its rate is zero"}}function OD(e,t,r,n,o=O1,a){let s=0,i=b=>(s++,e(b)-t),c=(b,g,y)=>({value:b,reading:t+g,reached:y,reads:s});if(a!==void 0&&a>=r&&a<=n){let b=i(a);if(Math.abs(b)<=o)return c(a,b,!0)}let l=r,u=n,d=i(l),p=i(u);if(!Number.isFinite(d)||!Number.isFinite(p))return c(NaN,NaN,!1);if(Math.abs(d)<=o)return c(l,d,!0);if(Math.abs(p)<=o)return c(u,p,!0);if(d*p>0)return Math.abs(d)<=Math.abs(p)?c(l,d,!1):c(u,p,!1);let m=0,f=l,h=d;for(let b=0;b<60;b++){if(f=(l*p-u*d)/(p-d),h=i(f),!Number.isFinite(h))return c(NaN,NaN,!1);if(Math.abs(h)<=o||Math.abs(u-l)<=1e-12*Math.max(1,Math.abs(f)))break;h*p>0?(u=f,p=h,m===-1&&(d/=2),m=-1):(l=f,d=h,m===1&&(p/=2),m=1)}return c(f,h,Math.abs(h)<=o)}function Zf(e,t){let r=e.variables.findIndex(a=>N1.includes(a.id));if(r<0)return{why:"the front bar is not one of the variables"};let n=t.byId[ND];if(!n)return{why:"the balance cannot be read here"};let o=NaN;try{o=Rt(e.build(Vr(e.variables)).ev,n)}catch{}return Number.isFinite(o)?{slot:r,target:o,metric:n}:{why:"the car\u2019s balance could not be read"}}function Jf(e,t,r){let n=e.variables[r.slot],a=OD(i=>{let c=t.slice();c[r.slot]=i;try{return Rt(e.build(c).ev,r.metric)}catch{return NaN}},r.target,Math.max(0,n.lo),Math.max(0,n.hi),O1,t[r.slot]),s=t.slice();return Number.isFinite(a.value)&&(s[r.slot]=a.value),{x:s,held:{value:s[r.slot],balance:a.reading,target:r.target,reached:a.reached}}}var V1="param.m",B1=.01;function $1(e,t,r){return r===void 0||!Number.isFinite(r)||r===0||!Number.isFinite(e)||!Number.isFinite(t)?NaN:(e-t)/r}var eh=.5,oz=new Set(["lap","session"]);function az(e){return ut({...e,label:e.label.replace(/ [xyz]$/,"")})}function VD(e){let t=Ga(e);if(t)return[t.point];let r=Cr(e);if(r)return[r.point];let n=/^arm\.(front|rear)\.(uca|lca)\./.exec(e);if(n){let a=yr[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]}.${vn.fore}`,`hp.${o[1]}.${vn.aft}`]:[]}function BD(e,t){let r=Bt(e,t),n=bt(e),o=new Map;for(let a of[...r.variables,...r.followers??[]])for(let s of VD(a.id)){if(o.has(s))continue;let i=Fi.map(c=>`${s}.${c}`).filter(c=>n[c]&&!n[c].supersededBy);i.length&&o.set(s,{id:s,name:az(n[i[0]]),coords:i})}return[...o.values()]}function G1(e,t,r,n={},o=eh){let a=Bt(e,t),s=(n.metrics??gr()).byId,i=Ni(e,a,r),c=BD(e,a),l=bt(i),u=[];a.objectives.forEach((A,C)=>{let P=s[A.metricId];P&&u.push({key:A.key??`target:${C}`,role:"target",metric:P,at:A.at})}),a.constraints.forEach((A,C)=>{let P=s[A.metricId];P&&u.push({key:A.key??`hold:${C}`,role:"hold",metric:P,at:A.at,hold:A})}),(a.watches??[]).forEach((A,C)=>{let P=s[A.metricId];P&&u.push({key:A.key??`watch:${C}`,role:"watch",metric:P,at:A.at})});let d=u.filter(A=>!oz.has(A.metric.cost)),p=A=>{let C=Wf(A,a,n),P=d.map(L=>Rt(C,L.metric,L.at));return C.failure?null:P},m=p(i)??d.map(()=>NaN),f=[],h=[],b=[],g=1,y=[...m],x=[...m],v=A=>A.forEach((C,P)=>{Number.isFinite(C)&&(C>=y[P]||(y[P]=C),C<=x[P]||(x[P]=C))}),k=A=>{g++;try{return p(A())}catch{return null}};for(let A of c)for(let C of A.coords){let P=l[C],L=P.read(i),E=C.slice(C.lastIndexOf(".")+1),_=k(()=>P.write(i,L+o)),D=k(()=>P.write(i,L-o));if(!_||!D){b.push(`${A.name} ${E}`);continue}f.push({id:C,def:P,now:L,point:A,axis:E}),h.push([_,D]),v(_),v(D)}let R=new Map,M=A=>{let C=A.join("");if(R.has(C))return;let P=k(()=>f.reduce((L,E,_)=>E.def.write(L,E.now+A[_]*o),i));R.set(C,P),P&&v(P)};f.length>1&&d.forEach((A,C)=>{let P=h.map(([L,E])=>L[C]-m[C]>=E[C]-m[C]?1:-1);Number.isFinite(m[C])&&(M(P),M(P.map(L=>-L)))});let S=[...R.values()].filter(A=>!A).length;S&&b.push(`${S} of ${R.size} corners`);let w=u.map(A=>{let C={key:A.key,role:A.role,name:ht(A.metric)+Wa(A.at,A.metric,a),unit:A.metric.unit==="-"?"":A.metric.unit,...A.hold?{limit:{op:A.hold.op,limit:A.hold.limit,...A.hold.limit2!==void 0?{limit2:A.hold.limit2}:{}}}:{}},P=d.indexOf(A);if(P<0)return{...C,value:NaN,lo:NaN,hi:NaN,skipped:"read off a lap"};let L=m[P],E=Number.isFinite(L)?y[P]:NaN,_=Number.isFinite(L)?x[P]:NaN,D=h.map(([B,z])=>Math.max(Math.abs(B[P]-L),Math.abs(z[P]-L))),I=D.filter(Number.isFinite).reduce((B,z)=>B+z,0),V;if(I>0){let B=D.indexOf(Math.max(...D.filter(Number.isFinite)));V={point:f[B].point.name,axis:f[B].axis,share:D[B]/I}}let O=A.hold?Math.max(_o(A.hold,E),_o(A.hold,_)):void 0;return{...C,value:L,lo:E,hi:_,...V?{most:V}:{},...O!==void 0?{excess:O}:{}}}),F=new Set(c.flatMap(A=>A.coords)),T=a.variables.filter(A=>!VD(A.id).length&&!F.has(A.id)).length;return{mm:o,points:c,rows:w,evaluations:g,unsolved:b,settings:T}}function K1(e){if(!e.chassis)return e;let{chassis:t,...r}=e;return t.boxes.length?{...r,chassis:{boxes:t.boxes}}:r}var QAe=180/Math.PI;var Gz={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:Sa,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 wCe=Gz.id;var Qa=.02;function ZD(e){let t=Math.max(Qa,Math.abs(e.heaveMotionRatio)),r=Math.max(Qa,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 Hz=(e,t)=>({od:t,id:Math.min(e.id,t-.5)}),zz=(e,t)=>e/(2*t*t);function QD(e,t){switch(e.kind){case"ubar":case"blade":case"torsionTube":return{...e,section:Hz(e.section,t)};default:return e}}function JD(e,t,r){let n=Math.max(Qa,Math.abs(r));if(e?.kind==="coil"){let l=zz(t,n),u=e.rate;if(typeof u=="number")return{...e,rate:l};let d=Wn(u,0);if(!(d>0))return{...e,rate:l};let p=l/d;return{...e,rate:{...u,y:u.y.map(m=>m*p)}}}let o=t/(n*n),a=e&&(e.kind==="ubar"||e.kind==="blade"||e.kind==="torsionTube")?e:{kind:"torsionTube",section:{od:20,id:16},length:400,leverArm:60,G:8e4},s=l=>sl(QD(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 QD(a,c)}function eE(e,t,r,n){let o=e?.design,a=JD(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 Yz=Math.PI/180,th=1e-6;function Wz(e){return!(Pe(e.rockerPivotA,e.rockerPivotB)<th||Pe(e.rockerToPushrod,e.rockerPivotA)<th||Pe(e.rockerToDamper,e.rockerPivotA)<th||Pe(e.rockerToDamper,e.damperChassis)<th)}function oE(e){if(!Wz(e.hardpoints))return!1;let t={...e,config:{...e.config,actuation:"rocker"}};try{let r=wt(t);for(let n of[-20,-1,0,1,20]){let o=Ae(r,n,0);if(!o.ok||!Number.isFinite(o.state.metrics.damperLength))return!1}return!0}catch{return!1}}function Y1(e){if(e.config.actuation!=="direct"||oE(e))return;let{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}=Uz(e);return{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}}var tE=40;function rh(e,t={}){let r=e.hardpoints,n=r.pushrodOuter,o=r.damperChassis,a=Pe(n,o),s=oe(n,X(H(o,n),jz)),i=t.armRod??Math.max(25,.15*a),c=t.armDamper??i,l=[s[0]-tE,s[1],s[2]],u=[s[0]+tE,s[1],s[2]],d=re(H(u,l)),p=H(n,s),m=re(H(p,X(d,rE(p,d)))),f=sr(m,d,(t.armAngleDeg??60)*Yz),h=oe(s,X(f,i)),b=H(o,s),g=re(H(b,X(d,rE(b,d)))),y=X(re(le(d,g)),t.damperSide??1),x=oe(s,X(y,c));return{...r,rockerPivotA:l,rockerPivotB:u,rockerToPushrod:h,rockerToDamper:x}}var jz=.72,rE=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2];function nE(e){let t=ct(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 Uz(e,t={}){let r=t.target??nE(e),n=t.armAngleDeg,o=rh(e,{armAngleDeg:n});if(!(r>0))return o;let a=Pe(e.hardpoints.pushrodOuter,e.hardpoints.damperChassis),s=Math.max(25,.15*a),i=(()=>{for(let m of[1,-1]){let f=rh(e,{armRod:s,armAngleDeg:n,damperSide:m}),h={...e,config:{...e.config,actuation:"rocker"},hardpoints:f};try{let b=wt(h),g=Ae(b,15,0),y=Ae(b,-15,0);if(g.ok&&y.ok&&g.state.metrics.damperLength<y.state.metrics.damperLength)return m}catch{}}return 1})(),c=(m,f)=>{try{return nE({...e,config:{...e.config,actuation:"rocker"},hardpoints:rh(e,{armRod:m,armAngleDeg:n,armDamper:f,damperSide:i})})}catch{return Number.NaN}},l=[1,.6,.35,.2,1.7,2.6].map(m=>Math.max(12,s*m)),u=s,d=s,p=1/0;for(let m of l){let f=.25*m,h=6*m,b=m;for(let y=0;y<24;y++){let x=(f+h)/2,v=c(m,x);if(!Number.isFinite(v))break;b=x,v<r?f=x:h=x}let g=Math.abs(c(m,b)-r);if(Number.isFinite(g)&&g<p&&(p=g,u=m,d=b),p<1e-4*Math.max(1,r))break}return rh(e,{armRod:u,armAngleDeg:n,armDamper:d,damperSide:i})}var $Ce=Array.from({length:19},(e,t)=>-45+5*t);var GCe=Math.PI/180;function Xz(e){let t=e.hardpoints,r=re(H(t.rockerPivotB,t.rockerPivotA)),n=Fn(t.rockerToDamper,t.rockerPivotA,r),o=.6*qr(H(t.rockerToDamper,n)),a=le(r,jv),s=qr(a)>1e-6?re(a):re(H(t.rockerToDamper,n));return{outer:oe(n,X(s,o)),inner:oe(n,X(s,-o)),attach:"rocker"}}var sE=(e,t)=>({...e,config:{...e.config,actuation:t}});function W1(e,t,r,n){let o=r==="front"?e.front:e.rear,a=t.decoupledElements?.[r],s=Y1(o);if(a&&Qz(o,t,r,a)){let C=a.kept;return{heave:C.heave??{design:{kind:"none"}},arb:C.arb??{design:{kind:"none"}},cornerDamper:C.damper,scalars:{heave:C.heaveSpring,arb:C.arbRate},...s?{crank:s}:{}}}let i=qs(o),c=o.config.springRate*i*i,l=ee(t,r==="front"?"damper_front":"damper_rear")*i*i,u=r==="front"?t.arbFrontDesign:t.arbRearDesign,d=ul(e,t)[r]??ee(t,r==="front"?"arb_front":"arb_rear"),p=Qs(e,t)[r]??ee(t,r==="front"?"heave_spring_front":"heave_spring_rear"),m=sE(s?{...o,hardpoints:{...o.hardpoints,...s}}:o,"decoupled"),f=r==="front"?t.heaveFrontDesign:t.heaveRearDesign,h=a?a.kept.heave:f,b=a?a.kept.arb:u,g=n?.heave??aE(h?.linkage,C=>zo(m,C).atDesign)??yb(m,"rockerToRocker"),y=!b||b.design.kind==="none"||b.design.kind==="coil",x=y?"coil":"ubar",v=b?.linkage&&(a||b.design.kind==="none"||b.linkage.attach!=="rocker")?b.linkage:void 0,k=n?.roll??aE(y?v:b?.linkage,C=>xs(m,C,{kind:x}).atDesign)??(y?Xz(m):jA(m)),R=zo(m,g).atDesign,M=xs(m,k,{kind:x}).atDesign,S=Ld(e,t),w=ZD({cornerWheelRate:c,cornerDamper:l,arbWheelRate:d,heaveWheelRate:p,heaveWheelDamping:r==="front"?S.heaveFront:S.heaveRear,rollWheelDamping:r==="front"?S.rollFront:S.rollRear,heaveMotionRatio:R,rollMotionRatio:M}),F=!b||b.design.kind==="none"?{design:{kind:"coil",rate:1},linkage:k}:{...b,linkage:k},T=eE({design:h?.design??{kind:"none"},linkage:g,damper:h?.damper},F,w,M),A=(C,P)=>a&&P?.coilover&&C.linkage===P.linkage?{...C,coilover:P.coilover}:C;return{heave:A(T.heave,h),arb:A(T.arb,b),cornerDamper:ee(t,r==="front"?"damper_front":"damper_rear")*Zz(o,"rocker").f,...s?{crank:s}:{}}}function qz(e,t){let r=t==="front"?e.heaveFrontDesign:e.heaveRearDesign,n=t==="front"?e.arbFrontDesign:e.arbRearDesign;return{...r?{heave:r}:{},...n?{arb:n}:{},damper:ee(e,t==="front"?"damper_front":"damper_rear"),heaveSpring:ee(e,t==="front"?"heave_spring_front":"heave_spring_rear"),arbRate:ee(e,t==="front"?"arb_front":"arb_rear")}}function Qz(e,t,r,n){let o=e.config.decoupledSpring;return o!==void 0&&o.wrote===e.config.springRate&&Au(qz(t,r),n.wrote)}function aE(e,t){return e&&Math.abs(t(e))>=Qa?e:void 0}function Zz(e,t){let r=t==="rocker"?Y1(e):void 0,n=sE(r?{...e,hardpoints:{...e.hardpoints,...r}}:e,t),o=qs(e),a=qs(n);return{next:n,f:o>=Qa&&a>=Qa?(o/a)**2:1,...r?{crank:r}:{}}}var nh=[{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"]}],j1=()=>({arbFront:void 0,arbRear:void 0,heaveFront:void 0,heaveRear:void 0}),Jz={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]}},e6={front:{pushrodOuter:[-3,510,359],rockerPivotA:[-20,174,181],rockerPivotB:[-20,200,139],rockerToPushrod:[18,199,167],rockerToDamper:[-20,102,108],damperChassis:[205,102,108]},rear:{pushrodOuter:[-1,516,365],rockerPivotA:[39,177,181],rockerPivotB:[39,203,139],rockerToPushrod:[1,202,167],rockerToDamper:[39,112,111],damperChassis:[-186,112,111]}},t6=()=>({outer:[0,189,486],attach:"rocker",mount:{kind:"chassis",anchor:[-225,0,486]}}),r6={rate:60,motionRatio:1},n6={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]}},o6=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]}},a6={kind:"coil",rate:1560,motionRatio:1,gap:0,bothWays:!0},s6=40,i6={rockerPivotA:[50,130,440],rockerPivotB:[-50,130,440],rockerToPushrod:[10,170,460],rockerToDamper:[-20,64,440],damperChassis:[-20,64,215]},iE=()=>({outer:[-50,130,480],attach:"rocker",shaftStation:-50}),cE=()=>({outer:[50,130,400],inner:[50,130,480],attach:"rocker",shaftStationOuter:50,shaftStationInner:50}),c6=e=>[e[0],e[1],e[2]];function l6(e){let t=r=>({...r,hardpoints:{...r.hardpoints,...uE(i6)},config:{...r.config,actuation:"decoupled"}});return{...e,front:t(e.front),rear:t(e.rear)}}function uE(e){return Object.fromEntries(Object.entries(e).map(([t,r])=>[t,c6(r)]))}function mE(e,t=La(),r=e==="pull"?e6:Jz){let n=(o,a)=>({...o,hardpoints:{...o.hardpoints,...uE(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 oh(e,t){let r=U1(e),n=Oi(e);if(e==="heave")return{meta:r,vehicle:n,components:{...j1(),heaveFront:{design:{..._0,...r6},linkage:t6()}}};if(e!=="decoupled")return{meta:r,vehicle:n,components:j1()};let o=W1(n,t,"front",{heave:iE(),roll:cE()}),a=W1(n,t,"rear",{heave:iE(),roll:cE()});return{meta:r,vehicle:n,components:{arbFront:o.arb,arbRear:a.arb,heaveFront:o.heave,heaveRear:a.heave}}}function Oi(e){let{name:t}=U1(e);if(e==="direct")return{...zl(),name:t};if(e==="mcpherson"){let n=Yl(),o=_p();return{...n,front:{...o,config:{...o.config,loadedRadius:n.front.config.loadedRadius}},name:t}}let r=u6(mE(e==="pullrod"?"pull":"push"));return{...e==="decoupled"?l6(r):r,name:t}}var lE={front:221.7,rear:220.9};function u6(e){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:lE.front}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:lE.rear}}}}function U1(e){let t=nh.find(r=>r.id===e);if(!t)throw new Error(`Unknown suspension template: ${e}`);return t}function ah(){let e=t=>({design:{...a6},linkage:o6(t),damper:s6});return{meta:U1("heave"),vehicle:mE("push",ex(),n6),components:{...j1(),heaveFront:e("front"),heaveRear:e("rear")}}}var dE=[10,25,50,100,200,300],m6=[{id:"c1",label:"Soft",scale:.7},{id:"c2",label:"Medium",scale:1},{id:"c3",label:"Firm",scale:1.4}],pE=e=>Math.round(e*100)/100;function d6(e,t,r){let n=dE.map(o=>pE(r*o));return{id:e,label:t,speedMmS:[...dE],bumpN:n,reboundN:[...n]}}function p6(e){return{name:e.name,body:{...e.body},curves:m6.map(t=>d6(t.id,t.label,pE(e.coefficient*t.scale)))}}function Fu(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 kn(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:Ql[e.dampers.length%Ql.length],model:p6(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 $t=e=>`${e} (typical)`,X1={car:{name:$t("Formula Student damper"),coefficient:2.5,body:{extended:249,stroke:55}}},sh={car:X1.car,heave:{name:$t("Formula Student heave damper"),coefficient:3.4,body:{extended:270,stroke:47}},roll:{name:$t("Formula Student roll damper"),coefficient:3.7,body:{extended:322,stroke:100}}},ih={car:{name:$t("Formula 1 damper"),coefficient:6,body:{extended:240,stroke:40}},heave:{name:$t("Formula 1 heave damper"),coefficient:40,body:{extended:240,stroke:40}}},fE={car:{name:$t("GT damper"),coefficient:4.5,body:{extended:510,stroke:80}}},q1={car:{name:$t("Sports car damper"),coefficient:2.4,body:{extended:515,stroke:110}}},hE={car:{name:$t("Sports car strut"),coefficient:2.4,body:{extended:310,stroke:120}},rear:q1.car},bE={car:{name:$t("Cup car strut"),coefficient:4,body:{extended:285,stroke:75}},rear:{name:$t("Cup car rear damper"),coefficient:3.5,body:{extended:505,stroke:80}}},gE={car:{name:$t("Stock car front damper"),coefficient:7.5,body:{extended:555,stroke:110}},rear:{name:$t("Stock car rear damper"),coefficient:6.75,body:{extended:555,stroke:110}}},yE={car:{name:$t("Hill-climb front damper"),coefficient:3,body:{extended:285,stroke:65}},rear:{name:$t("Hill-climb rear damper"),coefficient:3.5,body:{extended:285,stroke:65}}},xE={car:{name:$t("Race truck front damper"),coefficient:12,body:{extended:780,stroke:160}},rear:{name:$t("Race truck rear damper"),coefficient:8.5,body:{extended:780,stroke:160}}};var No=(e,t)=>({diameter:e*25.4,width:t*25.4,offset:20,wall:4}),Vi=e=>({front:e,rear:e}),Q1=Vi(No(13,7)),RE=Vi(No(18,12)),vE=Vi(No(18,10)),kE=Vi(No(17,8)),ME={rear:No(17,8)},SE=Vi(No(18,9)),AE=Vi(No(18,12)),wE={front:No(22.5,9)};function so(e,t){for(let r of e.suspensions){let n={...r.model.parts};for(let o of["front","rear"]){let a=t[o];a&&(n[o]={...n[o],rim:{...a}})}(n.front||n.rear)&&(r.model.parts=n)}}function $i(e){return e.vehicles=e.vehicles.slice(0,1),e.activeVehicleId=e.vehicles[0]?.id??null,e}function Oo(e,t){let r=Zl(e);return r.meta.rulesetId=t,r}function Za(e,t,r,n){let o=Oo(e,t);return o.suspensions=[{...o.suspensions[0],model:n()}],o.vehicles=[wx(r,"v1",0)],o.activeVehicleId="v1",o}var[,f6,h6,b6,g6,y6,x6,R6]=cx;function Z1(e,t){delete e.arbFrontDesign,delete e.arbRearDesign,delete e.rollBarFrontDesign,delete e.rollBarRearDesign,delete e.heaveFrontDesign,delete e.heaveRearDesign,t.arbFront&&(e.arbFrontDesign=structuredClone(t.arbFront)),t.arbRear&&(e.arbRearDesign=structuredClone(t.arbRear)),t.heaveFront&&(e.heaveFrontDesign=structuredClone(t.heaveFront)),t.heaveRear&&(e.heaveRearDesign=structuredClone(t.heaveRear))}function CE(){return{...Oi("decoupled"),name:La().name}}var v6=[{label:"Formula Student (decoupled)",vehicle:CE,components:e=>Fu(oh("decoupled",e).components,sh)},{label:"Formula 1 (third springs)",vehicle:()=>ah().vehicle,components:()=>Fu(ah().components,ih)}],J1={"direct-coilover":"direct",pushrod:"pushrod",pullrod:"pullrod","third-spring":"heave","mcpherson-strut":"mcpherson"},k6=[...v6.map(e=>e.vehicle),...Object.values(J1).map(e=>()=>Oi(e))];function Bi(e){let t=Fu(oh("decoupled",e.vehicles[0].params).components,sh);e.suspensions=[{...e.suspensions[0],model:CE()}];for(let r of e.vehicles)Z1(r.params,t);return kn(e,sh),so(e,Q1),e}var Ja={title:"OpenStreetMap",url:"https://www.openstreetmap.org/copyright",licence:"ODbL-1.0",credit:"\xA9 OpenStreetMap contributors"},ch={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"},FE={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]"},TE={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"},M6={id:"cota",name:"Circuit of the Americas, Austin",address:"e0c6ea889d708cf15f9c",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,ch,TE]}},S6={id:"laguna-seca",name:"Laguna Seca, Monterey",address:"185b5811b9c423ef44ef",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,ch,TE]}},A6={id:"nordschleife",name:"Nordschleife, N\xFCrburg",address:"74c49603c7b2f15985c6",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,FE]}},w6={id:"brands-hatch",name:"Brands Hatch, Kent",address:"c4953e3c25eaba4a5b7e",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,{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."}]}},C6={id:"bristol",name:"Bristol, Tennessee",address:"f0e23953669a414ad600",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,ch]}},F6={id:"pikes-peak",name:"Pikes Peak, Colorado",address:"3de137fe33b5c2875036",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,ch]},standingStart:!0},T6={source:"venue",altitudeM:3580,pressure:{kind:"standard"},humidityPct:0},P6=10,L6={id:"nurburg-sprint",name:"Sprintstrecke, N\xFCrburg",address:"1875636cdbb615aa2756",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Ja,FE]}};function es(e,t){let{id:r,name:n,address:o,provenance:a,standingStart:s}=t,i={kind:"catalogue",id:r,address:o},c=Wl(yx({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 Vo(e,t,r){let n=e.vehicles[0].params,o=`m${e.motors.length+1}`;e.motors=[...e.motors,{id:o,color:Po[e.motors.length%Po.length],model:t}];let a=bw({},{...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 D6=3.8,lh={hubPlanetary:14.5,inboardChain:4,engineChain:3.4},E6="Hub motor, 35 kW (example)";function ev(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 PE(e){let t=e.motors.find(r=>r.id==="m1");return t.model={...t.model,name:E6},t.id}function uh(e,t,r){let n=$i(Bi(Oo(e,r)));return n.vehicles[0].params.name=t,n}function I6(){let e=uh("Formula Student combustion car","Formula Student combustion","fs-cv");Vo(e,px(),lh.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 _6(){let e=uh("Formula Student AWD car","Formula Student AWD","fs-ev");return ev(e,PE(e),4,"awd",lh.hubPlanetary,"hub"),e}function N6(){let e=uh("Formula Student RWD hub-motor car","Formula Student RWD hub motors","fs-ev");return ev(e,PE(e),2,"rear",lh.hubPlanetary,"hub"),e}function O6(){let e=uh("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:Po[e.motors.length%Po.length],model:dx()}],ev(e,t,1,"rear",lh.inboardChain),e.vehicles[0].params.driveline={rear:structuredClone(Jt.clutch)},e}function V6(){let e=$i(Bi(Oo("Formula Student endurance energy","fs-ev"))),t=e.vehicles[0],r=structuredClone(t);if(r.id="v2",r.color=ql[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 B6(){let e=ah(),t=Za("Formula 1 car","trackday",f6,()=>e.vehicle);return Z1(t.vehicles[0].params,Fu(e.components,ih)),kn(t,ih),so(t,RE),Vo(t,fx(),D6),es(t,M6)}function LE(e="GT car",t=zl){let r=Za(e,"trackday",h6,t);return kn(r,fE),so(r,vE),Vo(r,cT(),r.vehicles[0].params.gear_ratio.value),es(r,S6)}function DE(e="Sports car",t=Yl,r=q1,n=kE){let o=Za(e,"trackday",b6,t);return kn(o,r),so(o,n),Vo(o,lT(),o.vehicles[0].params.gear_ratio.value),es(o,A6)}function $6(){let e=Za("Cup car","trackday",g6,qF);return kn(e,bE),so(e,SE),Vo(e,uT(),e.vehicles[0].params.gear_ratio.value),es(e,w6)}function G6(){let e=Za("Stock car","trackday",y6,QF);return kn(e,gE),so(e,AE),Vo(e,mT(),e.vehicles[0].params.gear_ratio.value),es(e,C6)}function K6(){let e=Za("Hill-climb prototype","trackday",x6,ZF);return kn(e,yE),Vo(e,dT(),e.vehicles[0].params.gear_ratio.value),e.settings.air=structuredClone(T6),e.settings.airTempC=P6,es(e,F6)}function H6(){let e=Za("Race truck","trackday",R6,JF);return kn(e,xE),so(e,wE),Vo(e,pT(),e.vehicles[0].params.gear_ratio.value),es(e,L6)}function z6(e){let t=nh.find(o=>o.id===e);if(e==="direct")return LE(t.name,()=>Oi(e));if(e==="mcpherson")return DE(t.name,()=>Oi(e),hE,ME);let r=$i(Oo(t.name,"trackday")),n=oh(e,r.vehicles[0].params);return r.suspensions=[{...r.suspensions[0],model:n.vehicle}],Z1(r.vehicles[0].params,n.components),kn(r,X1),so(r,Q1),r}function Tu(e,t,r){let n=J1[e],o=nh.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:()=>z6(n)}}var Y6=[{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:()=>Bi(Oo("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:V6},{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:()=>$i(Bi(Oo("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:I6},{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:_6},{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:N6},{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:O6},{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:B6},{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:LE},{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:DE},{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:$6},{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:G6},{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:K6},{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:H6},{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:()=>$i(Bi(Oo("Suspension study","trackday")))},Tu("direct-coilover","The GT car\u2019s wishbones driving coilovers straight into the towers, at Laguna Seca.","On the GT car, at Laguna Seca."),Tu("pushrod","The FS car on pushrods: a rod from each lower wishbone works a rocker.","On the Formula Student car, at FSG."),Tu("pullrod","The FS car on pullrods: a rod from each upper wishbone pulls a low rocker.","On the Formula Student car, at FSG."),Tu("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."),Tu("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:()=>$i(Bi(Oo("Tyre study","fs-ev")))}],EE=Y6.map(e=>({...e,load:()=>Cx(e.load())}));var IE={width:320,height:200},FFe=[.6*IE.width-9,.6*IE.height-9];var _E=new WeakMap,NE=new WeakMap,tv=e=>JSON.stringify(e,(t,r)=>r===1/0?"Infinity":r);function OE(e,t){if(!t){let a=_E.get(e);return a||(a=pr(e),_E.set(e,a)),a}let r=NE.get(e);r||(r=new Map,NE.set(e,r));let n=tv(t),o=r.get(n);return o||(r.size>=4&&r.clear(),o=pr(e,t),r.set(n,o)),o}var U6=Math.PI/180,X6=e=>e>1?e/100:e;function Pu(e){let t=null;return()=>(t??={v:e()}).v}function VE(e){let t=ct(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 BE=new WeakMap,rv={heave:0,pitch:0,roll:0,steer:0},$E=[0,1,2,3,4],GE=[-20,-10,0,10,20];function HE(e,t){let r=jn(e,rv),n=["front","rear"],o=c=>{let l=js(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 $E){let l=c===0?null:jn(e,{...rv,roll:c*U6});n.forEach((u,d)=>{let p=l?js(l[u]):null,m=p&&Number.isFinite(a[d]);s[d].rc.push(m?t[d]+(p.left+p.right)/2-a[d]:t[d]),s[d].split.push(m?(p.left-p.right)/2:0)})}let i=n.map(()=>[]);for(let c of GE){let l=c===0?null:jn(e,{...rv,heave:-c});n.forEach((u,d)=>{let p=l&&l[u].valid&&r[u].valid;i[d].push(p?t[d]+l[u].height-r[u].height:t[d])})}return{roll:{rollDeg:$E,rcFront:s[0].rc,rcRear:s[1].rc,rcSplitFront:s[0].split,rcSplitRear:s[1].split},heave:{drop:GE,rcFront:i[0],rcRear:i[1]}}}var KE=new WeakMap;function q6(e,t,r,n){let o=KE.get(e);o||(o=new Map,KE.set(e,o));let a=`${tv(r)}|${n[0]}|${n[1]}`,s=o.get(a);if(!s){o.size>=4&&o.clear();try{s=HE(OE(e,r),n)}catch{s=t.rigidMigration(n)}o.set(a,s)}return s}function Q6(e){let t=BE.get(e);if(t)return t;let r=pr(e),n=jn(r,{heave:0,pitch:0,roll:0,steer:0}),o=VE(e.front),a=VE(e.rear),s={wheelbase:e.config.wheelbase,trackFront:qt(e.front),trackRear:qt(e.rear),mrFront:o.motionRatio,mrRear:a.motionRatio,wheelRateFront:o.wheelRate,wheelRateRear:a.wheelRate,unsprungCgHeight:e.front.config.loadedRadius,rcHeightFront:n.front.valid?n.front.heightAboveGround:0,rcHeightRear:n.rear.valid?n.rear.heightAboveGround:0,rcGainFront:Xs(n.front),rcGainRear:Xs(n.rear),rigidMigration:i=>HE(r,i),kinFront:Pu(()=>Ps(e.front)),kinRear:Pu(()=>Ps(e.rear))};return BE.set(e,s),s}function zE(e,t,r,n){let o=Q6(e),a=ul(e,t),s=Qs(e,t),i=lw(e,t),c=Ld(e,t),l=uw(e,t),u=mw(t),d=Dd(e,t),p=So(e.front),m=So(e.rear),f=ma(t.damperModel,t.damperSetup,o.mrFront,o.mrRear,t.damperModelRear??t.damperModel),h={rho:t.rho.value,area:t.A.value,cl:t.c_l.value,cw:t.c_w.value,copLongFront:1-Math.max(0,Math.min(1,ee(t,"cop_long"))),copHeight:ee(t,"cop_height"),...t.aeroModel?{model:t.aeroModel}:{},rideHeightFront:ee(t,"ride_height_front"),rideHeightRear:ee(t,"ride_height_rear")},b=9.81,g=X6(t.front_mass_diss.value),y=ha(t,r,n),x=Ke(y.front),v=y.rear===y.front?x:Ke(y.rear),k=n??t.tireModelRear??r,R=t.m.value*b*g/2,M=t.m.value*b*(1-g)/2,S=x.corneringStiffness(R),w=v.corneringStiffness(M),F=(r?x.verticalStiffness():0)||ee(t,"tire_vertical_rate"),T=(k?v.verticalStiffness():0)||ee(t,"tire_vertical_rate"),A=on(r)??0,C=on(k)??0,P=Od({freeRadius:A,staticLoad:R,tyreRate:F,surveyed:e.front.config.loadedRadius},{freeRadius:C,staticLoad:M,tyreRate:T,surveyed:e.rear.config.loadedRadius},g),L=Mr(A,R,F,e.front.config.loadedRadius),E=Mr(C,M,T,e.rear.config.loadedRadius),_=[Un(o.rcHeightFront,o.rcGainFront,e.front.config.loadedRadius,L),Un(o.rcHeightRear,o.rcGainRear,e.rear.config.loadedRadius,E)],D=Pu(()=>dl(o.kinFront(),ee(t,"camber_front_deg"))),I=Pu(()=>dl(o.kinRear(),ee(t,"camber_rear_deg"))),V=Pu(()=>q6(e,o,Ci(z),_)),O=$c({...t,wheelbase:{...t.wheelbase,value:o.wheelbase}}),B=ml(t),z={massTotal:t.m.value,frontMassFrac:g,steeringSystem:t.steeringSystem,tv:bd(t),cgHeight:Zs(ee(t,"cg_height"),t.cgReference?.standingRadius,P),cgStandingRadius:P,wheelbase:o.wheelbase,trackFront:o.trackFront,trackRear:o.trackRear,wheelRateFront:p?0:o.wheelRateFront,wheelRateRear:m?0:o.wheelRateRear,decoupledFront:p,decoupledRear:m,...u.front?{elementLinkagesFront:u.front}:{},...u.rear?{elementLinkagesRear:u.rear}:{},...d.front.source==="part"?{cornerCoiloverFront:d.front.coilover}:{},...d.rear.source==="part"?{cornerCoiloverRear:d.rear.coilover}:{},...d.heaveFront.coilover?{heaveCoiloverFront:d.heaveFront.coilover}:{},...d.heaveRear.coilover?{heaveCoiloverRear:d.heaveRear.coilover}:{},...i.front&&!p?{heaveSeatFront:i.front}:{},...i.rear&&!m?{heaveSeatRear:i.rear}:{},...d.rollFront.coilover?{rollCoiloverFront:d.rollFront.coilover}:{},...d.rollRear.coilover?{rollCoiloverRear:d.rollRear.coilover}:{},tireRate:F,...T!==F?{tireRateRear:T}:{},tireDamping:ee(t,"tire_vertical_damping"),arbFront:a.front??ee(t,"arb_front"),arbRear:a.rear??ee(t,"arb_rear"),brakeBalanceFront:O.balanceFront,brakes:O,...B?{driveline:B}:{},heaveSpringFront:s.front??ee(t,"heave_spring_front"),heaveSpringRear:s.rear??ee(t,"heave_spring_rear"),unsprungPerCorner:ee(t,"unsprung_mass"),unsprungCgHeight:Mr(A,R,F,o.unsprungCgHeight),tyreFreeRadius:A,...C!==A?{tyreFreeRadiusRear:C}:{},rcHeightFront:_[0],rcHeightRear:_[1],corneringStiffnessFront:S,corneringStiffnessRear:w,get kinFront(){return D()},get kinRear(){return I()},damperFront:p?0:f?.front?.rate??ee(t,"damper_front")*o.mrFront*o.mrFront,damperRear:m?0:f?.rear?.rate??ee(t,"damper_rear")*o.mrRear*o.mrRear,...f?.front&&!p?{damperCurveFront:f.front.curve}:{},...f?.rear&&!m?{damperCurveRear:f.rear.curve}:{},heaveDamperFront:l.heaveFront?.rate??c.heaveFront,heaveDamperRear:l.heaveRear?.rate??c.heaveRear,rollDamperFront:l.rollFront?.rate??c.rollFront,rollDamperRear:l.rollRear?.rate??c.rollRear,...l.heaveFront?{heaveDamperCurveFront:l.heaveFront.curve}:{},...l.heaveRear?{heaveDamperCurveRear:l.heaveRear.curve}:{},...l.rollFront?{rollDamperCurveFront:l.rollFront.curve}:{},...l.rollRear?{rollDamperCurveRear:l.rollRear.curve}:{},unsprungCornerMass:ee(t,"unsprung_mass"),get rollCentreCurve(){return V().roll},get rcHeaveCurve(){return V().heave},aero:h,yawInertia:ee(t,"I_yaw"),rollInertia:ee(t,"I_roll"),pitchInertia:ee(t,"I_pitch"),...ua(t)?{chassisTorsion:ua(t)}:{},...Zc(t,"front")?{twistInertiaFront:Zc(t,"front")}:{},...Zc(t,"rear")?{twistInertiaRear:Zc(t,"rear")}:{},get steerFront(){return Ed(e.front,L)},ackermannPct:ee(t,"ackermann_pct"),toeFrontDeg:ee(t,"toe_front_deg"),toeRearDeg:ee(t,"toe_rear_deg")};return z}var WE=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}),ov={ggvMode:"twoTrack"},YE=new WeakMap;function av(e,t=ov){let r=YE.get(e.vehicle);r||YE.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={...WE(e.params),suspensionOf:()=>e.vehicle};n.set(o,a=qa(e.params,s,t))}return a}var jE=(e=ov)=>t=>av(t,e),mh=(e=ov)=>t=>zE(t.vehicle,D1(t.params,WE(t.params),e),t.params.tireModel,t.params.tireModelRear);function Z6(e,t){return av(e,t.switches)}var sv=e=>gr(e?.rulesets);function UE(e,t,r,n,o={},a=()=>r.standingStart){let s=av(n,r.switches),i=(l,u)=>{let d=Cp(l,t,{racingLine:r.racingLine,params:s});return{asset:d.asset,numerics:d.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 XE=e=>[...new Set(e.lap.courses.flatMap(t=>t.course.kind==="track"?[t.course.trackId]:[]))],qE=e=>{let t=e?.session;return t?{sessionParams:r=>Z6(r,t),session:()=>t}:{}},Du=e=>({metrics:sv(e),assemble:mh(e?.switches),simParams:jE(e?.switches),projectTrack:()=>e?.course??null,libraryTrack:t=>e?.tracks?.[t]??null,numerics:e?.numerics,...qE(e)}),J6=(e,t)=>({density:e.density,envelope:e.envelope,states:e.states,operating:e.operating,assemble:mh(t)}),eY=(e,t)=>({...J6(e,t?.switches),lap:e.lap,simParams:jE(t?.switches),projectTrack:()=>t?.course??null,libraryTrack:r=>t?.tracks?.[r]??null,numerics:t?.numerics,...qE(t)}),QE="nelder-mead",ZE=600,Lu=[0,.15,.15];function JE(e,t,r,n=Lu.length){let o=lv(t);return Lu.slice(0,Math.max(1,n)).map((a,s)=>({...e,seed:s+1,startJitter:a,car:o,...r?{lap:r}:{}}))}function eI(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 tI(e,t,r,n,o=.01){let a=sv(n).byId;return tY(e,t,r,n).filter(s=>s.excess>-o*(a[s.metricId]?.scale??1))}function tY(e,t,r,n){let o;try{o=Do(Ni(e,t,r),eY(t,n))}catch{return[]}return rY(o,t,sv(n))}function rY(e,t,r){let n=[];for(let o of t.constraints){let a=r.byId[o.metricId];if(!a)continue;let s=Rt(e,a,o.at);if(!Number.isFinite(s))continue;let i=`${ht(a)}${Wa(o.at,a)}`;n.push({key:o.key,metricId:o.metricId,label:i,unit:a.unit==="-"?"":a.unit,value:s,excess:_o(o,s)})}return n}var nY=.05;function oY(e,t){if(t.id.startsWith("hp.")||Kf(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 c1(Io(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 a1(oo(o.hardpoints,n[2]),n[3],1)}function rI(e,t,r){let n=r.filter(p=>p.score.feasible);if(n.length<2)return null;let o=t.map(p=>oY(e,p)),a=o.every(p=>p!==null)?"mm":null,s=0,i="",c=0,l=n.reduce((p,m)=>m.score.total<p.score.total?m:p);for(let p of n)if(p!==l)for(let m=0;m<t.length;m++){let f=Math.abs(p.x[m]-l.x[m])*(o[m]??1);c+=f*f,f>s&&(s=f,i=t[m].name)}let u=n.map(p=>p.score.total),d=l.score.terms.reduce((p,m)=>p+(m.resolution??0),0);return{distance:Math.sqrt(c),worst:s,worstName:i,scoreSpread:Math.max(...u)-Math.min(...u),tolerance:Math.max(nY,d),unit:a}}var aY={steeringSystem:!0,brakeSetup:!0,driveline:!0,heaveFrontDesign:!0,heaveRearDesign:!0,arbFrontDesign:!0,arbRearDesign:!0},nI=e=>Object.hasOwn(aY,e);function nv(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 sY(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":nI(t)||nv(e)?"block":null}function iv(e,t){t=Bt(e,t);let r=bt(e);return[...t.variables,...t.followers??[]].filter(n=>r[n.id]&&!r[n.id].supersededBy&&!sY(n.id)).map(n=>ut(r[n.id]))}function dh(e,t,r){t=Bt(e,t);let n=bt(e),o=Ni(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),[d,p,m,f]=c.id.split(".");if(d==="rocker"){let h=`${p}.rocker`;if(i.has(h))continue;i.add(h);let b=p==="front"?o.vehicle.front:o.vehicle.rear;for(let g of[vn.fore,vn.aft]){let y=b.hardpoints[g];for(let x=0;x<3;x++)a.push({kind:"hardpoint",axle:p,key:g,axis:x,value:y[x]})}}else if(d==="arm"){let h=`${p}.${m}`;if(i.has(h))continue;i.add(h);let b=p==="front"?o.vehicle.front:o.vehicle.rear,g=yr[m];for(let y of[g.fore,g.aft]){let x=b.hardpoints[y];for(let v=0;v<3;v++)a.push({kind:"hardpoint",axle:p,key:y,axis:v,value:x[v]})}}else if(d==="hp"&&Cr(c.id)){let h=`${p}.${m}`;if(i.has(h))continue;i.add(h);let b=(p==="front"?o.vehicle.front:o.vehicle.rear).hardpoints[m];for(let g=0;g<3;g++)a.push({kind:"hardpoint",axle:p,key:m,axis:g,value:b[g]})}else if(d==="hp")a.push({kind:"hardpoint",axle:p,key:m,axis:"xyz".indexOf(f),value:u});else if(d==="cfg")a.push({kind:"config",axle:p,field:m,value:u});else if(d==="kc"){if(s.has(`kc.${p}`))continue;s.add(`kc.${p}`);let h=p==="front"?o.vehicle.front:o.vehicle.rear;a.push({kind:"compliance",axle:p,value:h.compliance})}else if(d==="param")a.push({kind:"param",label:ut(l),value:u});else if(d==="brakeModel"){if(s.has(d))continue;if(s.add(d),!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(nI(d)||nv(c.id)){let h=nv(c.id)??d;if(s.has(h))continue;s.add(h);let b=o.params[h];if(!b)throw new Error(`optimiser: "${c.id}" left the car with no ${h} to adopt`);a.push({kind:"block",key:h,value:b})}else throw new Error(`optimiser: Adopt has no way to write "${c.id}" back into the project`)}return a}function cv(e){let t=performance.now(),r=Du(e.lap),n=e.follow?x1(e.car,e.spec,r):e.spec,{dead:o,unprobed:a,...s}=M1(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 oI(e){let t=performance.now();return{tolerance:G1(e.car,e.spec,e.x,Du(e.lap),e.mm),elapsedMs:performance.now()-t}}var lv=e=>e.vehicle.chassis?{...e,vehicle:K1(e.vehicle)}:e;function aI(e,t){try{let r=uv(e.car,e.spec,e.lap),n=Es.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:Vr(r.variables),score:In(r,Vr(r.variables)),infeasible:0}});let o=e.from,a=o?{...r,variables:r.variables.map((u,d)=>({...u,start:Number.isFinite(o[d])?o[d]: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&&d1(r.variables)?f1(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 uv=(e,t,r)=>ja(e,t,Du(r));function sI(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),...rl(e,t.damper)}}function iI(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}:{}},...Ca(n)?{sessionAir:!0}:{}}}var ph=e=>({ggvMode:e.ggvMode,quasiTransient:e.quasiTransient===!0&&e.ggvMode!=="fast",motorThermal:e.motorThermal===!0,...FD({brakeFade:e.brakeFade===!0,airTempC:e.airTempC,diffYaw:e.diffYaw===!0,...e.air?{air:e.air}:{}})});function iY(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 cI(e,t){let r=t.plannedPath!==void 0,n=iY(t);return{...UE(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 ts(e,t){let r=e.vehicles.find(o=>o.id===t);if(!r)throw new Error(`this project holds no vehicle "${t}"`);let n=Xa(e);return iI(structuredClone(L1(e,r.params)),structuredClone(r.params),sI(r.params,n),ao(e).air)}var cY="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 mv(e,t,r,n){if(e.settings.pathPlanId)throw new Error(cY);let o=ao(e),a=e.tracks.length?(await Xf(e,t)).asset:null,s={};for(let i of n?XE(n):[]){let c=e.tracks.find(l=>l.id===i);c&&(s[i]=await Cu(c,t))}return cI(r,{track:a,numerics:o.numerics,racingLine:o.racingLine,standingStart:o.standingStart,lapCounts:o.lapCounts??{},switches:ph(o),rulesets:e.rulesets??[],library:s,standingOf:i=>e.tracks.find(c=>c.id===i)?.standingStart===!0})}async function lI(e,t,r,n){let o=ts(e,r),a=Bt(o,n),s=await mv(e,t,o,a);return cv({id:0,car:o,spec:a,lap:s})}async function uI(e,t,r,n){let o=ts(e,r),a=Bt(o,n),s=iv(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 mv(e,t,o,a)}catch(l){return{problems:[l instanceof Error?l.message:String(l)]}}let c=k1(o,a,{...Du(i),metrics:gr(e.rulesets)});return c.length?{problems:c}:{problems:[],msPerEval:cv({id:0,car:o,spec:a,lap:i}).msPerEval,carFingerprint:Ma(lv(o))}}async function lY(e,t,r,n,o,a=[]){let s=JE(t,e,r,n),i=s.length*t.budget,c=null,l=[];for(let[u,d]of s.entries()){if(a.includes(d.seed))continue;await o?.tick();let p=[],m=null,f=null;if(aI(d,y=>{y.kind==="progress"?(p.push([y.progress.evaluations,y.progress.score.total]),y.progress.evaluations===0&&(c??=y.progress.score),o?.progress(u*t.budget+y.progress.evaluations,i)):y.kind==="done"?m={result:y.result,elapsedMs:y.elapsedMs}:f=y.message}),f)throw new Error(f);if(!m)throw new Error("the search stopped without a result");let{result:h,elapsedMs:b}=m,g={seed:d.seed,startJitter:d.startJitter,x:h.x,score:h.score,evaluations:h.evaluations,infeasible:h.infeasible,history:h.history,trace:p,elapsedMs:b,...h.snapped?{snapped:h.snapped}:{}};l.push(g),o?.progress((u+1)*t.budget,i),await o?.finished?.(g)}if(!c)throw new Error("the search never scored the starting design");return{method:t.method,budget:t.budget,designScore:c,runs:l}}async function mI(e,t,r,n){let o=ts(e,r.vehicleId),a=Bt(o,r.spec),s=iv(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 mv(e,t,o,a),c=r.method??QE;if(!Es.some(x=>x.name===c))throw new Error(`unknown method "${c}" \u2014 it is one of ${Es.map(x=>x.name).join(", ")}`);let l=r.budget??ZE,u=Math.max(1,Math.min(r.seeds??Lu.length,Lu.length)),d=await lY(o,{spec:a,method:c,budget:l},i,u,n),p=uv(o,a,i),m=d.runs.map(x=>({seed:x.seed,startScore:d.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:eI(p.variables,x.x),constraints:tI(o,a,x.x,i),...x.snapped?{onSteps:{x:x.snapped.x,score:x.snapped.score.total,feasible:x.snapped.score.feasible,...x.snapped.score.reason?{reason:x.snapped.score.reason}:{},terms:x.snapped.score.terms}}:{}})),f=d.runs.reduce((x,v)=>Fc(v.score,x.score)?v:x),h=f.snapped?.score.feasible?f.snapped:null,b=h?h.x:f.x,g=r.tolerance??eh,y=f.score.feasible&&g>0?oI({id:0,car:o,spec:a,x:b,lap:i,mm:g}).tolerance:null;return{method:c,budget:l,seeds:m,spread:d.runs.length>1?rI(o,p.variables,d.runs.map(x=>({x:x.x,score:x.score}))):null,writes:dh(o,a,b),...f.snapped?{adopts:h?"on its steps":`as found: on its steps it breaks a hold (${f.snapped.score.reason??"not legal"})`}:{},...y?{asBuilt:y}:{}}}var uY=(e,t)=>e[t]??[],mY=(e,t,r)=>r<=1?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function fh(e){return e.kind==="param"?mY(e.start,e.end,Math.max(1,Math.round(e.steps))):e.kind==="part"?[...e.partIds]:[...e.values]}var dI=e=>e.kind==="param"?e.label:e.kind==="part"?`${e.part} model`:e.setting;function dY(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=qa(structuredClone(r.params),Xa(e),ao(e)),o=Pw(n,{geometry:!0}),a=$d(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=To.find(l=>l.doc===i.part);if(!c)throw new Error(`"${i.part}" is not a library \u2014 it is one of ${To.map(l=>l.doc).join(", ")}`);for(let l of i.partIds)if(!uY(e,c.doc).some(u=>u.id===l))throw new Error(`the ${c.label} library holds no "${l}"`)}}if(t.holdBalance){let i=a.find(l=>l.key==="arb_front");if(t.axes.find(l=>l.kind==="param"&&l.label===i?.label))throw new Error(`holding the balance moves "${i.label}": it cannot also be an axis`)}let s=t.axes.reduce((i,c)=>i*fh(c).length,1)+(t.priceInMass?pI:0);if(s>Fp)throw new Error(`that grid is ${s} runs, over the ${Fp} cap \u2014 a run is a whole session. Drop an axis or use fewer steps.`)}var pI=3,fI=(e,t)=>({...zf(),variables:[{id:e,lo:0,hi:2*t}]});function pY(e,t){let r=ts(e,t.vehicleId),n=Qf(r);if("why"in n)throw new Error(`the balance cannot be held: ${n.why}`);let o=mh(ph(ao(e,t.settings))),a=Zf(ja(r,fI(n.id,n.now),{assemble:o}),gr(e.rulesets));if("why"in a)throw new Error(`the balance cannot be held: ${a.why}`);return{target:a.target,metric:a.metric,assemble:o,bar:ut(n.def),unit:n.def.unit,now:n.now}}function fY(e,t,r){let n=ts(e,t),o=Qf(n);if("why"in o)return{value:NaN,balance:NaN,reached:!1};let a=fI(o.id,o.now),{x:s,held:i}=Jf(ja(n,a,{assemble:r.assemble}),[o.now],{slot:0,target:r.target,metric:r.metric}),c=e.vehicles.find(l=>l.id===t).params;for(let l of dh(n,a,s))if(l.kind==="param")Js(c,l.label,l.value);else if(l.kind==="block")Object.assign(c,{[l.key]:structuredClone(l.value)});else throw new Error(`a held balance has no way to write ${l.kind} back into the car`);return{value:i.value,balance:i.balance,reached:i.reached}}var hI=e=>e.map(t=>String(typeof t=="number"?Number(t.toPrecision(4)):t)).join(" \xD7 ");function hY(e,t){let r=[...new Set(e.flatMap(o=>(o.didNotFinish??[]).map(a=>a.label)))],n=e.map(o=>({name:hI(o.at),events:r.map(a=>({label:a,incomplete:o.didNotFinish?.find(s=>s.label===a)}))}));return ED(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`:_1(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 bY(e){let t=[[]];for(let r of e){let n=fh(r),o=[];for(let a of n)for(let s of t)o.push([...s,a]);t=o}return t}async function bI(e,t,r,n){dY(e,r);let o=bY(r.axes),a=o.length+(r.priceInMass?pI:0),s=r.holdBalance?pY(e,r):null,i=[],c=!1,l=0,u=async(h,b={})=>{let g=structuredClone(e),y=g.vehicles.find(F=>F.id===r.vehicleId),x={...r.settings},v={...b};h&&r.axes.forEach((F,T)=>{let A=h[T];if(F.kind==="param")v[F.label]=A;else if(F.kind==="part"){let C=To.find(P=>P.doc===F.part);y.params[C.ref]=A}else x[F.setting]=A}),Object.keys(v).length&&(y.params=I1(y.params,v));let k=s?fY(g,r.vehicleId,s):void 0,R=r.fleet?g.vehicles.filter(F=>F.visible||F.id===r.vehicleId).map(F=>F.id):[r.vehicleId],M=await qf(g,t,{vehicleIds:R,settings:x});c=M.fleetScored;let S=M.vehicles.find(F=>F.id===r.vehicleId),w=S.events.flatMap(F=>F.incomplete?[{label:F.label,...F.incomplete}]:[]);return n?.(++l,a),{at:h??[],metrics:S.metrics,...w.length?{didNotFinish:w}:{},...k?{held:k}:{}}};for(let h of o)i.push(await u(h));let d;if(r.priceInMass){let h=ts(e,r.vehicleId),b=bt(h)[V1],g=b.read(h),y=B1*g,x=ut(b),v=await u(null),k=await u(null,{[x]:g+y}),R=await u(null,{[x]:g-y}),M=Object.fromEntries(Object.keys(v.metrics).map(S=>[S,(k.metrics[S]-R.metrics[S])/(2*y)]));d={car:v.metrics,perKg:M,dKg:y};for(let S of i)S.asKg=Object.fromEntries(Object.keys(S.metrics).map(w=>[w,$1(S.metrics[w],v.metrics[w],M[w])]))}let p=Object.keys(i[0]?.metrics??{}),m=[];r.axes.forEach((h,b)=>{if(fh(h).length<2)return;p.some(y=>{if(new Set(i.map(k=>`${k.at[b]}`)).size<2)return!1;let v=i.map(k=>k.metrics[y]).filter(Number.isFinite);return Math.max(...v)-Math.min(...v)>1e-9})||m.push(dI(h))});let f=[];if(c&&!r.fleet&&f.push("Points here were scored with this car alone, so it takes the maximum in every event and the points axis is flat by construction. Re-run with fleet: true to price a change in points."),f.push(...hY(i,c)),s&&ao(e,r.settings).ggvMode==="fast"&&f.push("The fast envelope is a point mass: no balance reaches its laps, so a held sweep runs the same laps as a loose one. Hold it on the full envelope (settings.ggvMode)."),s){let h=i.filter(b=>b.held&&!b.held.reached).map(b=>hI(b.at));h.length&&f.push(`No ${s.bar} between 0 and twice the car's holds TLLTD at ${s.target.toFixed(2)} % at ${_1(h.length>6?[...h.slice(0,6),"\u2026"]:h)}: those points ran with the bar at the end nearer it, so their balance is not the car's.`)}return d&&f.push(`As mass: each point's change from the car as it is, over what 1 kg moves it, read at \xB1${d.dKg.toFixed(1)} kg. Negative is as much as taking that many kilograms off. A metric the mass hardly moves prices at nonsense: read the lap and event times.`),m.length&&f.push(`Nothing moved along ${m.join(", ")}. Exactly zero is a wiring question before it is a finding: check that a library part is not superseding the value, and that the switch it needs is on.`),{axes:r.axes.map(h=>({kind:h.kind,label:dI(h),values:fh(h)})),runs:i,metricKeys:p,fleetScored:c,flat:m,caveats:f,...s?{hold:{bar:s.bar,unit:s.unit,now:s.now,tlltdPct:s.target}}:{},...d?{price:d}:{}}}function yI(){if(typeof process.threadCpuUsage!="function")return performance.now();let e=process.threadCpuUsage();return(e.user+e.system)/1e3}async function yY(e,t){let r=AD(e.root);switch(e.kind){case"sweep":return bI(e.doc,r,e.req,t);case"convergence":return ID(e.doc,r,{vehicleId:e.vehicleId,...e.steps?{steps:e.steps}:{},...e.tolPct!==void 0?{tolPct:e.tolPct}:{},onStep:t});case"study":return mI(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 qf(e.doc,r,{...e.vehicleIds?{vehicleIds:e.vehicleIds}:{},...e.settings?{settings:e.settings}:{},...e.overrides?{overrides:e.overrides}:{}});case"probe":return lI(e.doc,r,e.vehicleId,e.spec);case"quote":return uI(e.doc,r,e.vehicleId,e.spec)}}if(gI){let e=gI,t=r=>e.postMessage(r);(async()=>{try{let r=await yY(gY,(n,o)=>t({type:"progress",done:n,total:o}));t({type:"done",result:r,cpuMs:yI()})}catch(r){t({type:"failed",message:r instanceof Error?r.message:String(r),cpuMs:yI()})}})()}export{yY as runJob,yI as threadCpuMs};
|