# Turnout

The points, and the fact that a route is a state rather than a setting: two blades on one throw bar, and what decides where a train goes is detection — so a turnout caught in mid stroke has no route set at all.

> For the complete index, see [llms.txt](https://robocn.dev/llms.txt). A Markdown version of any page is available by appending `.md` to its URL or by sending an `Accept: text/markdown` header.

## Install

```bash
bunx --bun shadcn@latest add https://robocn.dev/r/rail-turnout.json
```

Registry item: `rail-turnout` · [`https://robocn.dev/r/rail-turnout.json`](https://robocn.dev/r/rail-turnout.json)

## Notes

- Solved: the geometry, from `turnoutGeometry()` and `bladePose()`. The number fixes the crossing angle at `atan(1/N)`; the crossing is where the inner rails actually meet, which fixes the radius and the lead; and the two blades share a rod, so the open gap is exactly the throw less the closed one.
- The route is detection, not a flag: `onRouteChange` fires when the closed blade comes inside its tolerance, and a turnout held in mid stroke reports `"unset"` and lights nothing. That is the state a signaller sees.
- Drawn to scale, which is why a bigger number comes out as a longer, flatter machine — a real turnout is a long shallow thing, and the frame is refitted per number rather than the geometry being squashed.
- Illustrated: rail sections, the check rails' own geometry and the point machine's internals. No locking, no interlocking, no forces, and nothing runs over it.

## Usage

```tsx
import { RailTurnout } from "@/components/ui/rail-turnout"

<RailTurnout behavior="route" />

// The number is the whole geometry, and it is drawn to scale.
<RailTurnout number={10} throwPosition={1} />
<RailTurnout hand="left" interactive onRouteChange={setRoute} />
```

## Props

| name | type | default | description |
| --- | --- | --- | --- |
| `view` | `"plan" | "front" | "profile" | "iso"` | `"plan"` | Where the camera stands. One turnout, four projections: straight down, straight on, side elevation, or three-quarter from above. |
| `throwPosition` | `number` | — | Blade position, 0 normal to 1 reverse. Supplying it stops the loop. |
| `onThrowChange` | `(position: number) => void` | — | The blades, while a person is working them. |
| `onRouteChange` | `(route: "normal" | "reverse" | "unset") => void` | — | Fires when detection makes or breaks — which is when the route really changes, rather than on every frame the blades move. |
| `behavior` | `"route" | "creep" | "static"` | `"route"` | Set, dwell, throw, dwell; or working the blade around the point of detection, where a machine that cannot quite make its route spends its time. |
| `number` | `number` | `5` | Turnout number: one across for N along, 3–12. Bigger is shallower, faster, and — because this is drawn to scale — visibly longer. |
| `hand` | `"left" | "right"` | `"right"` | Which way the diverging route goes. |
| `speed` | `number` | `0.28` | Point-machine cycles per second. |
| `animate` | `boolean` | `true` | Off parks the machine at phase and stops rendering. A reduced-motion preference does the same. |
| `paused` | `boolean` | `false` | Freeze where it stands. |
| `phase` | `number` | `0` | Seconds of offset, so a row of machines breaks step. |
| `interactive` | `boolean` | `false` | Press and drag across it to work the blades; arrows 10%, shift 25%, Home normal and End reverse. |
| `showSleepers` | `boolean` | `true` | The sleepers, which run out under the diverging route through the switch. |
| `active` | `boolean` | — | Light the route that is set and the detection lamp. Omit and it lights when detection is made. |
| `label` | `string` | — | Caption underneath the turnout. |
| `variant` | `"solid" | "outline" | "blueprint" | "wire"` | `"solid"` | How the machine is painted. Geometry never changes between variants. |
| `size` | `"xs" | "sm" | "md" | "lg" | "xl" | number` | `"md"` | Rendered width in pixels, or a step on the scale. |
| `color` | `string` | `var(--robot-shell)` | Body panels — the colour the machine reads as. |
| `accent` | `string` | `var(--robot-accent)` | Status colour: tip light, live tool, readouts. |
| `metal` | `string` | `var(--robot-metal)` | Bare machined parts: collars, bolts, tool bodies. |
| `dark` | `string` | `var(--robot-dark)` | Cast joints, base, shadow side. |
| `palette` | `Partial<RobotPalette>` | — | Override any subset of roles at once, including glow and grid. |

## Source

- `src/components/ui/rail-turnout.tsx`
