-
Notifications
You must be signed in to change notification settings - Fork 708
[css-values-4] How should atan2 behave with different length units? #7482
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
Comments
Same is true for percentages. If percentages are allowed, then what are they a percentage of? WebKit ignores this and treats Most of this applies for the |
Math functions are simplified to the extent possible. See 10.10.1. Simplification:
There is not enough information to resolve percentages (except when replacing a
Units should be used. I'm not a spec author so please do not take my words for granted. But I went through the implementation of math expressions, so I hope it helps. |
The result from the If a math function cannot be simplified to a numeric value at parse time, it is serialized as is. Then at computed value time, I agree that some clarification on the processing (parsing, simplification, type checking) of a math function would have helped me a lot. :) |
That is one interpretation. It is not the interpretation that WebKit implements, and there are no tests in WPT that show this to be the correct one. Additionally it leaves the question of what percentages are resolved against in properties that normally don't support them (eg rotate). I guess only the ratio between the arguments matters, but it's a little weird when the percentages don't actually resolve to anything. |
Are you referring to the resolved value I expect for Regarding
EDIT: he, no sorry, it will successfully resolve to |
This behavior seems inconsistent, so I am looking for clarification from the spec authors on the correct intent. Then, we can work on adding new Web Platform Tests to handle these cases.
This part of the spec is about resolving the type of the result of a math function, specifically
I believe this means that percentages are valid in any use of |
It doesn't matter. Then
It depends. Percentages may have the type «[ "percent" → 1 ]» e.g. in But in properties like
See https://drafts.csswg.org/css-values-4/#calc-computed-value. Maybe not at specified value time, maybe not at computed value time either, but: "with used value time information, a math function always simplifies down to a single numeric value."
Because it's more flexible and it's well-defined. Math functions that can accept dimensions do so: |
Thanks. So it seems the webkit implementation is buggy then, and it would be good to add some new tests to WPT where different units are used between the arguments. |
Those two are absolutely not equivalent (unless the viewport is 100px wide), and if an implementation is treating them as having the same value it's buggy, just at a basic definitional level. Looking at all the rest of your example, phew, yeah the WK implementation appears to be completely wrong when working with dimensions; that behavior is nonsensical.
You resolve them as far as you can, given the value stage you're at. If you can't fully resolve the two arguments to the same canonical unit, then the function can't resolve yet, and will have to wait until later in the value pipeline. See https://drafts.csswg.org/css-values/#calc-simplification and https://drafts.csswg.org/css-values/#calc-computed-value for details - at computed value time we resolve everything as much we can, including resolving functions to their answers if possible, but if it's not yet possible then we wait for used-value time, when it's guaranteed to be possible. For example,
The units are used, WebKit's impl is just completely broken. atan2() takes a coordinate pair, and it's reasonable to specify a coordinate pair with dimensions, when lengths are relevant to what you're doing. For example, knowing the angle formed by moving 90px up and 90vw sideways is meaningful!
Yeah, I wouldn't have imagined an implementation like this would have passed review in the first place, so we definitely need some tests to make sure they're definitely failing. |
Thanks. I filed this WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=242629 And sorry for my confusion here. I was really scratching my head! |
The spec says that
atan2
accepts two calculations, which must have the same type. However, the type is defined as only "length" for length values, and does not include the unit. In fact, the unit seems to be completely ignored.For example, the following are equivalent despite having completely different units.
In the WebKit implementation, however, the following are not equivalent. Presumably there is some unit conversion happening due to the units being compatible, but not sure if this is correct.
Further, when a calculation results in incompatible units, it's unclear what the behavior should be. For example:
In WebKit, the second term seems to be ignored and result in the same value as
rotate: atan2(90px, 10px)
. This seems like a bug, but I'm not sure what to expect here. Should10vw
be computed and converted into px? What if the terms were reversed? Should10px
be converted tovw
then? Should the units be ignored, resulting inatan2(90, 20)
? The spec doesn't say in which unitatan2
should be computed.My question: what should the behavior be when the units of the arguments are different, but the types are the same? What should happen if a calculation cannot be simplified to a single number?
Perhaps a better question: why does this function accept units at all? Why not only allow calculations that resolve to a
<number>
similar to some of the other math functions? Since the units aren't actually used, it just seems confusing.The text was updated successfully, but these errors were encountered: