Skip to content

Commit 83c9090

Browse files
committed
Increase Bezier timing function accuracy
The polyfill evaluation of cubic Bezier timing functions gives slightly different results than the native Blink implementation. In my testing, this change reduced the absolute error by 63% while only increasing the number of cubic function evaluations by 31% This closes #139
1 parent fb701cb commit 83c9090

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/timing-utilities.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
var mid = (start + end) / 2;
169169
function f(a, b, m) { return 3 * a * (1 - m) * (1 - m) * m + 3 * b * (1 - m) * m * m + m * m * m};
170170
var xEst = f(a, c, mid);
171-
if (Math.abs(x - xEst) < 0.001) {
171+
if (Math.abs(x - xEst) < 0.0001) {
172172
return f(b, d, mid);
173173
}
174174
if (xEst < x) {

test/js/timing-utilities.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ suite('timing-utilities', function() {
2323
var f = toTimingFunction('ease');
2424
var g = toTimingFunction('cubic-bezier(.25, 0.1, 0.25, 1.0)');
2525
assertTimingFunctionsEqual(f, g, 'ease should map onto preset cubic-bezier');
26-
assert.closeTo(f(0.1844), 0.2601, 0.01);
27-
assert.closeTo(g(0.1844), 0.2601, 0.01);
26+
assert.closeTo(f(0.1844), 0.2599, 0.001);
27+
assert.closeTo(g(0.1844), 0.2599, 0.001);
2828
assert.equal(f(0), 0);
2929
assert.equal(f(1), 1);
3030
assert.equal(g(0), 0);
3131
assert.equal(g(1), 1);
3232

3333
f = toTimingFunction('cubic-bezier(0, 1, 1, 0)');
34-
assert.closeTo(f(0.104), 0.392, 0.01);
34+
assert.closeTo(f(0.104), 0.3920, 0.001);
3535

3636
function assertIsLinear(easing) {
3737
var f = toTimingFunction(easing);

0 commit comments

Comments
 (0)