mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Convert react-native-github/Libraries to let/const
Reviewed By: sahrens Differential Revision: D7956042 fbshipit-source-id: 221851aa311f3cdd6326497352b366048db0a1bb
This commit is contained in:
committed by
Facebook Github Bot
parent
266016c521
commit
8f5ebe5952
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var AnimatedImplementation = require('AnimatedImplementation');
|
||||
const AnimatedImplementation = require('AnimatedImplementation');
|
||||
|
||||
module.exports = {
|
||||
...AnimatedImplementation,
|
||||
|
||||
@@ -208,7 +208,7 @@ function validateTransform(configs: Array<Object>): void {
|
||||
}
|
||||
|
||||
function validateStyles(styles: Object): void {
|
||||
for (var key in styles) {
|
||||
for (const key in styles) {
|
||||
if (!STYLES_WHITELIST.hasOwnProperty(key)) {
|
||||
throw new Error(
|
||||
`Style property '${key}' is not supported by native animated module`,
|
||||
@@ -218,7 +218,7 @@ function validateStyles(styles: Object): void {
|
||||
}
|
||||
|
||||
function validateInterpolation(config: Object): void {
|
||||
for (var key in config) {
|
||||
for (const key in config) {
|
||||
if (!SUPPORTED_INTERPOLATION_PARAMS.hasOwnProperty(key)) {
|
||||
throw new Error(
|
||||
`Interpolation property '${key}' is not supported by native animated module`,
|
||||
|
||||
@@ -77,11 +77,11 @@ function fromBouncinessAndSpeed(
|
||||
}
|
||||
}
|
||||
|
||||
var b = normalize(bounciness / 1.7, 0, 20);
|
||||
let b = normalize(bounciness / 1.7, 0, 20);
|
||||
b = projectNormal(b, 0, 0.8);
|
||||
var s = normalize(speed / 1.7, 0, 20);
|
||||
var bouncyTension = projectNormal(s, 0.5, 200);
|
||||
var bouncyFriction = quadraticOutInterpolation(
|
||||
const s = normalize(speed / 1.7, 0, 20);
|
||||
const bouncyTension = projectNormal(s, 0.5, 200);
|
||||
const bouncyFriction = quadraticOutInterpolation(
|
||||
b,
|
||||
b3Nobounce(bouncyTension),
|
||||
0.01
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var Animated = require('Animated');
|
||||
let Animated = require('Animated');
|
||||
describe('Animated tests', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
@@ -17,11 +17,11 @@ describe('Animated tests', () => {
|
||||
describe('Animated', () => {
|
||||
|
||||
it('works end to end', () => {
|
||||
var anim = new Animated.Value(0);
|
||||
const anim = new Animated.Value(0);
|
||||
|
||||
var callback = jest.fn();
|
||||
const callback = jest.fn();
|
||||
|
||||
var node = new Animated.__PropsOnlyForTests({
|
||||
const node = new Animated.__PropsOnlyForTests({
|
||||
style: {
|
||||
backgroundColor: 'red',
|
||||
opacity: anim,
|
||||
@@ -83,10 +83,10 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('does not detach on updates', () => {
|
||||
var anim = new Animated.Value(0);
|
||||
const anim = new Animated.Value(0);
|
||||
anim.__detach = jest.fn();
|
||||
|
||||
var c = new Animated.View();
|
||||
const c = new Animated.View();
|
||||
c.props = {
|
||||
style: {
|
||||
opacity: anim,
|
||||
@@ -109,10 +109,10 @@ describe('Animated tests', () => {
|
||||
|
||||
|
||||
it('stops animation when detached', () => {
|
||||
var anim = new Animated.Value(0);
|
||||
var callback = jest.fn();
|
||||
const anim = new Animated.Value(0);
|
||||
const callback = jest.fn();
|
||||
|
||||
var c = new Animated.View();
|
||||
const c = new Animated.View();
|
||||
c.props = {
|
||||
style: {
|
||||
opacity: anim,
|
||||
@@ -129,31 +129,31 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('triggers callback when spring is at rest', () => {
|
||||
var anim = new Animated.Value(0);
|
||||
var callback = jest.fn();
|
||||
const anim = new Animated.Value(0);
|
||||
const callback = jest.fn();
|
||||
Animated.spring(anim, {toValue: 0, velocity: 0}).start(callback);
|
||||
expect(callback).toBeCalled();
|
||||
});
|
||||
|
||||
it('send toValue when an underdamped spring stops', () => {
|
||||
var anim = new Animated.Value(0);
|
||||
var listener = jest.fn();
|
||||
const anim = new Animated.Value(0);
|
||||
const listener = jest.fn();
|
||||
anim.addListener(listener);
|
||||
Animated.spring(anim, {toValue: 15}).start();
|
||||
jest.runAllTimers();
|
||||
var lastValue = listener.mock.calls[listener.mock.calls.length - 2][0].value;
|
||||
const lastValue = listener.mock.calls[listener.mock.calls.length - 2][0].value;
|
||||
expect(lastValue).not.toBe(15);
|
||||
expect(lastValue).toBeCloseTo(15);
|
||||
expect(anim.__getValue()).toBe(15);
|
||||
});
|
||||
|
||||
it('send toValue when a critically damped spring stops', () => {
|
||||
var anim = new Animated.Value(0);
|
||||
var listener = jest.fn();
|
||||
const anim = new Animated.Value(0);
|
||||
const listener = jest.fn();
|
||||
anim.addListener(listener);
|
||||
Animated.spring(anim, {stiffness: 8000, damping: 2000, toValue: 15}).start();
|
||||
jest.runAllTimers();
|
||||
var lastValue = listener.mock.calls[listener.mock.calls.length - 2][0].value;
|
||||
const lastValue = listener.mock.calls[listener.mock.calls.length - 2][0].value;
|
||||
expect(lastValue).not.toBe(15);
|
||||
expect(lastValue).toBeCloseTo(15);
|
||||
expect(anim.__getValue()).toBe(15);
|
||||
@@ -168,17 +168,17 @@ describe('Animated tests', () => {
|
||||
describe('Animated Sequence', () => {
|
||||
|
||||
it('works with an empty sequence', () => {
|
||||
var cb = jest.fn();
|
||||
const cb = jest.fn();
|
||||
Animated.sequence([]).start(cb);
|
||||
expect(cb).toBeCalledWith({finished: true});
|
||||
});
|
||||
|
||||
it('sequences well', () => {
|
||||
var anim1 = {start: jest.fn()};
|
||||
var anim2 = {start: jest.fn()};
|
||||
var cb = jest.fn();
|
||||
const anim1 = {start: jest.fn()};
|
||||
const anim2 = {start: jest.fn()};
|
||||
const cb = jest.fn();
|
||||
|
||||
var seq = Animated.sequence([anim1, anim2]);
|
||||
const seq = Animated.sequence([anim1, anim2]);
|
||||
|
||||
expect(anim1.start).not.toBeCalled();
|
||||
expect(anim2.start).not.toBeCalled();
|
||||
@@ -199,9 +199,9 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('supports interrupting sequence', () => {
|
||||
var anim1 = {start: jest.fn()};
|
||||
var anim2 = {start: jest.fn()};
|
||||
var cb = jest.fn();
|
||||
const anim1 = {start: jest.fn()};
|
||||
const anim2 = {start: jest.fn()};
|
||||
const cb = jest.fn();
|
||||
|
||||
Animated.sequence([anim1, anim2]).start(cb);
|
||||
|
||||
@@ -213,11 +213,11 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('supports stopping sequence', () => {
|
||||
var anim1 = {start: jest.fn(), stop: jest.fn()};
|
||||
var anim2 = {start: jest.fn(), stop: jest.fn()};
|
||||
var cb = jest.fn();
|
||||
const anim1 = {start: jest.fn(), stop: jest.fn()};
|
||||
const anim2 = {start: jest.fn(), stop: jest.fn()};
|
||||
const cb = jest.fn();
|
||||
|
||||
var seq = Animated.sequence([anim1, anim2]);
|
||||
const seq = Animated.sequence([anim1, anim2]);
|
||||
seq.start(cb);
|
||||
seq.stop();
|
||||
|
||||
@@ -234,10 +234,10 @@ describe('Animated tests', () => {
|
||||
describe('Animated Loop', () => {
|
||||
|
||||
it('loops indefinitely if config not specified', () => {
|
||||
var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
var cb = jest.fn();
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const cb = jest.fn();
|
||||
|
||||
var loop = Animated.loop(animation);
|
||||
const loop = Animated.loop(animation);
|
||||
|
||||
expect(animation.start).not.toBeCalled();
|
||||
|
||||
@@ -261,10 +261,10 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('loops indefinitely if iterations is -1', () => {
|
||||
var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
var cb = jest.fn();
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const cb = jest.fn();
|
||||
|
||||
var loop = Animated.loop(animation, { iterations: -1 });
|
||||
const loop = Animated.loop(animation, { iterations: -1 });
|
||||
|
||||
expect(animation.start).not.toBeCalled();
|
||||
|
||||
@@ -288,10 +288,10 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('loops indefinitely if iterations not specified', () => {
|
||||
var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
var cb = jest.fn();
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const cb = jest.fn();
|
||||
|
||||
var loop = Animated.loop(animation, { anotherKey: 'value' });
|
||||
const loop = Animated.loop(animation, { anotherKey: 'value' });
|
||||
|
||||
expect(animation.start).not.toBeCalled();
|
||||
|
||||
@@ -315,10 +315,10 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('loops three times if iterations is 3', () => {
|
||||
var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
var cb = jest.fn();
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const cb = jest.fn();
|
||||
|
||||
var loop = Animated.loop(animation, { iterations: 3 });
|
||||
const loop = Animated.loop(animation, { iterations: 3 });
|
||||
|
||||
expect(animation.start).not.toBeCalled();
|
||||
|
||||
@@ -342,10 +342,10 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('does not loop if iterations is 1', () => {
|
||||
var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
var cb = jest.fn();
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const cb = jest.fn();
|
||||
|
||||
var loop = Animated.loop(animation, { iterations: 1 });
|
||||
const loop = Animated.loop(animation, { iterations: 1 });
|
||||
|
||||
expect(animation.start).not.toBeCalled();
|
||||
|
||||
@@ -359,10 +359,10 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('does not animate if iterations is 0', () => {
|
||||
var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
var cb = jest.fn();
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const cb = jest.fn();
|
||||
|
||||
var loop = Animated.loop(animation, { iterations: 0 });
|
||||
const loop = Animated.loop(animation, { iterations: 0 });
|
||||
|
||||
expect(animation.start).not.toBeCalled();
|
||||
|
||||
@@ -373,8 +373,8 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('supports interrupting an indefinite loop', () => {
|
||||
var animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
var cb = jest.fn();
|
||||
const animation = {start: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const cb = jest.fn();
|
||||
|
||||
Animated.loop(animation).start(cb);
|
||||
expect(animation.start).toBeCalled();
|
||||
@@ -391,10 +391,10 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('supports stopping loop', () => {
|
||||
var animation = {start: jest.fn(), stop: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
var cb = jest.fn();
|
||||
const animation = {start: jest.fn(), stop: jest.fn(), reset: jest.fn(), _isUsingNativeDriver: () => false};
|
||||
const cb = jest.fn();
|
||||
|
||||
var loop = Animated.loop(animation);
|
||||
const loop = Animated.loop(animation);
|
||||
loop.start(cb);
|
||||
loop.stop();
|
||||
|
||||
@@ -411,14 +411,14 @@ describe('Animated tests', () => {
|
||||
describe('Animated Parallel', () => {
|
||||
|
||||
it('works with an empty parallel', () => {
|
||||
var cb = jest.fn();
|
||||
const cb = jest.fn();
|
||||
Animated.parallel([]).start(cb);
|
||||
expect(cb).toBeCalledWith({finished: true});
|
||||
});
|
||||
|
||||
it('works with an empty element in array', () => {
|
||||
var anim1 = {start: jest.fn()};
|
||||
var cb = jest.fn();
|
||||
const anim1 = {start: jest.fn()};
|
||||
const cb = jest.fn();
|
||||
Animated.parallel([null, anim1]).start(cb);
|
||||
|
||||
expect(anim1.start).toBeCalled();
|
||||
@@ -428,11 +428,11 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('parellelizes well', () => {
|
||||
var anim1 = {start: jest.fn()};
|
||||
var anim2 = {start: jest.fn()};
|
||||
var cb = jest.fn();
|
||||
const anim1 = {start: jest.fn()};
|
||||
const anim2 = {start: jest.fn()};
|
||||
const cb = jest.fn();
|
||||
|
||||
var par = Animated.parallel([anim1, anim2]);
|
||||
const par = Animated.parallel([anim1, anim2]);
|
||||
|
||||
expect(anim1.start).not.toBeCalled();
|
||||
expect(anim2.start).not.toBeCalled();
|
||||
@@ -451,11 +451,11 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('supports stopping parallel', () => {
|
||||
var anim1 = {start: jest.fn(), stop: jest.fn()};
|
||||
var anim2 = {start: jest.fn(), stop: jest.fn()};
|
||||
var cb = jest.fn();
|
||||
const anim1 = {start: jest.fn(), stop: jest.fn()};
|
||||
const anim2 = {start: jest.fn(), stop: jest.fn()};
|
||||
const cb = jest.fn();
|
||||
|
||||
var seq = Animated.parallel([anim1, anim2]);
|
||||
const seq = Animated.parallel([anim1, anim2]);
|
||||
seq.start(cb);
|
||||
seq.stop();
|
||||
|
||||
@@ -472,12 +472,12 @@ describe('Animated tests', () => {
|
||||
|
||||
|
||||
it('does not call stop more than once when stopping', () => {
|
||||
var anim1 = {start: jest.fn(), stop: jest.fn()};
|
||||
var anim2 = {start: jest.fn(), stop: jest.fn()};
|
||||
var anim3 = {start: jest.fn(), stop: jest.fn()};
|
||||
var cb = jest.fn();
|
||||
const anim1 = {start: jest.fn(), stop: jest.fn()};
|
||||
const anim2 = {start: jest.fn(), stop: jest.fn()};
|
||||
const anim3 = {start: jest.fn(), stop: jest.fn()};
|
||||
const cb = jest.fn();
|
||||
|
||||
var seq = Animated.parallel([anim1, anim2, anim3]);
|
||||
const seq = Animated.parallel([anim1, anim2, anim3]);
|
||||
seq.start(cb);
|
||||
|
||||
anim1.start.mock.calls[0][0]({finished: false});
|
||||
@@ -502,8 +502,8 @@ describe('Animated tests', () => {
|
||||
|
||||
describe('Animated delays', () => {
|
||||
it('should call anim after delay in sequence', () => {
|
||||
var anim = {start: jest.fn(), stop: jest.fn()};
|
||||
var cb = jest.fn();
|
||||
const anim = {start: jest.fn(), stop: jest.fn()};
|
||||
const cb = jest.fn();
|
||||
Animated.sequence([
|
||||
Animated.delay(1000),
|
||||
anim,
|
||||
@@ -515,7 +515,7 @@ describe('Animated tests', () => {
|
||||
expect(cb).toBeCalledWith({finished: true});
|
||||
});
|
||||
it('should run stagger to end', () => {
|
||||
var cb = jest.fn();
|
||||
const cb = jest.fn();
|
||||
Animated.stagger(1000, [
|
||||
Animated.delay(1000),
|
||||
Animated.delay(1000),
|
||||
@@ -528,17 +528,17 @@ describe('Animated tests', () => {
|
||||
|
||||
describe('Animated Events', () => {
|
||||
it('should map events', () => {
|
||||
var value = new Animated.Value(0);
|
||||
var handler = Animated.event(
|
||||
const value = new Animated.Value(0);
|
||||
const handler = Animated.event(
|
||||
[null, {state: {foo: value}}],
|
||||
);
|
||||
handler({bar: 'ignoreBar'}, {state: {baz: 'ignoreBaz', foo: 42}});
|
||||
expect(value.__getValue()).toBe(42);
|
||||
});
|
||||
it('should call listeners', () => {
|
||||
var value = new Animated.Value(0);
|
||||
var listener = jest.fn();
|
||||
var handler = Animated.event(
|
||||
const value = new Animated.Value(0);
|
||||
const listener = jest.fn();
|
||||
const handler = Animated.event(
|
||||
[{foo: value}],
|
||||
{listener},
|
||||
);
|
||||
@@ -548,14 +548,14 @@ describe('Animated tests', () => {
|
||||
expect(listener).toBeCalledWith({foo: 42});
|
||||
});
|
||||
it('should call forked event listeners', () => {
|
||||
var value = new Animated.Value(0);
|
||||
var listener = jest.fn();
|
||||
var handler = Animated.event(
|
||||
const value = new Animated.Value(0);
|
||||
const listener = jest.fn();
|
||||
const handler = Animated.event(
|
||||
[{foo: value}],
|
||||
{listener},
|
||||
);
|
||||
var listener2 = jest.fn();
|
||||
var forkedHandler = Animated.forkEvent(handler, listener2);
|
||||
const listener2 = jest.fn();
|
||||
const forkedHandler = Animated.forkEvent(handler, listener2);
|
||||
forkedHandler({foo: 42});
|
||||
expect(value.__getValue()).toBe(42);
|
||||
expect(listener.mock.calls.length).toBe(1);
|
||||
@@ -567,9 +567,9 @@ describe('Animated tests', () => {
|
||||
|
||||
describe('Animated Interactions', () => {
|
||||
/*eslint-disable no-shadow*/
|
||||
var Animated;
|
||||
let Animated;
|
||||
/*eslint-enable*/
|
||||
var InteractionManager;
|
||||
let InteractionManager;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.mock('InteractionManager');
|
||||
@@ -584,8 +584,8 @@ describe('Animated tests', () => {
|
||||
it('registers an interaction by default', () => {
|
||||
InteractionManager.createInteractionHandle.mockReturnValue(777);
|
||||
|
||||
var value = new Animated.Value(0);
|
||||
var callback = jest.fn();
|
||||
const value = new Animated.Value(0);
|
||||
const callback = jest.fn();
|
||||
Animated.timing(value, {
|
||||
toValue: 100,
|
||||
duration: 100,
|
||||
@@ -598,8 +598,8 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('does not register an interaction when specified', () => {
|
||||
var value = new Animated.Value(0);
|
||||
var callback = jest.fn();
|
||||
const value = new Animated.Value(0);
|
||||
const callback = jest.fn();
|
||||
Animated.timing(value, {
|
||||
toValue: 100,
|
||||
duration: 100,
|
||||
@@ -615,8 +615,8 @@ describe('Animated tests', () => {
|
||||
|
||||
describe('Animated Tracking', () => {
|
||||
it('should track values', () => {
|
||||
var value1 = new Animated.Value(0);
|
||||
var value2 = new Animated.Value(0);
|
||||
const value1 = new Animated.Value(0);
|
||||
const value2 = new Animated.Value(0);
|
||||
Animated.timing(value2, {
|
||||
toValue: value1,
|
||||
duration: 0,
|
||||
@@ -628,8 +628,8 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('should track interpolated values', () => {
|
||||
var value1 = new Animated.Value(0);
|
||||
var value2 = new Animated.Value(0);
|
||||
const value1 = new Animated.Value(0);
|
||||
const value2 = new Animated.Value(0);
|
||||
Animated.timing(value2, {
|
||||
toValue: value1.interpolate({
|
||||
inputRange: [0, 2],
|
||||
@@ -642,8 +642,8 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('should stop tracking when animated', () => {
|
||||
var value1 = new Animated.Value(0);
|
||||
var value2 = new Animated.Value(0);
|
||||
const value1 = new Animated.Value(0);
|
||||
const value2 = new Animated.Value(0);
|
||||
Animated.timing(value2, {
|
||||
toValue: value1,
|
||||
duration: 0,
|
||||
@@ -661,11 +661,11 @@ describe('Animated tests', () => {
|
||||
|
||||
describe('Animated Vectors', () => {
|
||||
it('should animate vectors', () => {
|
||||
var vec = new Animated.ValueXY();
|
||||
const vec = new Animated.ValueXY();
|
||||
|
||||
var callback = jest.fn();
|
||||
const callback = jest.fn();
|
||||
|
||||
var node = new Animated.__PropsOnlyForTests({
|
||||
const node = new Animated.__PropsOnlyForTests({
|
||||
style: {
|
||||
opacity: vec.x.interpolate({
|
||||
inputRange: [0, 42],
|
||||
@@ -711,8 +711,8 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('should track vectors', () => {
|
||||
var value1 = new Animated.ValueXY();
|
||||
var value2 = new Animated.ValueXY();
|
||||
const value1 = new Animated.ValueXY();
|
||||
const value2 = new Animated.ValueXY();
|
||||
Animated.timing(value2, {
|
||||
toValue: value1,
|
||||
duration: 0,
|
||||
@@ -727,8 +727,8 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('should track with springs', () => {
|
||||
var value1 = new Animated.ValueXY();
|
||||
var value2 = new Animated.ValueXY();
|
||||
const value1 = new Animated.ValueXY();
|
||||
const value2 = new Animated.ValueXY();
|
||||
Animated.spring(value2, {
|
||||
toValue: value1,
|
||||
tension: 3000, // faster spring for faster test
|
||||
@@ -747,9 +747,9 @@ describe('Animated tests', () => {
|
||||
|
||||
describe('Animated Listeners', () => {
|
||||
it('should get updates', () => {
|
||||
var value1 = new Animated.Value(0);
|
||||
var listener = jest.fn();
|
||||
var id = value1.addListener(listener);
|
||||
const value1 = new Animated.Value(0);
|
||||
const listener = jest.fn();
|
||||
const id = value1.addListener(listener);
|
||||
value1.setValue(42);
|
||||
expect(listener.mock.calls.length).toBe(1);
|
||||
expect(listener).toBeCalledWith({value: 42});
|
||||
@@ -765,8 +765,8 @@ describe('Animated tests', () => {
|
||||
});
|
||||
|
||||
it('should removeAll', () => {
|
||||
var value1 = new Animated.Value(0);
|
||||
var listener = jest.fn();
|
||||
const value1 = new Animated.Value(0);
|
||||
const listener = jest.fn();
|
||||
[1,2,3,4].forEach(() => value1.addListener(listener));
|
||||
value1.setValue(42);
|
||||
expect(listener.mock.calls.length).toBe(4);
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var Easing = require('Easing');
|
||||
const Easing = require('Easing');
|
||||
describe('Easing', () => {
|
||||
it('should work with linear', () => {
|
||||
var easing = Easing.linear;
|
||||
const easing = Easing.linear;
|
||||
|
||||
expect(easing(0)).toBe(0);
|
||||
expect(easing(0.5)).toBe(0.5);
|
||||
@@ -20,7 +20,7 @@ describe('Easing', () => {
|
||||
});
|
||||
|
||||
it('should work with ease in linear', () => {
|
||||
var easing = Easing.in(Easing.linear);
|
||||
const easing = Easing.in(Easing.linear);
|
||||
expect(easing(0)).toBe(0);
|
||||
expect(easing(0.5)).toBe(0.5);
|
||||
expect(easing(0.8)).toBe(0.8);
|
||||
@@ -28,7 +28,7 @@ describe('Easing', () => {
|
||||
});
|
||||
|
||||
it('should work with easy out linear', () => {
|
||||
var easing = Easing.out(Easing.linear);
|
||||
const easing = Easing.out(Easing.linear);
|
||||
expect(easing(0)).toBe(0);
|
||||
expect(easing(0.5)).toBe(0.5);
|
||||
expect(easing(0.6)).toBe(0.6);
|
||||
@@ -39,8 +39,8 @@ describe('Easing', () => {
|
||||
function easeInQuad(t) {
|
||||
return t * t;
|
||||
}
|
||||
var easing = Easing.in(Easing.quad);
|
||||
for (var t = -0.5; t < 1.5; t += 0.1) {
|
||||
const easing = Easing.in(Easing.quad);
|
||||
for (let t = -0.5; t < 1.5; t += 0.1) {
|
||||
expect(easing(t)).toBe(easeInQuad(t));
|
||||
}
|
||||
});
|
||||
@@ -49,8 +49,8 @@ describe('Easing', () => {
|
||||
function easeOutQuad(t) {
|
||||
return -t * (t - 2);
|
||||
}
|
||||
var easing = Easing.out(Easing.quad);
|
||||
for (var t = 0; t <= 1; t += 0.1) {
|
||||
const easing = Easing.out(Easing.quad);
|
||||
for (let t = 0; t <= 1; t += 0.1) {
|
||||
expect(easing(1)).toBe(easeOutQuad(1));
|
||||
}
|
||||
});
|
||||
@@ -63,31 +63,31 @@ describe('Easing', () => {
|
||||
}
|
||||
return -((t - 1) * (t - 3) - 1) / 2;
|
||||
}
|
||||
var easing = Easing.inOut(Easing.quad);
|
||||
for (var t = -0.5; t < 1.5; t += 0.1) {
|
||||
const easing = Easing.inOut(Easing.quad);
|
||||
for (let t = -0.5; t < 1.5; t += 0.1) {
|
||||
expect(easing(t)).toBeCloseTo(easeInOutQuad(t), 4);
|
||||
}
|
||||
});
|
||||
|
||||
it('should satisfy boundary conditions with elastic', () => {
|
||||
for (var b = 0; b < 4; b += 0.3) {
|
||||
var easing = Easing.elastic(b);
|
||||
for (let b = 0; b < 4; b += 0.3) {
|
||||
const easing = Easing.elastic(b);
|
||||
expect(easing(0)).toBe(0);
|
||||
expect(easing(1)).toBe(1);
|
||||
}
|
||||
});
|
||||
|
||||
function sampleEasingFunction(easing) {
|
||||
var DURATION = 300;
|
||||
var tickCount = Math.round(DURATION * 60 / 1000);
|
||||
var samples = [];
|
||||
for (var i = 0; i <= tickCount; i++) {
|
||||
const DURATION = 300;
|
||||
const tickCount = Math.round(DURATION * 60 / 1000);
|
||||
const samples = [];
|
||||
for (let i = 0; i <= tickCount; i++) {
|
||||
samples.push(easing(i / tickCount));
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
var Samples = {
|
||||
const Samples = {
|
||||
in_quad: [0,0.0030864197530864196,0.012345679012345678,0.027777777777777776,0.04938271604938271,0.0771604938271605,0.1111111111111111,0.15123456790123457,0.19753086419753085,0.25,0.308641975308642,0.37345679012345684,0.4444444444444444,0.5216049382716049,0.6049382716049383,0.6944444444444445,0.7901234567901234,0.8919753086419753,1],
|
||||
out_quad: [0,0.10802469135802469,0.20987654320987653,0.3055555555555555,0.3950617283950617,0.47839506172839513,0.5555555555555556,0.6265432098765432,0.691358024691358,0.75,0.8024691358024691,0.8487654320987654,0.888888888888889,0.9228395061728394,0.9506172839506174,0.9722222222222221,0.9876543209876543,0.9969135802469136,1],
|
||||
inOut_quad: [0,0.006172839506172839,0.024691358024691357,0.05555555555555555,0.09876543209876543,0.154320987654321,0.2222222222222222,0.30246913580246915,0.3950617283950617,0.5,0.6049382716049383,0.697530864197531,0.7777777777777777,0.845679012345679,0.9012345679012346,0.9444444444444444,0.9753086419753086,0.9938271604938271,1],
|
||||
@@ -109,13 +109,13 @@ describe('Easing', () => {
|
||||
|
||||
Object.keys(Samples).forEach(function(type) {
|
||||
it('should ease ' + type, function() {
|
||||
var [modeName, easingName, isFunction] = type.split('_');
|
||||
var easing = Easing[easingName];
|
||||
const [modeName, easingName, isFunction] = type.split('_');
|
||||
let easing = Easing[easingName];
|
||||
if (isFunction !== undefined) {
|
||||
easing = easing();
|
||||
}
|
||||
var computed = sampleEasingFunction(Easing[modeName](easing));
|
||||
var samples = Samples[type];
|
||||
const computed = sampleEasingFunction(Easing[modeName](easing));
|
||||
const samples = Samples[type];
|
||||
|
||||
computed.forEach((value, key) => {
|
||||
expect(value).toBeCloseTo(samples[key], 2);
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var AnimatedInterpolation = require('../nodes/AnimatedInterpolation');
|
||||
var Easing = require('Easing');
|
||||
const AnimatedInterpolation = require('../nodes/AnimatedInterpolation');
|
||||
const Easing = require('Easing');
|
||||
|
||||
describe('Interpolation', () => {
|
||||
it('should work with defaults', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 1],
|
||||
outputRange: [0, 1],
|
||||
});
|
||||
@@ -25,7 +25,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with output range', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 1],
|
||||
outputRange: [100, 200],
|
||||
});
|
||||
@@ -37,7 +37,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with input range', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [100, 200],
|
||||
outputRange: [0, 1],
|
||||
});
|
||||
@@ -65,7 +65,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with empty input range', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 10, 10],
|
||||
outputRange: [1, 2, 3],
|
||||
extrapolate: 'extend',
|
||||
@@ -79,7 +79,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with empty output range', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [1, 2, 3],
|
||||
outputRange: [0, 10, 10],
|
||||
extrapolate: 'extend',
|
||||
@@ -94,7 +94,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with easing', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 1],
|
||||
outputRange: [0, 1],
|
||||
easing: Easing.quad,
|
||||
@@ -107,7 +107,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with extrapolate', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
let interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 1],
|
||||
outputRange: [0, 1],
|
||||
extrapolate: 'extend',
|
||||
@@ -139,7 +139,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with keyframes with extrapolate', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 10, 100, 1000],
|
||||
outputRange: [0, 5, 50, 500],
|
||||
extrapolate: true,
|
||||
@@ -157,7 +157,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with keyframes without extrapolate', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 1, 2],
|
||||
outputRange: [0.2, 1, 0.2],
|
||||
extrapolate: 'clamp',
|
||||
@@ -183,7 +183,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with negative infinite', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [-Infinity, 0],
|
||||
outputRange: [-Infinity, 0],
|
||||
easing: Easing.quad,
|
||||
@@ -199,7 +199,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with positive infinite', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [5, Infinity],
|
||||
outputRange: [5, Infinity],
|
||||
easing: Easing.quad,
|
||||
@@ -217,7 +217,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with output ranges as string', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 1],
|
||||
outputRange: ['rgba(0, 100, 200, 0)', 'rgba(50, 150, 250, 0.4)'],
|
||||
});
|
||||
@@ -228,7 +228,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with output ranges as short hex string', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 1],
|
||||
outputRange: ['#024', '#9BF'],
|
||||
});
|
||||
@@ -239,7 +239,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with output ranges as long hex string', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 1],
|
||||
outputRange: ['#FF9500', '#87FC70'],
|
||||
});
|
||||
@@ -250,7 +250,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with output ranges with mixed hex and rgba strings', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 1],
|
||||
outputRange: ['rgba(100, 120, 140, .4)', '#87FC70'],
|
||||
});
|
||||
@@ -261,7 +261,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should work with negative and decimal values in string ranges', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 1],
|
||||
outputRange: ['-100.5deg', '100deg'],
|
||||
});
|
||||
@@ -272,7 +272,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should crash when chaining an interpolation that returns a string', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 1],
|
||||
outputRange: [0, 1],
|
||||
});
|
||||
@@ -282,7 +282,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should support a mix of color patterns', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 1, 2],
|
||||
outputRange: ['rgba(0, 100, 200, 0)', 'rgb(50, 150, 250)', 'red'],
|
||||
});
|
||||
@@ -303,7 +303,7 @@ describe('Interpolation', () => {
|
||||
});
|
||||
|
||||
it('should round the alpha channel of a color to the nearest thousandth', () => {
|
||||
var interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
const interpolation = AnimatedInterpolation.__createInterpolation({
|
||||
inputRange: [0, 1],
|
||||
outputRange: ['rgba(0, 0, 0, 0)', 'rgba(0, 0, 0, 1)'],
|
||||
});
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var bezier = require('bezier');
|
||||
const bezier = require('bezier');
|
||||
|
||||
var identity = function(x) {
|
||||
const identity = function(x) {
|
||||
return x;
|
||||
};
|
||||
|
||||
@@ -30,15 +30,15 @@ function allEquals(be1, be2, samples, assertion) {
|
||||
if (!assertion) {
|
||||
assertion = assertClose;
|
||||
}
|
||||
for (var i = 0; i <= samples; ++i) {
|
||||
var x = i / samples;
|
||||
for (let i = 0; i <= samples; ++i) {
|
||||
const x = i / samples;
|
||||
assertion(be1(x), be2(x));
|
||||
}
|
||||
}
|
||||
|
||||
function repeat(n) {
|
||||
return function(f) {
|
||||
for (var i = 0; i < n; ++i) {
|
||||
for (let i = 0; i < n; ++i) {
|
||||
f(i);
|
||||
}
|
||||
};
|
||||
@@ -74,11 +74,8 @@ describe('bezier', function() {
|
||||
describe('common properties', function() {
|
||||
it('should be the right value at extremes', function() {
|
||||
repeat(10)(function() {
|
||||
var a = Math.random(),
|
||||
b = 2 * Math.random() - 0.5,
|
||||
c = Math.random(),
|
||||
d = 2 * Math.random() - 0.5;
|
||||
var easing = bezier(a, b, c, d);
|
||||
const a = Math.random(), b = 2 * Math.random() - 0.5, c = Math.random(), d = 2 * Math.random() - 0.5;
|
||||
const easing = bezier(a, b, c, d);
|
||||
expect(easing(0)).toBe(0);
|
||||
expect(easing(1)).toBe(1);
|
||||
});
|
||||
@@ -86,13 +83,10 @@ describe('bezier', function() {
|
||||
|
||||
it('should approach the projected value of its x=y projected curve', function() {
|
||||
repeat(10)(function() {
|
||||
var a = Math.random(),
|
||||
b = Math.random(),
|
||||
c = Math.random(),
|
||||
d = Math.random();
|
||||
var easing = bezier(a, b, c, d);
|
||||
var projected = bezier(b, a, d, c);
|
||||
var composed = function(x) {
|
||||
const a = Math.random(), b = Math.random(), c = Math.random(), d = Math.random();
|
||||
const easing = bezier(a, b, c, d);
|
||||
const projected = bezier(b, a, d, c);
|
||||
const composed = function(x) {
|
||||
return projected(easing(x));
|
||||
};
|
||||
allEquals(identity, composed, 100, makeAssertCloseWithPrecision(2));
|
||||
@@ -102,10 +96,7 @@ describe('bezier', function() {
|
||||
describe('two same instances', function() {
|
||||
it('should be strictly equals', function() {
|
||||
repeat(10)(function() {
|
||||
var a = Math.random(),
|
||||
b = 2 * Math.random() - 0.5,
|
||||
c = Math.random(),
|
||||
d = 2 * Math.random() - 0.5;
|
||||
const a = Math.random(), b = 2 * Math.random() - 0.5, c = Math.random(), d = 2 * Math.random() - 0.5;
|
||||
allEquals(bezier(a, b, c, d), bezier(a, b, c, d), 100, 0);
|
||||
});
|
||||
});
|
||||
@@ -113,22 +104,16 @@ describe('bezier', function() {
|
||||
describe('symetric curves', function() {
|
||||
it('should have a central value y~=0.5 at x=0.5', function() {
|
||||
repeat(10)(function() {
|
||||
var a = Math.random(),
|
||||
b = 2 * Math.random() - 0.5,
|
||||
c = 1 - a,
|
||||
d = 1 - b;
|
||||
var easing = bezier(a, b, c, d);
|
||||
const a = Math.random(), b = 2 * Math.random() - 0.5, c = 1 - a, d = 1 - b;
|
||||
const easing = bezier(a, b, c, d);
|
||||
assertClose(easing(0.5), 0.5, 2);
|
||||
});
|
||||
});
|
||||
it('should be symmetrical', function() {
|
||||
repeat(10)(function() {
|
||||
var a = Math.random(),
|
||||
b = 2 * Math.random() - 0.5,
|
||||
c = 1 - a,
|
||||
d = 1 - b;
|
||||
var easing = bezier(a, b, c, d);
|
||||
var sym = function(x) {
|
||||
const a = Math.random(), b = 2 * Math.random() - 0.5, c = 1 - a, d = 1 - b;
|
||||
const easing = bezier(a, b, c, d);
|
||||
const sym = function(x) {
|
||||
return 1 - easing(1 - x);
|
||||
};
|
||||
allEquals(easing, sym, 100, makeAssertCloseWithPrecision(2));
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
'use strict';
|
||||
|
||||
// These values are established by empiricism with tests (tradeoff: performance VS precision)
|
||||
var NEWTON_ITERATIONS = 4;
|
||||
var NEWTON_MIN_SLOPE = 0.001;
|
||||
var SUBDIVISION_PRECISION = 0.0000001;
|
||||
var SUBDIVISION_MAX_ITERATIONS = 10;
|
||||
const NEWTON_ITERATIONS = 4;
|
||||
const NEWTON_MIN_SLOPE = 0.001;
|
||||
const SUBDIVISION_PRECISION = 0.0000001;
|
||||
const SUBDIVISION_MAX_ITERATIONS = 10;
|
||||
|
||||
var kSplineTableSize = 11;
|
||||
var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
|
||||
const kSplineTableSize = 11;
|
||||
const kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
|
||||
|
||||
var float32ArraySupported = typeof Float32Array === 'function';
|
||||
const float32ArraySupported = typeof Float32Array === 'function';
|
||||
|
||||
function A (aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
|
||||
function B (aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }
|
||||
@@ -29,7 +29,7 @@
|
||||
function getSlope (aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); }
|
||||
|
||||
function binarySubdivide (aX, aA, aB, mX1, mX2) {
|
||||
var currentX, currentT, i = 0;
|
||||
let currentX, currentT, i = 0;
|
||||
do {
|
||||
currentT = aA + (aB - aA) / 2.0;
|
||||
currentX = calcBezier(currentT, mX1, mX2) - aX;
|
||||
@@ -43,12 +43,12 @@
|
||||
}
|
||||
|
||||
function newtonRaphsonIterate (aX, aGuessT, mX1, mX2) {
|
||||
for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
|
||||
var currentSlope = getSlope(aGuessT, mX1, mX2);
|
||||
for (let i = 0; i < NEWTON_ITERATIONS; ++i) {
|
||||
const currentSlope = getSlope(aGuessT, mX1, mX2);
|
||||
if (currentSlope === 0.0) {
|
||||
return aGuessT;
|
||||
}
|
||||
var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
|
||||
const currentX = calcBezier(aGuessT, mX1, mX2) - aX;
|
||||
aGuessT -= currentX / currentSlope;
|
||||
}
|
||||
return aGuessT;
|
||||
@@ -60,17 +60,17 @@
|
||||
}
|
||||
|
||||
// Precompute samples table
|
||||
var sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
|
||||
const sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
|
||||
if (mX1 !== mY1 || mX2 !== mY2) {
|
||||
for (var i = 0; i < kSplineTableSize; ++i) {
|
||||
for (let i = 0; i < kSplineTableSize; ++i) {
|
||||
sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
|
||||
}
|
||||
}
|
||||
|
||||
function getTForX (aX) {
|
||||
var intervalStart = 0.0;
|
||||
var currentSample = 1;
|
||||
var lastSample = kSplineTableSize - 1;
|
||||
let intervalStart = 0.0;
|
||||
let currentSample = 1;
|
||||
const lastSample = kSplineTableSize - 1;
|
||||
|
||||
for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) {
|
||||
intervalStart += kSampleStepSize;
|
||||
@@ -78,10 +78,10 @@
|
||||
--currentSample;
|
||||
|
||||
// Interpolate to provide an initial guess for t
|
||||
var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
|
||||
var guessForT = intervalStart + dist * kSampleStepSize;
|
||||
const dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
|
||||
const guessForT = intervalStart + dist * kSampleStepSize;
|
||||
|
||||
var initialSlope = getSlope(guessForT, mX1, mX2);
|
||||
const initialSlope = getSlope(guessForT, mX1, mX2);
|
||||
if (initialSlope >= NEWTON_MIN_SLOPE) {
|
||||
return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
|
||||
} else if (initialSlope === 0.0) {
|
||||
|
||||
Reference in New Issue
Block a user