# `Circle`

A centre and a distance around it.

Use it for "within 5 km of here", such as a delivery radius. For a drawn area, use [`Polygon`](/docs/types/type-polygon.md).

## Shape

| Field | Type | Required? |
|---|---|---|
| `centre` | [`Point`](/docs/types/type-point.md) | Yes |
| `radius` | [`Length`](/docs/types/type-length.md) | Yes |

## Example

```jadpo
Circle {
    centre: Point { latitude: 51.5072 longitude: -0.1276 altitude: none }
    radius: 1km
}
```

## Good to know

- The radius can't be below zero, and it is measured on the ground.
- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it, so sort by one of its parts instead.

## In JSON

An object of its parts, in a request, a response or `json.write`:

```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"}}
```

## Details

<details>
<summary>Text form, storage, how it is shown, and operations</summary>

`Circle` is in the group Geospatial, and has been in Jadpo since 0.1.0.

### Text form

It has no single text form, so `text.from` and `text.parse` don't take it.

### How it is stored

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` |

### How it is 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.

It also takes `text.format`, `json.read`, `json.write` and `==`. [How every standard type behaves](/docs/every-standard-type-meets-one-contract.md) says how they work.

</details>
