# `Macaw.Draw.Polygon`
[🔗](https://github.com/dcoai/macaw_draw/blob/v0.1.0/lib/macaw/draw/polygon.ex#L1)

Polygon measures (spec/07 §21), copied from visualize's `Visualize.Polygon` over lists of
`{x, y}` tuples; a polygon is implicitly closed. Geographic polygons, contours and
Voronoi cells (spec/09) measure through this module.

    iex> square = [{0, 0}, {100, 0}, {100, 100}, {0, 100}]
    iex> {Macaw.Draw.Polygon.area(square), Macaw.Draw.Polygon.centroid(square)}
    {10000.0, {50.0, 50.0}}

`hull/1` is Andrew's monotone chain, `O(n log n)`; every other measure is one pass over
the points (visualize read them by position, a square of their count). A list holding a
term that is no pair of numbers is `{[i], {:type, :point}}` at its index.

# `error`

```elixir
@type error() :: {:error, [Macaw.Base.Fault.t()]}
```

A refusal: faults with their paths.

# `point`

```elixir
@type point() :: {number(), number()}
```

# `polygon`

```elixir
@type polygon() :: [point()]
```

# `area`

```elixir
@spec area(polygon()) :: float() | error()
```

The signed shoelace area: positive when the vertices wind counter-clockwise in a y-up
frame (clockwise on screen, where y points down); `0.0` for fewer than three points.

# `bounds`

```elixir
@spec bounds(polygon()) :: {number(), number(), number(), number()} | nil | error()
```

`{min_x, min_y, max_x, max_y}`, or `nil` for `[]`.

# `centroid`

```elixir
@spec centroid(polygon()) :: point() | error()
```

The area-weighted centroid: `{0.0, 0.0}` for `[]`, the point itself for one, the midpoint
for two, the vertex mean when `|area| < 1.0e-10`.

# `contains?`

```elixir
@spec contains?(polygon(), point()) :: boolean() | error()
```

Whether `point` is inside, by even-odd ray casting; `false` for fewer than three points.
A point exactly on an edge may answer either.

# `hull`

```elixir
@spec hull([point()]) :: polygon() | error()
```

The convex hull by Andrew's monotone chain: counter-clockwise (y-up), collinear points
and duplicates removed; two or fewer points are returned unchanged.

# `path_length`

```elixir
@spec path_length([point()]) :: float() | error()
```

The length of the open polyline: no closing edge.

# `perimeter`

```elixir
@spec perimeter(polygon()) :: float() | error()
```

The sum of edge lengths, the closing edge included; `0.0` for fewer than two points.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
