Title: [284725] trunk
Revision
284725
Author
[email protected]
Date
2021-10-22 16:21:57 -0700 (Fri, 22 Oct 2021)

Log Message

Integer interpolation in animations should be rounded towards positive infinity, not away from zero.
https://bugs.webkit.org/show_bug.cgi?id=232013

Currently, interpolation of <integer> is rounding away from 0.
The interpolation's result should be rounded according to the spec,
https://drafts.csswg.org/css-values-4/#combine-integers, which is

"the result is converted to an <integer> by rounding
to the nearest integer, with values halfway between
adjacent integers rounded towards positive infinity."

LayoutTests/imported/w3c:

Patch by Joonghun Park <[email protected]> on 2021-10-22
Reviewed by Darin Adler.

* web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_order-expected.txt: Added.
* web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_order.html: Added.
* web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_z_index-expected.txt: Added.
* web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_z_index.html: Added.

Source/WebCore:

This patch also removes redundant static_cast<double>s
and potential overflow(e.g.'to' is the maximum integer and 'from' is
the minimum integer) from blend in AnimationUtilities.h.

Patch by Joonghun Park <[email protected]> on 2021-10-22
Reviewed by Darin Adler.

Tests: animations/animation-order-overflow.html
       animations/animation-z-order-overflow.html
       imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_order.html
       imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_z_index.html

* platform/animation/AnimationUtilities.h:
(WebCore::blend):

Source/WTF:

Patch by Joonghun Park <[email protected]> on 2021-10-22
Reviewed by Darin Adler.

* wtf/MathExtras.h:
(roundTowardsPositiveInfinity):

LayoutTests:

This patch also removes redundant static_cast<double>s
and potential overflow(e.g.'to' is the maximum integer and 'from' is
the minimum integer) from blend in AnimationUtilities.h.

Patch by Joonghun Park <[email protected]> on 2021-10-22
Reviewed by Darin Adler.

* animations/animation-order-overflow-expected.txt: Added.
* animations/animation-order-overflow.html: Added.
* animations/animation-z-order-overflow-expected.txt: Added.
* animations/animation-z-order-overflow.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (284724 => 284725)


--- trunk/LayoutTests/ChangeLog	2021-10-22 23:20:28 UTC (rev 284724)
+++ trunk/LayoutTests/ChangeLog	2021-10-22 23:21:57 UTC (rev 284725)
@@ -1,3 +1,27 @@
+2021-10-22  Joonghun Park  <[email protected]>
+
+        Integer interpolation in animations should be rounded towards positive infinity, not away from zero.
+        https://bugs.webkit.org/show_bug.cgi?id=232013
+
+        Currently, interpolation of <integer> is rounding away from 0.
+        The interpolation's result should be rounded according to the spec,
+        https://drafts.csswg.org/css-values-4/#combine-integers, which is
+
+        "the result is converted to an <integer> by rounding
+        to the nearest integer, with values halfway between
+        adjacent integers rounded towards positive infinity."
+
+        This patch also removes redundant static_cast<double>s
+        and potential overflow(e.g.'to' is the maximum integer and 'from' is
+        the minimum integer) from blend in AnimationUtilities.h.
+
+        Reviewed by Darin Adler.
+
+        * animations/animation-order-overflow-expected.txt: Added.
+        * animations/animation-order-overflow.html: Added.
+        * animations/animation-z-order-overflow-expected.txt: Added.
+        * animations/animation-z-order-overflow.html: Added.
+
 2021-10-22  Chris Dumez  <[email protected]>
 
         Regression (r284610?): [ iOS BigSur wk2 ]imported/w3c/web-platform-tests/html/cross-origin-opener-policy/coop-csp-sandbox.https.html is a flaky failure

Added: trunk/LayoutTests/animations/animation-order-overflow-expected.txt (0 => 284725)


--- trunk/LayoutTests/animations/animation-order-overflow-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/animations/animation-order-overflow-expected.txt	2021-10-22 23:21:57 UTC (rev 284725)
@@ -0,0 +1,3 @@
+
+PASS Integer interpolation should be rounded towards positive infinity
+

