zenno/mspeed: calculator for front runner mechanical speed bonuses

This commit is contained in:
2026-05-22 19:08:23 -04:00
parent b720b325b3
commit 2a07f193ec
7 changed files with 433 additions and 7 deletions

View File

@@ -0,0 +1,33 @@
<script lang="ts">
import { HORSE_LENGTH, speedGain } from '$lib/race';
import type { Snippet } from 'svelte';
interface Props {
children: Snippet;
speed: number;
dur: number;
accel: number;
decel: number | number[];
}
function fmtp(x: number): string {
return x >= 0 ? '+' + x.toFixed(3) : x.toFixed(3);
}
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 text = $derived(gain.map(fmtp).join(' &ndash; '));
</script>
<div
class="m-2 flex h-full w-full max-w-80 flex-1 flex-col rounded-md border p-2 text-center shadow-sm transition-shadow hover:shadow-md"
>
<div class="block">{@render children()}</div>
<span class="block text-xl">{@html text} L</span>
<div class="flex flex-row">
<span class="flex-1 text-xs">{fmtp(speed)} m/s</span>
<span class="flex-1 text-xs">{dur.toFixed(3)} s</span>
</div>
</div>