[csswg-drafts] [css-values] Functions to select one value from a set: med(), mod()

Crissov has just created a new issue for 
https://github.com/w3c/csswg-drafts:

== [css-values] Functions to select one value from a set: med(), mod()
 ==
In #544, minimum and maximum functions have been accepted for [CSS 
Values Level 4](https://drafts.csswg.org/css-values/#calc-notation). 

    min(100px 10em 1vw)
    max(100px 10em 1vw)

Both functions select a single computed value – i.e. the smallest and 
largest, respectively – from a set of 1 to _N_ values (which may be 
results of nested `calc()` expressions). This cannot be achieved with 
Level 3 `calc()` syntax. There are at least two other useful statistic
 measures that work the same: **mode**  chooses the most frequently 
occuring computed value and **median** chooses the computed value with
 the same number of smaller and larger sibling values. . 

    mod(100px 10em 1vw)
    med(100px 10em 1vw)

    mod(100px 10px 10px) /* = 10px */
    med(100px 10px 1px) /* = 10px */

The **mode** function may benefit from an optional value to specify 
the precision, i.e. tolerance limits, when comparing (and returning) 
computed values.

    mod(100px 10em 1vw, 1pt)

This could effectively be reused as a ‘round to nearest multiple’ 
function.

    mod(101px, 1pt) /* = 76pt ≈ 101.33px */
    mod(100px, 1pt) /* = 75pt = 100px */
    mod(99px, 1pt) /* = 74pt ≈ 98.67px */
    mod(10px, 1pt) /* = 8pt ≈ 10.67px */
    mod(1px, 1pt) /* = 1pt ≈ 1.33px */

The specification must also say what to do if no computed value occurs
 more often than another. It may fall back to the arithmetic mean of 
all equally frequent values.

    mod(100px 10px) /* = 55px? */

The **median** function needs to be specified for an even number of 
values as well, i.e. when there is one above and one below but none at
 the center of the set. It may fall back to the arithmetic mean of the
 two values closest to the true median.

    med(100px 10px) /* = 55px? */

    med(100px 10px 10px) /* = 55px? */
    med(100px 100px 10px) /* = 55px? */

If the values closest to the center do not occur equally often, the 
median could be weighted instead.

    med(100px 10px 10px) /* = 40px? */
    med(100px 100px 10px) /* = 70px? */


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

Received on Friday, 13 January 2017 12:05:36 UTC