Bug 216906

Summary: CSS angle unit conversions should consistently use the same associativity
Product: WebKit Reporter: Keith Miller <keith_miller>
Component: New BugsAssignee: Keith Miller <keith_miller>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cdumez, cmarcelo, eric.carlson, esprehn+autocc, ews-watchlist, glenn, gyuyoung.kim, jer.noble, macpherson, menard, mjs, philipj, sergio, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch for landing none

Description Keith Miller 2020-09-23 16:21:49 PDT
CSS angle unit conversions should consistently use the same associativity
Comment 1 Keith Miller 2020-09-23 16:38:09 PDT
Created attachment 409516 [details]
Patch
Comment 2 Keith Miller 2020-09-23 16:39:43 PDT
I'm not 100% sure the image passes are real. If they fail on the bots I'll change them to [ PASS ImageOnlyFailure ] instead.
Comment 3 Maciej Stachowiak 2020-09-23 17:02:02 PDT
Comment on attachment 409516 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=409516&action=review

> Source/WebCore/ChangeLog:21
> +        This patch changes the WTF functions to operate on a single
> +        scale factor when converting to/from the canonical
> +        unit. Conversions between non-canonical units first convert to the
> +        canonical unit (degree). Also,
> +        conversionToCanonicalUnitsScaleFactor now gets the scale factor
> +        from the WTF functions for consistency.

Ideally the ChangeLog should explain why this matter.

> Source/WTF/wtf/MathExtras.h:103
> +// We compute the scale factor first because it allows us to extract scale factors via these functions. This is important because FP is not associative.

e.g. the explanation in this comment would be good in the ChangeLog.

> Source/WTF/wtf/MathExtras.h:104
> +inline double deg2rad(double d)  { return d * (piDouble / 180.0); }

How about extracting the conversion factors into named constants? That would make the comment unnecessary here (there would't be weird parens to explain) and it would avoid the need to call these functions with a 1.0 parameter to generate conversion factors, which seems more awkward than just using conversion factor constants.

> Source/WTF/wtf/MathExtras.h:121
> +inline float rad2grad(float r) { return deg2grad(rad2deg(r)); }
> +inline float grad2rad(float g) { return deg2rad(grad2deg(g)); }

I guess this is right for CSS, but is it right for all uses of these math functions?

> Source/WebCore/css/CSSPrimitiveValue.cpp:761
> +        factor = grad2deg(1.0);

As mentioned above, it would be even nicer if this referenced a named constant instead of calling the conversion function with a 1.0 parameter.
Comment 4 Keith Miller 2020-09-23 17:18:31 PDT
Comment on attachment 409516 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=409516&action=review

>> Source/WebCore/ChangeLog:21
>> +        from the WTF functions for consistency.
> 
> Ideally the ChangeLog should explain why this matter.

Sure.

>> Source/WTF/wtf/MathExtras.h:103
>> +// We compute the scale factor first because it allows us to extract scale factors via these functions. This is important because FP is not associative.
> 
> e.g. the explanation in this comment would be good in the ChangeLog.

Copied.

>> Source/WTF/wtf/MathExtras.h:104
>> +inline double deg2rad(double d)  { return d * (piDouble / 180.0); }
> 
> How about extracting the conversion factors into named constants? That would make the comment unnecessary here (there would't be weird parens to explain) and it would avoid the need to call these functions with a 1.0 parameter to generate conversion factors, which seems more awkward than just using conversion factor constants.

Fair enough. Done.

>> Source/WTF/wtf/MathExtras.h:121
>> +inline float grad2rad(float g) { return deg2rad(grad2deg(g)); }
> 
> I guess this is right for CSS, but is it right for all uses of these math functions?

The only place using these is in SVG. And changing this does appear to cause a test to pass.

>> Source/WebCore/css/CSSPrimitiveValue.cpp:761
>> +        factor = grad2deg(1.0);
> 
> As mentioned above, it would be even nicer if this referenced a named constant instead of calling the conversion function with a 1.0 parameter.

Sure.
Comment 5 Keith Miller 2020-09-23 18:55:27 PDT
Created attachment 409522 [details]
Patch
Comment 6 Keith Miller 2020-09-24 09:52:03 PDT
Created attachment 409586 [details]
Patch
Comment 7 Keith Miller 2020-09-24 11:10:38 PDT
Created attachment 409602 [details]
Patch
Comment 8 Keith Miller 2020-09-24 11:30:14 PDT
Comment on attachment 409516 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=409516&action=review

>>> Source/WTF/wtf/MathExtras.h:121
>>> +inline float grad2rad(float g) { return deg2rad(grad2deg(g)); }
>> 
>> I guess this is right for CSS, but is it right for all uses of these math functions?
> 
> The only place using these is in SVG. And changing this does appear to cause a test to pass.

I lied, that appears to have been a flakey pass... :/
Comment 9 Maciej Stachowiak 2020-09-24 13:10:37 PDT
Comment on attachment 409602 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=409602&action=review

r=me

> LayoutTests/imported/w3c/ChangeLog:13
> +        * web-platform-tests/css/css-values/minmax-angle-computed-expected.txt:
> +        * web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-panner-connections-expected.txt:
> +        * web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-panner-expected.txt:
> +        * web-platform-tests/webaudio/the-audio-api/the-pannernode-interface/panner-automation-basic-expected.txt:

You may want to explain that these are either progressions or irrelevant changes.

Does one of these tests cover what you are actually fixing? I assume the minmax-angle-computed-expected one?
Comment 10 Keith Miller 2020-09-24 13:14:48 PDT
Comment on attachment 409602 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=409602&action=review

>> LayoutTests/imported/w3c/ChangeLog:13
>> +        * web-platform-tests/webaudio/the-audio-api/the-pannernode-interface/panner-automation-basic-expected.txt:
> 
> You may want to explain that these are either progressions or irrelevant changes.
> 
> Does one of these tests cover what you are actually fixing? I assume the minmax-angle-computed-expected one?

Yeah, the minmax-angle-computed test covers this edge case. Will add that comment, I'll also clarify that the other tests are simply changes to the rounding error of the panner computation.
Comment 11 Keith Miller 2020-09-24 14:57:03 PDT
Created attachment 409623 [details]
Patch for landing
Comment 12 EWS 2020-09-24 15:40:12 PDT
Committed r267551: <https://trac.webkit.org/changeset/267551>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 409623 [details].
Comment 13 Radar WebKit Bug Importer 2020-09-24 15:41:20 PDT
<rdar://problem/69530589>