Added: trunk/LayoutTests/animations/animation-order-overflow.html (0 => 284725)


--- trunk/LayoutTests/animations/animation-order-overflow.html	                        (rev 0)
+++ trunk/LayoutTests/animations/animation-order-overflow.html	2021-10-22 23:21:57 UTC (rev 284725)
@@ -0,0 +1,38 @@
+<!doctype html>
+<title>Testing if integer interpolation is overflowed for 32bit integer type min/max value</title>
+<link rel="author" title="Joonghun Park" href=""
+<script src=""
+<script src=""
+<style>
+
+#flex-container {
+    display: flex;
+    animation: anim-order 4s steps(4) forwards 1;
+    animation-delay: -3s;
+    animation-play-state: paused;
+}
+
+@keyframes anim-order {
+  from {
+    order: -2147483647;
+  }
+
+  to {
+    order: 2147483647;
+  }
+}
+
+</style>
+<div id="flex-container"></div>
+<script>
+var test_description = "Integer interpolation should be rounded towards positive infinity";
+test(
+    t => {
+        const container = document.getElementById("flex-container");
+        const order_value = Number.parseFloat(getComputedStyle(container).getPropertyValue('order'));
+
+        assert_greater_than(order_value, 0, "Interpolation result for z-index should be positive integer");
+    },
+    test_description
+);
+</script>

Added: trunk/LayoutTests/animations/animation-z-order-overflow-expected.txt (0 => 284725)


--- trunk/LayoutTests/animations/animation-z-order-overflow-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/animations/animation-z-order-overflow-expected.txt	2021-10-22 23:21:57 UTC (rev 284725)
@@ -0,0 +1,3 @@
+
+PASS Integer interpolation should be rounded towards positive infinity
+

Added: trunk/LayoutTests/animations/animation-z-order-overflow.html (0 => 284725)


