⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 267551 in webkit


Ignore:
Timestamp:
Sep 24, 2020, 3:40:06 PM (6 years ago)
Author:
keith_miller@apple.com
Message:

CSS angle unit conversions should consistently use the same associativity
https://bugs.webkit.org/show_bug.cgi?id=216906

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

Rebaseline tests for different rounding errors in angle unit conversions. The minmax-angle-computed test
is now passing and the webaudio tests just have slightly different results now.

  • 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:

Source/WebCore:

Right now we inconsistently associate our floating point math for
angle unit conversions. In particular,
conversionToCanonicalUnitsScaleFactor expects there to be a single
fixed constant we can multiply by to change units. However, the
various conversion functions in WTF are not associated in this
way. e.g. rad2deg does ((radian * 180) / pi) rather than
(radian * (180 / pi)). Since FP math is NOT associative these
produce different results. For example, 1.57 radians is
89.954373835539258 degrees in the first case but
89.954373835539243 in the second.

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 WTF to ensure we get the same associativity
everywhere.

  • css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor):

Source/WTF:

Right now we inconsistently associate our floating point math for
angle unit conversions. In particular,
conversionToCanonicalUnitsScaleFactor expects there to be a single
fixed constant we can multiply by to change units. However, the
various conversion functions in WTF are not associated in this
way. e.g. rad2deg does ((radian * 180) / pi) rather than
(radian *(180 / pi)). Since FP math is NOT associative these
produce different results. For example, 1.57 radians is
89.954373835539258 degrees in the first case but
89.954373835539243 in the second.

This patch changes those 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).

  • wtf/MathExtras.h:

(deg2rad):
(rad2deg):
(deg2grad):
(grad2deg):
(deg2turn):
(turn2deg):
(rad2grad):
(grad2rad):

LayoutTests:

Rebaseline tests.

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r267547 r267551  
     12020-09-24  Keith Miller  <keith_miller@apple.com>
     2
     3        CSS angle unit conversions should consistently use the same associativity
     4        https://bugs.webkit.org/show_bug.cgi?id=216906
     5
     6        Reviewed by Simon Fraser.
     7
     8        Rebaseline tests.
     9
     10        * TestExpectations:
     11
    1122020-09-24  Lauro Moura  <lmoura@igalia.com>
    213
  • trunk/LayoutTests/TestExpectations

    r267531 r267551  
    11891189webkit.org/b/64861 imported/w3c/web-platform-tests/css/selectors/selectors-dir-selector-ltr-001.html [ ImageOnlyFailure ]
    11901190webkit.org/b/64861 imported/w3c/web-platform-tests/css/selectors/selectors-dir-selector-rtl-001.html [ ImageOnlyFailure ]
    1191 imported/w3c/web-platform-tests/css/selectors/selector-placeholder-shown-type-change-001.html [ ImageOnlyFailure ]
    1192 imported/w3c/web-platform-tests/css/selectors/selector-placeholder-shown-type-change-002.html [ ImageOnlyFailure ]
    1193 imported/w3c/web-platform-tests/css/selectors/selector-placeholder-shown-type-change-003.html [ ImageOnlyFailure ]
    1194 imported/w3c/web-platform-tests/css/selectors/selector-read-write-type-change-002.html [ ImageOnlyFailure ]
    1195 imported/w3c/web-platform-tests/css/selectors/selector-required-type-change-002.html [ ImageOnlyFailure ]
    11961191imported/w3c/web-platform-tests/css/selectors/old-tests/css3-modsel-172a.xml [ ImageOnlyFailure ]
    11971192imported/w3c/web-platform-tests/css/selectors/old-tests/css3-modsel-172b.xml [ ImageOnlyFailure ]
     
    16671662imported/w3c/web-platform-tests/svg/extensibility/foreignObject/isolation-with-svg.html [ ImageOnlyFailure ]
    16681663imported/w3c/web-platform-tests/svg/painting/reftests/display-none-mask.html [ ImageOnlyFailure ]
    1669 imported/w3c/web-platform-tests/svg/struct/reftests/use-external-resource-with-revalidation.tentative.html [ ImageOnlyFailure ]
    16701664
    16711665webkit.org/b/139595 imported/w3c/web-platform-tests/svg/import/animate-dom-02-f-manual.svg [ Skip ]
     
    24832477webkit.org/b/186045 imported/w3c/web-platform-tests/css/css-animations/animation-delay-008.html [ ImageOnlyFailure Pass ]
    24842478webkit.org/b/186045 imported/w3c/web-platform-tests/css/css-animations/animation-delay-009.html [ ImageOnlyFailure Pass ]
    2485 webkit.org/b/186045 imported/w3c/web-platform-tests/css/css-animations/animation-delay-010.html [ ImageOnlyFailure ]
    24862479
    24872480# overflow-wrap:anywhere feature is not implemented yet.
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r267531 r267551  
     12020-09-24  Keith Miller  <keith_miller@apple.com>
     2
     3        CSS angle unit conversions should consistently use the same associativity
     4        https://bugs.webkit.org/show_bug.cgi?id=216906
     5
     6        Reviewed by Simon Fraser.
     7
     8        Rebaseline tests for different rounding errors in angle unit conversions. The minmax-angle-computed test
     9        is now passing and the webaudio tests just have slightly different results now.
     10
     11        * web-platform-tests/css/css-values/minmax-angle-computed-expected.txt:
     12        * web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-panner-connections-expected.txt:
     13        * web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-panner-expected.txt:
     14        * web-platform-tests/webaudio/the-audio-api/the-pannernode-interface/panner-automation-basic-expected.txt:
     15
    1162020-09-24  Frederic Wang  <fwang@igalia.com>
    217
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/minmax-angle-computed-expected.txt

    r264522 r267551  
    1717PASS max(1turn, 2turn) should be used-value-equivalent to 2turn
    1818PASS min(90deg, 0.26turn) should be used-value-equivalent to 90deg
    19 FAIL min(1.57rad, 95deg) should be used-value-equivalent to 1.57rad assert_equals: rotate(min(1.57rad, 95deg)) and rotate(1.57rad) serialize to the same thing in used values. expected "matrix(0.0007963267107332633, 0.9999996829318346, -0.9999996829318346, 0.0007963267107332633, 0, 0)" but got "matrix(0.0007963267107334854, 0.9999996829318346, -0.9999996829318346, 0.0007963267107334854, 0, 0)"
     19PASS min(1.57rad, 95deg) should be used-value-equivalent to 1.57rad
    2020PASS max(91deg, 0.25turn) should be used-value-equivalent to 91deg
    2121PASS max(1.58rad, 90deg) should be used-value-equivalent to 1.58rad
    22 FAIL min(270deg, max(0.25turn, 3.14rad)) should be used-value-equivalent to 3.14rad assert_equals: rotate(min(270deg, max(0.25turn, 3.14rad))) and rotate(3.14rad) serialize to the same thing in used values. expected "matrix(-0.9999987317275395, 0.0015926529164868282, -0.0015926529164868282, -0.9999987317275395, 0, 0)" but got "matrix(-0.9999987317275395, 0.0015926529164872723, -0.0015926529164872723, -0.9999987317275395, 0, 0)"
    23 FAIL max(0.25turn, min(270deg, 3.14rad)) should be used-value-equivalent to 3.14rad assert_equals: rotate(max(0.25turn, min(270deg, 3.14rad))) and rotate(3.14rad) serialize to the same thing in used values. expected "matrix(-0.9999987317275395, 0.0015926529164868282, -0.0015926529164868282, -0.9999987317275395, 0, 0)" but got "matrix(-0.9999987317275395, 0.0015926529164872723, -0.0015926529164872723, -0.9999987317275395, 0, 0)"
     22PASS min(270deg, max(0.25turn, 3.14rad)) should be used-value-equivalent to 3.14rad
     23PASS max(0.25turn, min(270deg, 3.14rad)) should be used-value-equivalent to 3.14rad
    2424PASS calc(min(90deg, 1.58rad) + 0.25turn) should be used-value-equivalent to 180deg
    2525PASS calc(min(90deg, 1.58rad) - 0.125turn) should be used-value-equivalent to 45deg
  • trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-panner-connections-expected.txt

    r267167 r267551  
    1010PASS > [Panner x] k-rate input
    1111PASS   Panner: positionX: Expected output channel 0 is not constantly 0.017871389165520668 (contains 512 different values).
    12 PASS   positionX: Expected output channel 1 is not constantly 0.03648621588945389 (contains 512 different values).
     12PASS   positionX: Expected output channel 1 is not constantly 0.036486223340034485 (contains 512 different values).
    1313PASS   Panner: positionX: Channel 0 output[0, 127] contains only the constant 0.017871389165520668.
    1414PASS   Panner: positionX: Channel 0 output[128, 255] contains only the constant 0.012888134457170963.
     
    1616PASS   Panner: positionX: Channel 0 output[384, 511] contains only the constant 0.004646967630833387.
    1717PASS   Panner: positionX: Channel 0 output[512, 639] contains only the constant 0.0030441549606621265.
    18 PASS   Panner: positionX: Channel 1 output[0, 127] contains only the constant 0.03648621588945389.
     18PASS   Panner: positionX: Channel 1 output[0, 127] contains only the constant 0.036486223340034485.
    1919PASS   Panner: positionX: Channel 1 output[128, 255] contains only the constant 0.044254120439291.
    2020PASS   Panner: positionX: Channel 1 output[256, 383] contains only the constant 0.04127275571227074.
     
    2626PASS > [Panner y] k-rate input
    2727PASS   Panner: positionY: Expected output channel 0 is not constantly 0.039904240518808365 (contains 512 different values).
    28 PASS   positionY: Expected output channel 1 is not constantly 0.08146847039461136 (contains 512 different values).
     28PASS   positionY: Expected output channel 1 is not constantly 0.08146847784519196 (contains 512 different values).
    2929PASS   Panner: positionY: Channel 0 output[0, 127] contains only the constant 0.039904240518808365.
    3030PASS   Panner: positionY: Channel 0 output[128, 255] contains only the constant 0.030709920451045036.
     
    3232PASS   Panner: positionY: Channel 0 output[384, 511] contains only the constant 0.01528366282582283.
    3333PASS   Panner: positionY: Channel 0 output[512, 639] contains only the constant 0.011893529444932938.
    34 PASS   Panner: positionY: Channel 1 output[0, 127] contains only the constant 0.08146847039461136.
    35 PASS   Panner: positionY: Channel 1 output[128, 255] contains only the constant 0.06269735842943192.
    36 PASS   Panner: positionY: Channel 1 output[256, 383] contains only the constant 0.042775362730026245.
    37 PASS   Panner: positionY: Channel 1 output[384, 511] contains only the constant 0.031203117221593857.
    38 PASS   Panner: positionY: Channel 1 output[512, 639] contains only the constant 0.0242818221449852.
     34PASS   Panner: positionY: Channel 1 output[0, 127] contains only the constant 0.08146847784519196.
     35PASS   Panner: positionY: Channel 1 output[128, 255] contains only the constant 0.06269736588001251.
     36PASS   Panner: positionY: Channel 1 output[256, 383] contains only the constant 0.042775366455316544.
     37PASS   Panner: positionY: Channel 1 output[384, 511] contains only the constant 0.031203120946884155.
     38PASS   Panner: positionY: Channel 1 output[512, 639] contains only the constant 0.024281825870275497.
    3939PASS   Panner: positionY: Actual output channel 0 equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
    4040PASS   Panner: positionY: Actual output channel 1 equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
     
    5151PASS   Panner: positionZ: Channel 1 output[128, 255] contains only the constant 0.03781212866306305.
    5252PASS   Panner: positionZ: Channel 1 output[256, 383] contains only the constant 0.031430669128894806.
    53 PASS   Panner: positionZ: Channel 1 output[384, 511] contains only the constant 0.025715911760926247.
     53PASS   Panner: positionZ: Channel 1 output[384, 511] contains only the constant 0.025715915486216545.
    5454PASS   Panner: positionZ: Channel 1 output[512, 639] contains only the constant 0.021292630583047867.
    5555PASS   Panner: positionZ: Actual output channel 0 equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
     
    6969PASS < [Listener x] All assertions passed. (total 10 assertions)
    7070PASS > [Listener y] k-rate input
    71 PASS   Listener: positionY: Channel 0 output[0, 127] contains only the constant 0.016606438905000687.
     71PASS   Listener: positionY: Channel 0 output[0, 127] contains only the constant 0.016606437042355537.
    7272PASS   Listener: positionY: Channel 0 output[128, 255] contains only the constant 0.023375829681754112.
    73 PASS   Listener: positionY: Channel 0 output[256, 383] contains only the constant 0.03255589306354523.
     73PASS   Listener: positionY: Channel 0 output[256, 383] contains only the constant 0.03255588933825493.
    7474PASS   Listener: positionY: Channel 0 output[384, 511] contains only the constant 0.03216671943664551.
    75 PASS   Listener: positionY: Channel 0 output[512, 639] contains only the constant 0.02294781431555748.
    76 PASS   Listener: positionY: Channel 1 output[0, 127] contains only the constant 0.04241393506526947.
    77 PASS   Listener: positionY: Channel 1 output[128, 255] contains only the constant 0.05970340967178345.
    78 PASS   Listener: positionY: Channel 1 output[256, 383] contains only the constant 0.08314989507198334.
    79 PASS   Listener: positionY: Channel 1 output[384, 511] contains only the constant 0.08215592056512833.
    80 PASS   Listener: positionY: Channel 1 output[512, 639] contains only the constant 0.0586102269589901.
     75PASS   Listener: positionY: Channel 0 output[512, 639] contains only the constant 0.02294781245291233.
     76PASS   Listener: positionY: Channel 1 output[0, 127] contains only the constant 0.04241393879055977.
     77PASS   Listener: positionY: Channel 1 output[128, 255] contains only the constant 0.059703417122364044.
     78PASS   Listener: positionY: Channel 1 output[256, 383] contains only the constant 0.08314990252256393.
     79PASS   Listener: positionY: Channel 1 output[384, 511] contains only the constant 0.08215592801570892.
     80PASS   Listener: positionY: Channel 1 output[512, 639] contains only the constant 0.058610234409570694.
    8181PASS < [Listener y] All assertions passed. (total 10 assertions)
    8282PASS > [Listener z] k-rate input
     
    8888PASS   Listener: positionZ: Channel 1 output[0, 127] contains only the constant 0.04121469706296921.
    8989PASS   Listener: positionZ: Channel 1 output[128, 255] contains only the constant 0.032292626798152924.
    90 PASS   Listener: positionZ: Channel 1 output[256, 383] contains only the constant 0.02588506042957306.
     90PASS   Listener: positionZ: Channel 1 output[256, 383] contains only the constant 0.025885064154863358.
    9191PASS   Listener: positionZ: Channel 1 output[384, 511] contains only the constant 0.021276984363794327.
    9292PASS   Listener: positionZ: Channel 1 output[512, 639] contains only the constant 0.017917200922966003.
  • trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-panner-expected.txt

    r267357 r267551  
    9797PASS   Listener k-rate positionX: Output is not constantly 0.0012908608186990023 (contains 512 different values).
    9898PASS   Listener k-rate positionX: Output [0, 127] contains only the constant 0.0012908608186990023.
    99 PASS   Listener k-rate positionX: Output [128, 255] contains only the constant 0.012697513215243816.
     99PASS   Listener k-rate positionX: Output [128, 255] contains only the constant 0.012697515077888966.
    100100PASS   Listener k-rate positionX: Output [256, 383] contains only the constant 0.012066217139363289.
    101 PASS   Listener k-rate positionX: Output [384, 511] contains only the constant 0.008956578560173512.
     101PASS   Listener k-rate positionX: Output [384, 511] contains only the constant 0.008956579491496086.
    102102PASS   Listener k-rate positionX: Output [512, 639] contains only the constant 0.006926612462848425.
    103103PASS < [Listener k-rate positionX] All assertions passed. (total 9 assertions)
     
    131131PASS   Listener k-rate forwardX: Output [0, 127] contains only the constant 0.00111640605609864.
    132132PASS   Listener k-rate forwardX: Output [128, 255] contains only the constant 0.001115163555368781.
    133 PASS   Listener k-rate forwardX: Output [256, 383] contains only the constant 0.001113853300921619.
     133PASS   Listener k-rate forwardX: Output [256, 383] contains only the constant 0.0011138531845062971.
    134134PASS   Listener k-rate forwardX: Output [384, 511] contains only the constant 0.0011124692391604185.
    135135PASS   Listener k-rate forwardX: Output [512, 639] contains only the constant 0.0011110050836578012.
     
    183183PASS   Listener upZ.setValueAtTime(-1,0) did not throw an exception.
    184184PASS   Listener upZ.linearRampToValueAtTime(1000,1) did not throw an exception.
    185 PASS   Listener k-rate upZ: Output is not constantly 0.001004426390863955 (contains 512 different values).
    186 PASS   Listener k-rate upZ: Output [0, 127] contains only the constant 0.001004426390863955.
     185PASS   Listener k-rate upZ: Output is not constantly 0.0010044265072792768 (contains 512 different values).
     186PASS   Listener k-rate upZ: Output [0, 127] contains only the constant 0.0010044265072792768.
    187187PASS   Listener k-rate upZ: Output [128, 255] contains only the constant 0.0010139397345483303.
    188188PASS   Listener k-rate upZ: Output [256, 383] contains only the constant 0.0010087323607876897.
  • trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-pannernode-interface/panner-automation-basic-expected.txt

    r266476 r267551  
    9393PASS   Mono listener.positionY.value frame [0, 128) channel 0 contains only the constant 0.22094237804412842.
    9494PASS   Mono listener.positionY.value frame [0, 128) channel 1 contains only the constant 0.5334020853042603.
    95 PASS   Mono listener.positionY.value frame [128, 256) channel 0 contains only the constant 0.00003826833926723339.
     95PASS   Mono listener.positionY.value frame [128, 256) channel 0 contains only the constant 0.00003826833562925458.
    9696PASS   Mono listener.positionY.value frame [128, 256) channel 1 contains only the constant 0.00009238795610144734.
    9797PASS   Mono listener.positionY: Output at frame 128 channel 0 is not equal to 0.22094237804412842.
  • trunk/Source/WTF/ChangeLog

    r267533 r267551  
     12020-09-24  Keith Miller  <keith_miller@apple.com>
     2
     3        CSS angle unit conversions should consistently use the same associativity
     4        https://bugs.webkit.org/show_bug.cgi?id=216906
     5
     6        Reviewed by Simon Fraser.
     7
     8        Right now we inconsistently associate our floating point math for
     9        angle unit conversions. In particular,
     10        conversionToCanonicalUnitsScaleFactor expects there to be a single
     11        fixed constant we can multiply by to change units. However, the
     12        various conversion functions in WTF are not associated in this
     13        way. e.g. rad2deg does ((radian * 180) / pi) rather than
     14        (radian  *(180 / pi)). Since FP math is NOT associative these
     15        produce different results. For example, 1.57 radians is
     16        89.954373835539258 degrees in the first case but
     17        89.954373835539243 in the second.
     18
     19        This patch changes those WTF functions to operate on a single
     20        scale factor when converting to/from the canonical
     21        unit. Conversions between non-canonical units first convert to the
     22        canonical unit (degree).
     23
     24        * wtf/MathExtras.h:
     25        (deg2rad):
     26        (rad2deg):
     27        (deg2grad):
     28        (grad2deg):
     29        (deg2turn):
     30        (turn2deg):
     31        (rad2grad):
     32        (grad2rad):
     33
    1342020-09-24  Antti Koivisto  <antti@apple.com>
    235
  • trunk/Source/WTF/wtf/MathExtras.h

    r265416 r267551  
    4141
    4242#ifndef M_PI
    43 const double piDouble = 3.14159265358979323846;
    44 const float piFloat = 3.14159265358979323846f;
     43constexpr double piDouble = 3.14159265358979323846;
     44constexpr float piFloat = 3.14159265358979323846f;
    4545#else
    46 const double piDouble = M_PI;
    47 const float piFloat = static_cast<float>(M_PI);
     46constexpr double piDouble = M_PI;
     47constexpr float piFloat = static_cast<float>(M_PI);
    4848#endif
    4949
    5050#ifndef M_PI_2
    51 const double piOverTwoDouble = 1.57079632679489661923;
    52 const float piOverTwoFloat = 1.57079632679489661923f;
     51constexpr double piOverTwoDouble = 1.57079632679489661923;
     52constexpr float piOverTwoFloat = 1.57079632679489661923f;
    5353#else
    54 const double piOverTwoDouble = M_PI_2;
    55 const float piOverTwoFloat = static_cast<float>(M_PI_2);
     54constexpr double piOverTwoDouble = M_PI_2;
     55constexpr float piOverTwoFloat = static_cast<float>(M_PI_2);
    5656#endif
    5757
    5858#ifndef M_PI_4
    59 const double piOverFourDouble = 0.785398163397448309616;
    60 const float piOverFourFloat = 0.785398163397448309616f;
     59constexpr double piOverFourDouble = 0.785398163397448309616;
     60constexpr float piOverFourFloat = 0.785398163397448309616f;
    6161#else
    62 const double piOverFourDouble = M_PI_4;
    63 const float piOverFourFloat = static_cast<float>(M_PI_4);
     62constexpr double piOverFourDouble = M_PI_4;
     63constexpr float piOverFourFloat = static_cast<float>(M_PI_4);
    6464#endif
    6565
    6666#ifndef M_SQRT2
    67 const double sqrtOfTwoDouble = 1.41421356237309504880;
    68 const float sqrtOfTwoFloat = 1.41421356237309504880f;
     67constexpr double sqrtOfTwoDouble = 1.41421356237309504880;
     68constexpr float sqrtOfTwoFloat = 1.41421356237309504880f;
    6969#else
    70 const double sqrtOfTwoDouble = M_SQRT2;
    71 const float sqrtOfTwoFloat = static_cast<float>(M_SQRT2);
     70constexpr double sqrtOfTwoDouble = M_SQRT2;
     71constexpr float sqrtOfTwoFloat = static_cast<float>(M_SQRT2);
    7272#endif
    7373
     
    101101#endif // COMPILER(MSVC)
    102102
    103 inline double deg2rad(double d)  { return d * piDouble / 180.0; }
    104 inline double rad2deg(double r)  { return r * 180.0 / piDouble; }
    105 inline double deg2grad(double d) { return d * 400.0 / 360.0; }
    106 inline double grad2deg(double g) { return g * 360.0 / 400.0; }
    107 inline double turn2deg(double t) { return t * 360.0; }
    108 inline double deg2turn(double d) { return d / 360.0; }
    109 inline double rad2grad(double r) { return r * 200.0 / piDouble; }
    110 inline double grad2rad(double g) { return g * piDouble / 200.0; }
    111 
    112 inline float deg2rad(float d)  { return d * piFloat / 180.0f; }
    113 inline float rad2deg(float r)  { return r * 180.0f / piFloat; }
    114 inline float deg2grad(float d) { return d * 400.0f / 360.0f; }
    115 inline float grad2deg(float g) { return g * 360.0f / 400.0f; }
    116 inline float turn2deg(float t) { return t * 360.0f; }
    117 inline float deg2turn(float d) { return d / 360.0f; }
    118 inline float rad2grad(float r) { return r * 200.0f / piFloat; }
    119 inline float grad2rad(float g) { return g * piFloat / 200.0f; }
     103constexpr double radiansPerDegreeDouble = piDouble / 180.0;
     104constexpr double degreesPerRadianDouble = 180.0 / piDouble;
     105constexpr double gradientsPerDegreeDouble = 400.0 / 360.0;
     106constexpr double degreesPerGradientDouble = 360.0 / 400.0;
     107constexpr double turnsPerDegreeDouble = 1.0 / 360.0;
     108constexpr double degreesPerTurnDouble = 360.0;
     109
     110constexpr inline double deg2rad(double d)  { return d * radiansPerDegreeDouble; }
     111constexpr inline double rad2deg(double r)  { return r * degreesPerRadianDouble; }
     112constexpr inline double deg2grad(double d) { return d * gradientsPerDegreeDouble; }
     113constexpr inline double grad2deg(double g) { return g * degreesPerGradientDouble; }
     114constexpr inline double deg2turn(double d) { return d * turnsPerDegreeDouble; }
     115constexpr inline double turn2deg(double t) { return t * degreesPerTurnDouble; }
     116
     117
     118// Note that these differ from the casting the double values above in their rounding errors.
     119constexpr float radiansPerDegreeFloat = piFloat / 180.0f;
     120constexpr float degreesPerRadianFloat = 180.0f / piFloat;
     121constexpr float gradientsPerDegreeFloat= 400.0f / 360.0f;
     122constexpr float degreesPerGradientFloat = 360.0f / 400.0f;
     123constexpr float turnsPerDegreeFloat = 1.0f / 360.0f;
     124constexpr float degreesPerTurnFloat = 360.0f;
     125
     126constexpr inline float deg2rad(float d)  { return d * radiansPerDegreeFloat; }
     127constexpr inline float rad2deg(float r)  { return r * degreesPerRadianFloat; }
     128constexpr inline float deg2grad(float d) { return d * gradientsPerDegreeFloat; }
     129constexpr inline float grad2deg(float g) { return g * degreesPerGradientFloat; }
     130constexpr inline float deg2turn(float d) { return d * turnsPerDegreeFloat; }
     131constexpr inline float turn2deg(float t) { return t * degreesPerTurnFloat; }
     132
     133// Treat theses as conversions through the cannonical unit for angles, which is degrees.
     134constexpr inline double rad2grad(double r) { return deg2grad(rad2deg(r)); }
     135constexpr inline double grad2rad(double g) { return deg2rad(grad2deg(g)); }
     136constexpr inline float rad2grad(float r) { return deg2grad(rad2deg(r)); }
     137constexpr inline float grad2rad(float g) { return deg2rad(grad2deg(g)); }
    120138
    121139// std::numeric_limits<T>::min() returns the smallest positive value for floating point types
  • trunk/Source/WebCore/ChangeLog

    r267550 r267551  
     12020-09-24  Keith Miller  <keith_miller@apple.com>
     2
     3        CSS angle unit conversions should consistently use the same associativity
     4        https://bugs.webkit.org/show_bug.cgi?id=216906
     5
     6        Reviewed by Simon Fraser.
     7
     8        Right now we inconsistently associate our floating point math for
     9        angle unit conversions. In particular,
     10        conversionToCanonicalUnitsScaleFactor expects there to be a single
     11        fixed constant we can multiply by to change units. However, the
     12        various conversion functions in WTF are not associated in this
     13        way. e.g.  rad2deg does ((radian * 180) / pi) rather than
     14        (radian * (180 / pi)). Since FP math is NOT associative these
     15        produce different results. For example, 1.57 radians is
     16        89.954373835539258 degrees in the first case but
     17        89.954373835539243 in the second.
     18
     19        This patch changes the WTF functions to operate on a single scale
     20        factor when converting to/from the canonical unit. Conversions
     21        between non-canonical units first convert to the canonical unit
     22        (degree). Also, conversionToCanonicalUnitsScaleFactor now gets the
     23        scale factor from WTF to ensure we get the same associativity
     24        everywhere.
     25
     26        * css/CSSPrimitiveValue.cpp:
     27        (WebCore::CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor):
     28
    1292020-09-24  Fujii Hironori  <Hironori.Fujii@sony.com>
    230
  • trunk/Source/WebCore/css/CSSPrimitiveValue.cpp

    r267154 r267551  
    756756        break;
    757757    case CSSUnitType::CSS_RAD:
    758         factor = 180 / piDouble;
     758        factor = degreesPerRadianDouble;
    759759        break;
    760760    case CSSUnitType::CSS_GRAD:
    761         factor = 0.9;
     761        factor = degreesPerGradientDouble;
    762762        break;
    763763    case CSSUnitType::CSS_TURN:
    764         factor = 360;
     764        factor = degreesPerTurnDouble;
    765765        break;
    766766    case CSSUnitType::CSS_S:
Note: See TracChangeset for help on using the changeset viewer.