Skip to content

Commit

Permalink
fix(🐛): Make getYForX() robust to x value outside the graph
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon authored Oct 9, 2020
1 parent 3bd75eb commit b959959
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ export const interpolatePath = (
/**
* @summary Interpolate two paths with an animation value that goes from 0 to 1
*/

export const mixPath = (
value: number,
p1: Path,
Expand Down Expand Up @@ -298,7 +297,7 @@ export const getYForX = (path: Path, x: number) => {
}
return false;
});
if (isCurve(p[0])) {
if (p.length > 0 && isCurve(p[0])) {
return cubicBezierYForX(x, p[0].from, p[0].c1, p[0].c2, p[0].to);
}
return 0;
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/Paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test("getYForX()", () => {
);
expect(getYForX(p1, 200)).toBe(75);
expect(getYForX(p1, 50)).toBe(151.1683950839424);
expect(getYForX(p1, 750)).toBe(0);
});

test("getYForX2()", () => {
Expand Down

0 comments on commit b959959

Please sign in to comment.