Skip to content

Commit

Permalink
Remove semicolons
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Aug 6, 2020
1 parent 6e0af94 commit 8c33d79
Show file tree
Hide file tree
Showing 15 changed files with 1,004 additions and 1,011 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"plugins": ["jest", "prettier"],
"rules": {
"linebreak-style": ["error", "unix"],
"semi": ["error", "always"],
"valid-jsdoc": [
"error",
{
Expand Down
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
86 changes: 43 additions & 43 deletions src/bezier.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tweenable } from './tweenable';
import { Tweenable } from './tweenable'

/**
* The Bezier magic in this file is adapted/copied almost wholesale from
Expand Down Expand Up @@ -55,78 +55,78 @@ function cubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
cx = 0,
ay = 0,
by = 0,
cy = 0;
cy = 0

const sampleCurveX = t => ((ax * t + bx) * t + cx) * t;
const sampleCurveX = t => ((ax * t + bx) * t + cx) * t

const sampleCurveY = t => ((ay * t + by) * t + cy) * t;
const sampleCurveY = t => ((ay * t + by) * t + cy) * t

const sampleCurveDerivativeX = t => (3 * ax * t + 2 * bx) * t + cx;
const sampleCurveDerivativeX = t => (3 * ax * t + 2 * bx) * t + cx

const solveEpsilon = duration => 1 / (200 * duration);
const solveEpsilon = duration => 1 / (200 * duration)

const fabs = n => (n >= 0 ? n : 0 - n);
const fabs = n => (n >= 0 ? n : 0 - n)

const solveCurveX = (x, epsilon) => {
let t0, t1, t2, x2, d2, i;
let t0, t1, t2, x2, d2, i

for (t2 = x, i = 0; i < 8; i++) {
x2 = sampleCurveX(t2) - x;
x2 = sampleCurveX(t2) - x

if (fabs(x2) < epsilon) {
return t2;
return t2
}

d2 = sampleCurveDerivativeX(t2);
d2 = sampleCurveDerivativeX(t2)

if (fabs(d2) < 1e-6) {
break;
break
}

t2 = t2 - x2 / d2;
t2 = t2 - x2 / d2
}

t0 = 0;
t1 = 1;
t2 = x;
t0 = 0
t1 = 1
t2 = x

if (t2 < t0) {
return t0;
return t0
}

if (t2 > t1) {
return t1;
return t1
}

while (t0 < t1) {
x2 = sampleCurveX(t2);
x2 = sampleCurveX(t2)

if (fabs(x2 - x) < epsilon) {
return t2;
return t2
}

if (x > x2) {
t0 = t2;
t0 = t2
} else {
t1 = t2;
t1 = t2
}

t2 = (t1 - t0) * 0.5 + t0;
t2 = (t1 - t0) * 0.5 + t0
}

return t2; // Failure.
};
return t2 // Failure.
}

const solve = (x, epsilon) => sampleCurveY(solveCurveX(x, epsilon));
const solve = (x, epsilon) => sampleCurveY(solveCurveX(x, epsilon))

cx = 3 * p1x;
bx = 3 * (p2x - p1x) - cx;
ax = 1 - cx - bx;
cy = 3 * p1y;
by = 3 * (p2y - p1y) - cy;
ay = 1 - cy - by;
cx = 3 * p1x
bx = 3 * (p2x - p1x) - cx
ax = 1 - cx - bx
cy = 3 * p1y
by = 3 * (p2y - p1y) - cy
ay = 1 - cy - by

return solve(t, solveEpsilon(duration));
return solve(t, solveEpsilon(duration))
}
// End ported code

Expand All @@ -148,7 +148,7 @@ function cubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
* @private
*/
const getCubicBezierTransition = (x1, y1, x2, y2) => pos =>
cubicBezierAtTime(pos, x1, y1, x2, y2, 1);
cubicBezierAtTime(pos, x1, y1, x2, y2, 1)

/**
* Create a Bezier easing function and attach it to {@link
Expand All @@ -166,16 +166,16 @@ const getCubicBezierTransition = (x1, y1, x2, y2) => pos =>
* attached to {@link shifty.Tweenable.formulas}.
*/
export const setBezierFunction = (name, x1, y1, x2, y2) => {
const cubicBezierTransition = getCubicBezierTransition(x1, y1, x2, y2);
const cubicBezierTransition = getCubicBezierTransition(x1, y1, x2, y2)

cubicBezierTransition.displayName = name;
cubicBezierTransition.x1 = x1;
cubicBezierTransition.y1 = y1;
cubicBezierTransition.x2 = x2;
cubicBezierTransition.y2 = y2;
cubicBezierTransition.displayName = name
cubicBezierTransition.x1 = x1
cubicBezierTransition.y1 = y1
cubicBezierTransition.x2 = x2
cubicBezierTransition.y2 = y2

return (Tweenable.formulas[name] = cubicBezierTransition);
};
return (Tweenable.formulas[name] = cubicBezierTransition)
}

/**
* `delete` an easing function from {@link shifty.Tweenable.formulas}. Be
Expand All @@ -185,4 +185,4 @@ export const setBezierFunction = (name, x1, y1, x2, y2) => {
* @param {string} name The name of the easing function to delete.
* @return {boolean} Whether or not the functions was `delete`d.
*/
export const unsetBezierFunction = name => delete Tweenable.formulas[name];
export const unsetBezierFunction = name => delete Tweenable.formulas[name]
44 changes: 22 additions & 22 deletions src/bezier.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,47 @@ import {
interpolate,
setBezierFunction,
unsetBezierFunction,
} from './';
} from './'

