# `Area`

An area: `12sqm` or `2ha`.

Use it for floor space or land. A [`Length`](/docs/types/type-length.md) times a [`Length`](/docs/types/type-length.md) gives one. For a drawn shape on a map, use [`Polygon`](/docs/types/type-polygon.md), which `geo.area` measures.

## Shape

One value, with no fields to fill in. As text it reads `10000 sqm`.

## Example

```jadpo
Area(12sqm)
```

`text.parse(raw, as: Area)` reads one from text that comes from outside. Text that isn't one at all fails `malformed`, such as `5`, `1.2.3` or `five`.

These operations give one: `geo.area`, `units.of` and `units.sum`.

## Good to know

- It is held in square metres to 6 places.
- `==` tells you whether two are the same, and `<` and `list.sort_by` compare and sort them.

## In JSON

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

```json
{"value":"0.5","unit":"sqm"}
{"value":"12","unit":"sqm"}
{"value":"10000","unit":"sqm"}
```

## Details

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

`Area` is in the group Physical quantities, and has been in Jadpo since 0.1.0.

### Text form

`text.from` writes one standard text form, the same form `text.parse` reads back: `0.5 sqm`, `12 sqm` and `10000 sqm`.

### How it is stored

It is stored in one column named for the field, of type `numeric(38, 6)`, holding the area in square metres (m²). `12 sqm` is stored as `12`.

### How it is shown to people

`text.format(value, locale:)` shows it to people in their locale. A call may also give `unit:`.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `0.5 sqm` | `0.5 m²` |
| `12 sqm` | `12 m²` |
| `10000 sqm` | `10,000 m²` |

### Operations

- `geo.area(shape: T) -> Area`: A `Polygon`'s or `MultiPolygon`'s area on the ellipsoid, each edge a geodesic and each ring the smaller of the two sides it bounds, holes taken away, rounded half to even to the square millimetre.
- `units.in(value: Quantity, unit: QuantityUnit, scale: Int, rounding: Rounding) -> Decimal`: `value` in `unit`, a unit of its kind, as a `Decimal` of `scale` places rounded by `rounding`: `units.in(5km, LengthUnit.mile, scale: 2, rounding: Rounding.half_even)` is `3.11`.
- `units.of(value: Number, unit: QuantityUnit) -> Quantity`: `value` of `unit`, an `Int` or a `Decimal`, as the quantity of `unit`'s kind, converted exactly to the base unit and rounded half to even to the kind's scale: `units.of(5, LengthUnit.mile)`.
- `units.sum(items: List<Quantity>) -> Quantity`: The items added up, all of one kind; nothing for no items. A `Temperature` or a `SoundLevel` doesn't add to itself, so neither is summed.

It also takes `text.parse`, `text.from`, `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>
