W3C home > Mailing lists > Public > public-css-archive@w3.org > April 2019

Re: [csswg-drafts] [css-values] Serialize all functions in summation (#3785)

From: Amelia Bellamy-Royds via GitHub <sysbot+gh@w3.org>
Date: Mon, 01 Apr 2019 01:55:48 +0000
To: public-css-archive@w3.org
Message-ID: <issue_comment.created-478409942-1554083746-sysbot+gh@w3.org>
>  `calc(1 + calc(2px / 2em) + 3 + sqrt(16) + calc(5px / 5em))` should become
>  `calc(4 + calc(2px / 2em) + sqrt(16) + calc(5px / 5em))`

The nested `calc()` should be dropped in favour of simple parentheses per the rules on [simplifying a calculation](https://drafts.csswg.org/css-values/#math-function-simplify-a-calculation).  But you're correct that this complicates the sort order considerably, since terms can have all sorts of combinations of units.

I believe the whole purpose of sorting terms at all is so that two algebraically equal expressions have the same simplification.  To be consistent with that goal, we should probably define full sorting rules for complex dimensions (e.g., by number of dimensions and then alphabetically by numerator units and then by denominator units and then by numerical magnitude...) and for functions (e.g., alphabetically by function name). So, your equation would be more like:

`calc(4 + (2px / 2em) + (5px / 5em) +  sqrt(16))`

However, since serialization currently supports algebraic simplification, we could expect it to combine terms with equivalent dimensions, and maybe compute out trig functions of simple numbers:

`calc(8 + (2px / 1em) )`

Either way, we need a spec!  But I see no problem with merging your simple PR and then opening a separate issue for the full discussion.



-- 
GitHub Notification of comment by AmeliaBR
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/pull/3785#issuecomment-478409942 using your GitHub account
Received on Monday, 1 April 2019 01:55:49 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 19 October 2021 01:31:06 UTC