# Functions

Import these from `@grafloria/engine`.

## Functions

### `bumpMutationEpoch`

Bump the epoch by hand, for a mutation that legitimately bypasses
`markDirty()` (in-place `points` rewrites, say). Prefer `markDirty()`.

```ts
function bumpMutationEpoch(): number
```

### `distanceToSegment`

Distance from `p` to the segment `a`→`b`. The primitive both hit-tests are built on.

```ts
function distanceToSegment(p: Point, a: Point, b: Point): number
```

### `getMutationEpoch`

Read the current mutation epoch. Cheap enough to call every frame.

```ts
function getMutationEpoch(): number
```

### `hasPressure`

True when the device gave us pressure worth keeping (i.e. it actually varies).

```ts
function hasPressure(points: readonly StrokePoint[]): boolean
```

### `linkLabelPosition`

The position along the path (0-1) a label resolves to.

`slot` WINS over `position`. Naming a slot is an explicit act; `position` is a
required field that most slot users only fill in to satisfy the type, so
letting it win would make `slot` silently do nothing.

```ts
function linkLabelPosition(
  label: Pick<LinkLabel, 'position' | 'slot'>
): number
```

### `segmentDistance`

Minimum distance between two SEGMENTS.

The eraser needs this and a point-test cannot replace it. A pointermove at 60Hz over
a fast flick lands samples 80px apart; testing only the sample POINTS lets the
eraser jump clean over a stroke it visibly swept through. So the eraser tests the
segment it travelled, not the points it happened to land on.

```ts
function segmentDistance(a1: Point, a2: Point, b1: Point, b2: Point): number
```
