# ViewSize

> Talos 0.7 · Since 0.6; changed in 0.7

`ctx.camera.viewSize`: the box an orthographic lens frames in the reference view, world units and pixels.

## Signature

```ts
export interface ViewSize {
  /** The box's centre to its left or right edge, world units: `halfHeight` × 16/9. */
  readonly halfWidth: number
  /** The box's centre to its top or bottom edge, world units: `orthoSize`, else 1080 / (2 × `pixelsPerUnit`), else 5. */
  readonly halfHeight: number
  /** The reference view the box is measured in: 1920 and 1080, whatever the window. */
  readonly pixelWidth: number
  readonly pixelHeight: number
}
```

Import: `import type { ViewSize } from "@argus/api"`

## Members

| Member | Signature | Description |
|---|---|---|
| `halfWidth` | `readonly halfWidth: number` | The box's centre to its left or right edge, world units: `halfHeight` × 16/9. |
| `halfHeight` | `readonly halfHeight: number` | The box's centre to its top or bottom edge, world units: `orthoSize`, else 1080 / (2 × `pixelsPerUnit`), else 5. |
| `pixelWidth` | `readonly pixelWidth: number` | The reference view the box is measured in: 1920 and 1080, whatever the window. |
| `pixelHeight` | `readonly pixelHeight: number` |  |

## Example

The tested fixture `fixtures/host/road-edges.ts`.

```ts
// A behavior that keeps a car inside the road's wall: what `ctx.world.road(id).edge(s)` is for.
import type { Behavior } from "@argus/api"

export default {
  update(ctx) {
    const road = ctx.world.road("track")
    if (road === null) return
    const here = road.closest(ctx.entity.position)
    const edge = road.edge(here.s)
    // Keep the car's centre a radius inside the wall's inner face, or the kerb's edge when there is no wall.
    const limit = (edge.barrier?.inner ?? edge.kerbOuter) - 0.8
    const over: number = Math.abs(here.offset) - limit
    const wallHeight: number | undefined = road.barrier?.heightM
    const sides: "left" | "right" | "both" | undefined = road.barrier?.sides
    const kerb: number = road.kerbWidth + road.kerbHeight
    ctx.state.over = [over, wallHeight, sides, kerb, edge.halfWidth, edge.barrier?.left, edge.barrier?.right, edge.barrier?.outer, edge.barrier?.height]
  },
} satisfies Behavior
```
