# [csswg-drafts] [css-values] Interpolation with degenerate <ratio> (#5722)

From: Oriol Brufau via GitHub <sysbot+gh@w3.org>
Date: Thu, 12 Nov 2020 15:57:56 +0000

Message-ID: <issues.opened-741718796-1605196674-sysbot+gh@w3.org>
```Loirooriol has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-values] Interpolation with degenerate <ratio> ==
In #4953 we resolved that the interpolation between two ratios `ratio1` and `ratio2` at distance `p` would be

```
interpolate(ratio1, ratio2, p) := e^(log(ratio1)*(1-p) + log(ratio2)*p) = ratio1^(1-p) * ratio2^p
```
This is usually a continuous function, and the boundary conditions hold:

```
interpolate(ratio1, ratio2, 0) =  ratio1^1 * ratio2^0 = ratio1
interpolate(ratio1, ratio2, 1) =  ratio1^0 * ratio2^1 = ratio2
```

But this doesn't work well if at least one of the ratios is degenerate (`0/1`, `1/0` or `0/0`):

```
interpolate(0/1, ratio2, 1) =  0^0 * ratio2 = NaN = 0/0
interpolate(1/0, ratio2, 1) =  ∞^0 * ratio2 = NaN = 0/0
interpolate(0/0, ratio2, p) =  NaN * ratio2^p = NaN = 0/0
```
even if `ratio2` is not `0/0`.

(I'm saying `0^0` and `∞^0` are NaN because they are undefined in math, though in CSS/JS they produce `1`, huh. So maybe they are not degenerate after all?)

So at least, in order to comply with https://drafts.csswg.org/css-values/#interpolation, we would have to define
```
interpolate(ratio1, ratio2, p) :=
┌
│ ratio1, if p=0
:= ┤ ratio2, if p=1
│ ratio1^(1-p) * ratio2^p, otherwise
└
```
However, the range of `p` is actually `(−∞, ∞)` because of timing functions. For example, when interpolating from `0/1` to `1/1`, the above would produce `0` when `p=0→1`, `1` for `p=1`, `∞` when `p>1`, and `1` when `p=1` again. Not sure if this is great, might be better to clamp for degenerate cases:

```
interpolate(ratio1, ratio2, p) :=
┌
│ ratio1, if p≤0 and ratio2 ∈ {0/1, 1/0, 0/0}
:= ┤ ratio2, if p≥1 and ratio1 ∈ {0/1, 1/0, 0/0}
│ ratio1^(1-p) * ratio2^p, otherwise
└
```

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/5722 using your GitHub account

--
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
```
Received on Thursday, 12 November 2020 15:57:57 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 06:42:22 UTC