# `Circle`

A centre and a radius on the ground, the radius never below 0: shown `1,000 m around 51.5072° N, 0.1276° W`.

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

## Make one

Build one from its fields, `Circle { centre: ...  radius: ... }`.

## Fields

| Field | Type |
|---|---|
| `centre` | [`Point`](type-point.md) |
| `radius` | [`Length`](type-length.md) |

## Text, JSON and storage

It has no single text form, so `text.from` and `text.parse` don't take it. JSON sends an object of its parts.

| JSON |
|---|
| `{"centre":{"type":"Point","coordinates":[-0.1276,51.5072]},"radius":{"value":"1000","unit":"metre"}}` |
| `{"centre":{"type":"Point","coordinates":[0,0]},"radius":{"value":"0","unit":"metre"}}` |

It is stored in 2 columns, each named for the field, `_` and its suffix. This is `{"centre":{"type":"Point","coordinates":[0,0]},"radius":{"value":"0","unit":"metre"}}`:

| Column | Type | Holds |
|---|---|---|
| `<field>_centre` | `geography` | `'SRID=4326;POINT (0 0)'::geography` |
| `<field>_radius` | `numeric(38, 6)` | `0` |

## Shown to people

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

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `{"centre":{"type":"Point","coordinates":[-0.1276,51.5072]},"radius":{"value":"1000","unit":"metre"}}` | `1,000 m around 51.5072° N, 0.1276° W` |
| `{"centre":{"type":"Point","coordinates":[0,0]},"radius":{"value":"0","unit":"metre"}}` | `0 m around 0°, 0°` |

## Operations

- `geo.contains(a: T, b: U) -> Bool`: Whether no point of `b` lies outside `a`, edges included. `a` may be a `BoundingBox`, whose sides are compared directly, or a `Circle`, holding the points within its radius of its centre.
- `geo.within(a: T, b: U, distance: Length?) -> Bool`: `geo.contains(b, a)`; or, with `distance:`, whether two points are at most that far apart, as `geo.distance` measures them.

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