Skip to content

[css-values-4] Should simplification of Sum nodes convert to canonical units? #4505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
smfr opened this issue Nov 11, 2019 · 4 comments
Closed
Labels
css-values-4 Current Work

Comments

@smfr
Copy link
Contributor

smfr commented Nov 11, 2019

At https://drafts.csswg.org/css-values-4/#calc-simplification Step 7.2, it says:

For each set of root’s children that are numeric values with identical units, remove those children and replace them with a single numeric value containing the sum of the removed nodes, and with the same unit.

Note the "identical units". This is different from Product nodes, which simplify down (when possible) to a value represented in the result's canonical unit.

Step 4 says:

If root is an operator node that’s not one of the calc-operator nodes, and all of its children are numeric values with enough information to computed the operation root represents, return the result of running root’s operation using its children, expressed in the result’s canonical unit.

but Sum is one of the calc-operator nodes. So following the steps, I'm not sure how calc(1rad + 45deg) gets reduced down to 102.29578deg.

@smfr smfr closed this as completed Nov 11, 2019
@smfr smfr reopened this Nov 11, 2019
@smfr smfr changed the title [css-values-4 [css-values-4] Should simplification of Sum nodes convert to canonical units? Nov 11, 2019
@smfr smfr added the css-values-4 Current Work label Nov 11, 2019
@smfr
Copy link
Contributor Author

smfr commented Nov 11, 2019

There's also some ambiguity about whether the function name is preserved on the root if it simplifies down to a numerical value. Should calc(1px) simplify to 1px, and min(1px) to 1px? I think the combination of 10.7 step 6 and 10.7.1 step 4 suggest that they do, but browsers don't seem to implement that.

@smfr
Copy link
Contributor Author

smfr commented Nov 12, 2019

I think reduction of calc(1rad + 45deg)` to 102.29578deg`` was me just misunderstanding a web platform test.

@smfr
Copy link
Contributor Author

smfr commented Nov 15, 2019

Some concrete examples where implementations seem to disagree. How do the following serialize?

  • min(1): min(1) or 1?
  • min(1, 2): min(1, 2) or 1?
  • min(min(1)): min(min(1)), min(1) or 1?
  • calc(min(1)): calc(min(1)), min(1) or 1 or other?

Questions:

  1. Should simplification ever remove all the math functions?
  2. Should nested math functions of different types be simplified, i.e. is it OK to simplify calc(calc(1)) but not calc(min(1))

@tabatkins the note at https://drafts.csswg.org/css-values-4/#calc-serialize says this is under discussion, but is there anything more recent than 2016?

@tabatkins
Copy link
Member

So following the steps, I'm not sure how calc(1rad + 45deg) gets reduced down to 102.29578deg.

That's triggered by step 3, where you simplify all the children of the node; 1rad and 45deg then hit step 1.2 and return themselves converted to deg. Then, back in simplifying the Sum node, step 7.2 sees that it has two deg children and combines them.

There's also some ambiguity about whether the function name is preserved on the root if it simplifies down to a numerical value. Should calc(1px) simplify to 1px, and min(1px) to 1px? I think the combination of 10.7 step 6 and 10.7.1 step 4 suggest that they do, but browsers don't seem to implement that.

It's definitely not clear, and I'm not sure what's ideal, actually! That's why I opened #4399 to talk about it. ^_^ I'll move your questions/examples over to that issue, and since the original question from this issue has been answered, I'll close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-values-4 Current Work
Projects
None yet
Development

No branches or pull requests

2 participants