# `Bearing`

A compass direction, degrees clockwise from true north, from 0 to 360: `247.5`, shown `247.5°`.

[Geospatial](types.md#geospatial); ordered; since Jadpo 0.1.0.

## Make one

It is a `Decimal` with bounds of its own: build one as you build a `Decimal`, and a value outside its bounds breaks `min` or `max`.

`text.parse(raw, as: Bearing)` reads one from its text; text that isn't one at all fails `malformed`, such as `90°`, `N` or `1.5rad`.

This operation gives one: `geo.bearing`.

## Text, JSON and storage

`text.from` writes its canonical text, the one form `text.parse` reads back. JSON sends its canonical text as a string.

| Text | JSON |
|---|---|
| `0` | `"0"` |
| `90` | `"90"` |
| `247.5` | `"247.5"` |
| `359.9` | `"359.9"` |

It is stored in one column named for the field, of type `numeric`. `247.5` is stored as `247.5`.

## Shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `0` | `0°` |
| `90` | `90°` |
| `247.5` | `247.5°` |
| `359.9` | `359.9°` |

## Operations

- `geo.bearing(from: Point, to: Point) -> Bearing`: The direction the geodesic leaves `from` in, in degrees clockwise from true north, at least 0 and below 360, to 9 places. Two equal points have none: the call fails with `same_point`, which its `attempt` maps.

Like every standard type, it also has the contract's own operations: `text.parse`, `text.from`, `text.format`, `json.read`, `json.write` and `==`. It is ordered, so `<` and sorting take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
