From 3e2153b39c60bfc2c40093f21949516a2174623b Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Fri, 22 May 2026 23:52:21 -0400 Subject: [PATCH] zenno/lib: rearrange parameters in race.speedGain --- zenno/src/lib/race.ts | 14 +++++++------- zenno/src/routes/mspeed/+page.svelte | 10 +++++----- zenno/src/routes/mspeed/SpeedDur.svelte | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/zenno/src/lib/race.ts b/zenno/src/lib/race.ts index 969b3cb..d5f0793 100644 --- a/zenno/src/lib/race.ts +++ b/zenno/src/lib/race.ts @@ -270,24 +270,24 @@ export function skillDuration(baseDur: number, raceLen: number): number { * Calculate the distance gained from a target speed boost, including * acceleration to the boosted target speed and deceleration back to baseline. * @param speedBonus Difference between baseline and boosted speed in m/s - * @param accel Current acceleration value in m/s² - * @param decel Current phase-based deceleration value in m/s², a negative value. + * @param accel Current acceleration value in m/s², or null for instant acceleration + * @param decel Current phase-based deceleration value in m/s², a negative value; or null for instant deceleration * @param dur Duration of the boosted speed * @returns Distance gained from the speed boost in m */ -export function speedGain(speedBonus: number, accel: number, decel: number, dur: number): number { +export function speedGain(speedBonus: number, dur: number, accel: number | null, decel: number | null): number { // Actual effect of a target speed bonus looks like // speed: __/-----\__ // bonus: ====== // I.e., the speed bonus duration includes acceleration to the new speed // and does not include the acceleration back to baseline after it ends. - const accelTime = speedBonus / accel; - const decelTime = -speedBonus / decel; + const accelTime = accel !== null ? speedBonus / accel : 0; + const decelTime = decel !== null ? -speedBonus / decel : 0; if (accelTime >= dur) { // Acceleration is so low that the horse won't reach the boosted target // speed before the effect ends. E.g., G surface aptitude. - const peakSpeed = accel * dur; - return 0.5 * (peakSpeed * dur - peakSpeed / decel); + const peakSpeed = (accel ?? 0) * dur; + return 0.5 * (peakSpeed * dur - peakSpeed / (decel ?? 0)); } // speedBonus*(dur-accelTime) + speedBonus*accelTime/2 + speedBonus*decelTime/2 return speedBonus * (dur + 0.5 * (decelTime - accelTime)); diff --git a/zenno/src/routes/mspeed/+page.svelte b/zenno/src/routes/mspeed/+page.svelte index f936dee..61c277a 100644 --- a/zenno/src/routes/mspeed/+page.svelte +++ b/zenno/src/routes/mspeed/+page.svelte @@ -54,24 +54,24 @@ const ssY: Array = $derived([ { label: 'Aptitude S', - y: (x) => speedGain(spotStruggleSpeed(x), accel[0], decel[0], spotStruggleDuration(x, AptitudeLevel.S)) / HORSE_LENGTH, + y: (x) => speedGain(spotStruggleSpeed(x), spotStruggleDuration(x, AptitudeLevel.S), accel[0], decel[0]) / HORSE_LENGTH, }, { label: 'Aptitude A', - y: (x) => speedGain(spotStruggleSpeed(x), accel[0], decel[0], spotStruggleDuration(x, AptitudeLevel.A)) / HORSE_LENGTH, + y: (x) => speedGain(spotStruggleSpeed(x), spotStruggleDuration(x, AptitudeLevel.A), accel[0], decel[0]) / HORSE_LENGTH, }, frontApt < AptitudeLevel.A ? { label: `Aptitude ${AptitudeLevel[frontApt]}`, - y: (x) => speedGain(spotStruggleSpeed(x), accel[0], decel[0], spotStruggleDuration(x, frontApt)) / HORSE_LENGTH, + y: (x) => speedGain(spotStruggleSpeed(x), spotStruggleDuration(x, frontApt), accel[0], decel[0]) / HORSE_LENGTH, } : null, ]); const lcY: Array = $derived([ - { label: 'Ideal Lane Combo', y: (x) => speedGain(moveLaneModifier(x), accel[0], decel[0], lcDur) / HORSE_LENGTH }, + { label: 'Ideal Lane Combo', y: (x) => speedGain(moveLaneModifier(x), lcDur, accel[0], decel[0]) / HORSE_LENGTH }, ]); const yRule: HorizontalRule[] = $derived([ - { y: speedGain(0.35, accel[1], decel[1], skillDuration(2.4, raceLen)) / HORSE_LENGTH, label: 'Professor of Curvature' }, + { y: speedGain(0.35, skillDuration(2.4, raceLen), accel[1], decel[1]) / HORSE_LENGTH, label: 'Professor of Curvature' }, ]); diff --git a/zenno/src/routes/mspeed/SpeedDur.svelte b/zenno/src/routes/mspeed/SpeedDur.svelte index 4312b75..a8e2e4f 100644 --- a/zenno/src/routes/mspeed/SpeedDur.svelte +++ b/zenno/src/routes/mspeed/SpeedDur.svelte @@ -17,7 +17,7 @@ const { children, speed, dur, accel, decel }: Props = $props(); const decels = $derived([decel].flat(1)); - const gain = $derived(decels.map((d) => speedGain(speed, accel, d, dur) / HORSE_LENGTH)); + const gain = $derived(decels.map((d) => speedGain(speed, dur, accel, d) / HORSE_LENGTH)); const text = $derived(gain.map(fmtp).join(' – '));