--- trunk/LayoutTests/animations/animation-z-order-overflow.html	                        (rev 0)
+++ trunk/LayoutTests/animations/animation-z-order-overflow.html	2021-10-22 23:21:57 UTC (rev 284725)
@@ -0,0 +1,37 @@
+<!doctype html>
+<title>Testing if integer interpolation is overflowed for 32bit integer type min/max value</title>
+<link rel="author" title="Joonghun Park" href=""
+<script src=""
+<script src=""
+<style>
+
+#anim-target {
+  animation: anim-z 4s steps(4) forwards 1;
+  animation-delay: -3s;
+  animation-play-state: paused;
+}
+
+@keyframes anim-z {
+  from {
+    z-index: -2147483647;
+  }
+
+  to {
+    z-index: 2147483647;
+  }
+}
+
+</style>
+<div id="anim-target"></div>
+<script>
+var test_description = "Integer interpolation should be rounded towards positive infinity";
+test(
+    t => {
+        const target = document.getElementById("anim-target");
+        const z_index_value = Number.parseFloat(getComputedStyle(target).getPropertyValue('z-index'));
+
+        assert_greater_than(z_index_value, 0, "Interpolation result for z-index should be positive integer");
+    },
+    test_description
+);
+</script>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (284724 => 284725)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-22 23:20:28 UTC (rev 284724)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-22 23:21:57 UTC (rev 284725)
@@ -1,3 +1,23 @@
+2021-10-22  Joonghun Park  <[email protected]>
+
+        Integer interpolation in animations should be rounded towards positive infinity, not away from zero.
+        https://bugs.webkit.org/show_bug.cgi?id=232013
+
+        Currently, interpolation of <integer> is rounding away from 0.
+        The interpolation's result should be rounded according to the spec,
+        https://drafts.csswg.org/css-values-4/#combine-integers, which is
+
+        "the result is converted to an <integer> by rounding
+        to the nearest integer, with values halfway between
+        adjacent integers rounded towards positive infinity."
+
+        Reviewed by Darin Adler.
+
+        * web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_order-expected.txt: Added.
+        * web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_order.html: Added.
+        * web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_z_index-expected.txt: Added.
+        * web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_z_index.html: Added.
+
 2021-10-22  Chris Dumez  <[email protected]>
 
         Regression (r284610?): [ iOS BigSur wk2 ]imported/w3c/web-platform-tests/html/cross-origin-opener-policy/coop-csp-sandbox.https.html is a flaky failure

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_order-expected.txt (0 => 284725)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_order-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_order-expected.txt	2021-10-22 23:21:57 UTC (rev 284725)
@@ -0,0 +1,3 @@
+
+PASS Integer interpolation should be rounded towards positive infinity
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_order.html (0 => 284725)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_order.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_order.html	2021-10-22 23:21:57 UTC (rev 284725)
@@ -0,0 +1,39 @@
+<!doctype html>
+<title>Testing if integer interpolation is rounded towards positive infinity</title>
+<link rel="author" title="Joonghun Park" href=""
+<link rel="help" href=""
+<script src=""
+<script src=""
+<style>
+
+#flex-container {
+    display: flex;
+    animation: anim-order 4s steps(4) forwards 1;
+    animation-delay: -1s;
+    animation-play-state: paused;
+}
+
+@keyframes anim-order {
+  from {
+    order: -2;
+  }
+
+  to {
+    order: 0;
+  }
+}
+
+</style>
+<div id="flex-container"></div>
+<script>
+var test_description = "Integer interpolation should be rounded towards positive infinity";
+test(
+    t => {
+        const container = document.getElementById("flex-container");
+        const order_value = Number.parseFloat(getComputedStyle(container).getPropertyValue('order'));
+
+        assert_equals(order_value, -1, "Interpolation result for order should be rounded towards positive infinity");
+    },
+    test_description
+);
+</script>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_z_index-expected.txt (0 => 284725)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_z_index-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_z_index-expected.txt	2021-10-22 23:21:57 UTC (rev 284725)
@@ -0,0 +1,3 @@
+
+PASS Integer interpolation should be rounded towards positive infinity
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_z_index.html (0 => 284725)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_z_index.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_z_index.html	2021-10-22 23:21:57 UTC (rev 284725)
@@ -0,0 +1,38 @@
+<!doctype html>
+<title>Testing if integer interpolation is rounded towards positive infinity</title>
+<link rel="author" title="Joonghun Park" href=""
+<link rel="help" href=""
+<script src=""
+<script src=""
+<style>
+
+#anim-target {
+  animation: anim-z 4s steps(4) forwards 1;
+  animation-delay: -1s;
+  animation-play-state: paused;
+}
+
+@keyframes anim-z {
+  from {
+    z-index: -2;
+  }
+
+  to {
+    z-index: 0;
+  }
+}
+
+</style>
+<div id="anim-target"></div>
+<script>
+var test_description = "Integer interpolation should be rounded towards positive infinity";
+test(
+    t => {
+        const target = document.getElementById("anim-target");
+        const z_index_value = Number.parseFloat(getComputedStyle(target).getPropertyValue('z-index'));
+
+        assert_equals(z_index_value, -1, "Interpolation result for z-index should be rounded towards positive infinity");
+    },
+    test_description
+);
+</script>

Modified: trunk/Source/WTF/ChangeLog (284724 => 284725)


--- trunk/Source/WTF/ChangeLog	2021-10-22 23:20:28 UTC (rev 284724)
+++ trunk/Source/WTF/ChangeLog	2021-10-22 23:21:57 UTC (rev 284725)
@@ -1,3 +1,21 @@
+2021-10-22  Joonghun Park  <[email protected]>
+
+        Integer interpolation in animations should be rounded towards positive infinity, not away from zero.
+        https://bugs.webkit.org/show_bug.cgi?id=232013
+
+        Currently, interpolation of <integer> is rounding away from 0.
+        The interpolation's result should be rounded according to the spec,
+        https://drafts.csswg.org/css-values-4/#combine-integers, which is
+
+        "the result is converted to an <integer> by rounding
+        to the nearest integer, with values halfway between
+        adjacent integers rounded towards positive infinity."
+
+        Reviewed by Darin Adler.
+
+        * wtf/MathExtras.h:
+        (roundTowardsPositiveInfinity):
+
 2021-10-22  Pablo Correa Gómez  <[email protected]>
 
         Enable logging in under non-systemd linux distros

