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

A continuous linear scale, a numeric domain to a numeric range (spec/06 §4).

    {:ok, scale} = Macaw.Draw.Scale.Linear.new() |> Macaw.Draw.Scale.Linear.domain([0, 100])
    {:ok, scale} = Macaw.Draw.Scale.Linear.range(scale, [0, 500])
    Macaw.Draw.Scale.Linear.apply(scale, 50)
    #=> 250.0

`apply/2` is total: a value that is not a number answers `nil`. `ticks/2` and `nice/1`
are the one tick rule's, `Macaw.Draw.Ticks` (spec/06 §16).

# `error`

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

A refusal: faults with their paths.

# `t`

```elixir
@type t() :: %Macaw.Draw.Scale.Linear{
  clamp?: boolean(),
  domain: [number()],
  range: [number()]
}
```

# `apply`

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

The range value of `value`: `r0 + t · (r1 − r0)`, `t` the value's position in the domain,
`0.5` in a collapsed one, clamped to `[0, 1]` when the scale clamps. Always a float; a
value that is not a number answers `nil`.

# `bandwidth`

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

`0`: a linear scale has no bandwidth.

# `clamp`

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

Sets clamping; answers the struct.

# `domain`

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

Sets the domain, two numbers: `{:ok, scale}` or `{:error, faults}` (spec/06 §2.2).

# `domain!`

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

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

# `invert`

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

The domain value of a range value, `d0 + t · (d1 − d0)`; never clamps, `nil` for a non-number.

# `new`

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

The default scale: domain `[0, 1]`, range `[0, 1]`, no clamping.

# `nice`

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

The domain widened to nice values at count 10, keeping its orientation (spec/06 §16).

# `padding`

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

Identity: a linear scale has no padding.

# `range`

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

Sets the range, two numbers: `{:ok, scale}` or `{:error, faults}`.

# `range!`

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

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

# `ticks`

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

About `count` nice ticks over the domain: `Macaw.Draw.Ticks.ticks/3` (spec/06 §16).

---

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