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

A discretizing scale by uniform buckets: the domain divided into as many equal segments
as the range has elements (spec/06 §12).

    scale = Macaw.Draw.Scale.Quantize.new() |> Macaw.Draw.Scale.Quantize.domain!([0, 100])
    scale = Macaw.Draw.Scale.Quantize.range(scale, [:low, :mid, :high, :top])
    Macaw.Draw.Scale.Quantize.apply(scale, 60)
    #=> :high

`apply/2` always clamps: a value outside the domain maps to the first or last element.

# `error`

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

A refusal: faults with their paths.

# `t`

```elixir
@type t() :: %Macaw.Draw.Scale.Quantize{domain: [number()], range: [term()]}
```

# `apply`

```elixir
@spec apply(t(), term()) :: term() | error()
```

The range element of the value's bucket, `min(⌊t · n⌋, n − 1)` for `t` its clamped
position in the domain (`0` in a collapsed one); `nil` for an empty range or a value
that is no number.

# `bandwidth`

```elixir
@spec bandwidth(t()) :: 0 | error()
```

`0`: a quantize scale has no bandwidth.

# `bucket_count`

```elixir
@spec bucket_count(t()) :: non_neg_integer() | error()
```

The number of buckets, the range's length.

# `clamp`

```elixir
@spec clamp(t(), boolean()) :: t() | error()
```

Identity: a quantize scale always clamps.

# `domain`

```elixir
@spec domain(t(), term()) :: {:ok, t()} | error()
```

Sets the domain, two numbers as a list or a tuple, stored as a list.

# `domain!`

```elixir
@spec domain!(t(), term()) :: t()
```

`domain/2`, answering the scale or raising `Macaw.Draw.Error`.

# `invert`

```elixir
@spec invert(t(), term()) :: nil | error()
```

`nil`: a quantize scale maps many values to one bucket.

# `invert_extent`

```elixir
@spec invert_extent(t(), term()) :: {number(), number()} | nil | error()
```

The sub-interval of the domain a range element stands for,
`{d0 + k·step, d0 + (k+1)·step}`; `nil` for an empty range or an element not in it.

# `new`

```elixir
@spec new() :: t()
```

A quantize scale over `[0, 1]` with no range.

# `nice`

```elixir
@spec nice(t()) :: t() | error()
```

Identity.

# `padding`

```elixir
@spec padding(t(), number()) :: t() | error()
```

Identity: a quantize scale has no padding.

# `range`

```elixir
@spec range(t(), [term()]) :: t() | error()
```

Sets the range, a list; answers the struct.

# `thresholds`

```elixir
@spec thresholds(t()) :: [number()] | error()
```

The `n − 1` interior boundaries; `[]` for fewer than two range elements.

# `ticks`

```elixir
@spec ticks(t(), number()) :: [number()] | error()
```

`thresholds/1`; the count is ignored.

---

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