test('can create a linear bezier easing curve', () => {
setBezierFunction('bezier-linear', 0.25, 0.25, 0.75, 0.75);
setBezierFunction('bezier-linear', 0.25, 0.25, 0.75, 0.75)

expect(interpolate({ x: 0 }, { x: 10 }, 0.25, 'linear').x.toFixed(1)).toEqual(
interpolate({ x: 0 }, { x: 10 }, 0.25, 'bezier-linear').x.toFixed(1)
);
)
expect(interpolate({ x: 0 }, { x: 10 }, 0.5, 'linear').x.toFixed(1)).toEqual(
interpolate({ x: 0 }, { x: 10 }, 0.5, 'bezier-linear').x.toFixed(1)
);
)
expect(interpolate({ x: 0 }, { x: 10 }, 0.75, 'linear').x.toFixed(1)).toEqual(
interpolate({ x: 0 }, { x: 10 }, 0.75, 'bezier-linear').x.toFixed(1)
);
});
)
})

test('can create a "stretched" linear bezier easing curve', () => {
setBezierFunction('bezier-stretched-linear', 0, 0, 1, 1);
setBezierFunction('bezier-stretched-linear', 0, 0, 1, 1)

expect(interpolate({ x: 0 }, { x: 10 }, 0.25, 'linear').x.toFixed(1)).toEqual(
interpolate({ x: 0 }, { x: 10 }, 0.25, 'bezier-stretched-linear').x.toFixed(
1
)
);
)
expect(interpolate({ x: 0 }, { x: 10 }, 0.5, 'linear').x.toFixed(1)).toEqual(
interpolate({ x: 0 }, { x: 10 }, 0.5, 'bezier-stretched-linear').x.toFixed(
1
)
);
)
expect(interpolate({ x: 0 }, { x: 10 }, 0.75, 'linear').x.toFixed(1)).toEqual(
interpolate({ x: 0 }, { x: 10 }, 0.75, 'bezier-stretched-linear').x.toFixed(
1
)
);
});
)
})

test('can remove a bezier easing curve', () => {
setBezierFunction('bezier-linear', 0, 0, 1, 1);
unsetBezierFunction('bezier-linear');
expect(!Tweenable.prototype['bezier-linear']).toBeTruthy();
});
setBezierFunction('bezier-linear', 0, 0, 1, 1)
unsetBezierFunction('bezier-linear')
expect(!Tweenable.prototype['bezier-linear']).toBeTruthy()
})

test('bezier handle positions are stored on a custom easing function', () => {
const easingFunction = setBezierFunction(
Expand All @@ -52,11 +52,11 @@ test('bezier handle positions are stored on a custom easing function', () => {
0.4,
0.6,
0.8
);
)

expect(easingFunction.displayName).toEqual('decoration-test');
expect(easingFunction.x1).toEqual(0.2);
expect(easingFunction.y1).toEqual(0.4);
expect(easingFunction.x2).toEqual(0.6);
expect(easingFunction.y2).toEqual(0.8);
});
expect(easingFunction.displayName).toEqual('decoration-test')
expect(easingFunction.x1).toEqual(0.2)
expect(easingFunction.y1).toEqual(0.4)
expect(easingFunction.x2).toEqual(0.6)
expect(easingFunction.y2).toEqual(0.8)
})
Loading

0 comments on commit 8c33d79

Please sign in to comment.