# `BoundingBox`

A rectangle on the map by its sides (RFC 7946's bounding box), named: its south at or below its north, and a west east of its east across the antimeridian.

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

## Make one

Build one from its fields, `BoundingBox { south: ...  west: ...  north: ... }`.

This operation gives one: `geo.bounding_box`.

Its parts keep these rules; a value that breaks one fails with the rule's name:

- `south_not_above_north`: `south <= north`

## Fields

| Field | Type |
|---|---|
| `south` | [`Latitude`](type-latitude.md) |
| `west` | [`Longitude`](type-longitude.md) |
| `north` | [`Latitude`](type-latitude.md) |
| `east` | [`Longitude`](type-longitude.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 |
|---|
| `{"south":"51.28","west":"-0.51","north":"51.69","east":"0.33"}` |
| `{"south":"-20","west":"170","north":"-10","east":"-170"}` |

It is stored in 4 columns, each named for the field, `_` and its suffix. This is `{"south":"-20","west":"170","north":"-10","east":"-170"}`:

| Column | Type | Holds |
|---|---|---|
| `<field>_south` | `numeric` | `-20` |
| `<field>_west` | `numeric` | `170` |
| `<field>_north` | `numeric` | `-10` |
| `<field>_east` | `numeric` | `-170` |

## Shown to people

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

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `{"south":"51.28","west":"-0.51","north":"51.69","east":"0.33"}` | `51.28° N, 0.51° W – 51.69° N, 0.33° E` |
| `{"south":"-20","west":"170","north":"-10","east":"-170"}` | `20° S, 170° E – 10° S, 170° W` |

## Operations

- `geo.bounding_box(shape: T) -> BoundingBox`: The smallest box of parallels and meridians holding the shape, an edge's highest or lowest point counted, across the antimeridian when that box is narrower; a shape holding a pole runs from -180 to 180.
- `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.