Modified: trunk/Source/WTF/wtf/MathExtras.h (284724 => 284725)


--- trunk/Source/WTF/wtf/MathExtras.h	2021-10-22 23:20:28 UTC (rev 284724)
+++ trunk/Source/WTF/wtf/MathExtras.h	2021-10-22 23:21:57 UTC (rev 284725)
@@ -136,6 +136,9 @@
 constexpr inline float rad2grad(float r) { return deg2grad(rad2deg(r)); }
 constexpr inline float grad2rad(float g) { return deg2rad(grad2deg(g)); }
 
+inline double roundTowardsPositiveInfinity(double value) { return std::floor(value + 0.5); }
+inline float roundTowardsPositiveInfinity(float value) { return std::floor(value + 0.5f); }
+
 // std::numeric_limits<T>::min() returns the smallest positive value for floating point types
 template<typename T> constexpr T defaultMinimumForClamp() { return std::numeric_limits<T>::min(); }
 template<> constexpr float defaultMinimumForClamp() { return -std::numeric_limits<float>::max(); }

Modified: trunk/Source/WebCore/ChangeLog (284724 => 284725)


--- trunk/Source/WebCore/ChangeLog	2021-10-22 23:20:28 UTC (rev 284724)
+++ trunk/Source/WebCore/ChangeLog	2021-10-22 23:21:57 UTC (rev 284725)
@@ -1,3 +1,30 @@
+2021-10-22  Joonghun Park  <[email protected]>
+
+        Integer interpolation in animations should be rounded towards positive infinity, not away from zero.
+        https://bugs.webkit.org/show_bug.cgi?id=232013
+
+        Currently, interpolation of <integer> is rounding away from 0.
+        The interpolation's result should be rounded according to the spec,
+        https://drafts.csswg.org/css-values-4/#combine-integers, which is
+
+        "the result is converted to an <integer> by rounding
+        to the nearest integer, with values halfway between
+        adjacent integers rounded towards positive infinity."
+
+        This patch also removes redundant static_cast<double>s
+        and potential overflow(e.g.'to' is the maximum integer and 'from' is
+        the minimum integer) from blend in AnimationUtilities.h.
+
+        Reviewed by Darin Adler.
+
+        Tests: animations/animation-order-overflow.html
+               animations/animation-z-order-overflow.html
+               imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_order.html
+               imported/w3c/web-platform-tests/css/css-values/integer_interpolation_round_half_towards_positive_infinity_z_index.html
+
+        * platform/animation/AnimationUtilities.h:
+        (WebCore::blend):
+
 2021-10-22  Kiet Ho  <[email protected]>
 
         Rename ClipPathOperation to PathOperation

Modified: trunk/Source/WebCore/platform/animation/AnimationUtilities.h (284724 => 284725)


--- trunk/Source/WebCore/platform/animation/AnimationUtilities.h	2021-10-22 23:20:28 UTC (rev 284724)
+++ trunk/Source/WebCore/platform/animation/AnimationUtilities.h	2021-10-22 23:21:57 UTC (rev 284725)
@@ -45,13 +45,13 @@
 };
 
 inline int blend(int from, int to, const BlendingContext& context)
-{  
-    return static_cast<int>(lround(static_cast<double>(from) + static_cast<double>(to - from) * context.progress));
+{
+    return static_cast<int>(roundTowardsPositiveInfinity(from + (static_cast<double>(to) - from) * context.progress));
 }
 
 inline unsigned blend(unsigned from, unsigned to, const BlendingContext& context)
 {
-    return static_cast<unsigned>(lround(to > from ? static_cast<double>(from) + static_cast<double>(to - from) * context.progress : static_cast<double>(from) - static_cast<double>(from - to) * context.progress));
+    return static_cast<unsigned>(lround(to > from ? from + (static_cast<double>(to) - from) * context.progress : from - (static_cast<double>(from) - to) * context.progress));
 }
 
 inline double blend(double from, double to, const BlendingContext& context)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to