Skip to content

Commit e6f020e

Browse files
committed
fix bug: curve-fit generates NaN with straight line.
1 parent 55aa563 commit e6f020e

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

dist/easing-fit.bundle.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ fit = function(func, opt){
8080
j = k$;
8181
ncurve.push([Math.round(((curve[j][0] - x1) / (x2 - x1)) / opt.precision) * opt.precision, Math.round(((curve[j][1] - y1) / (y2 - y1)) / opt.precision) * opt.precision]);
8282
}
83+
if (isNaN(ncurve[1][1])) {
84+
ncurve[1][1] = ncurve[1][0];
85+
}
86+
if (isNaN(ncurve[2][1])) {
87+
ncurve[2][1] = ncurve[2][0];
88+
}
8389
keyframes.push({
8490
percent: round(x1 * 100),
8591
value: y1,

dist/easing-fit.bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/easing-fit.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/easing-fit.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ fit = (func, opt = {}) ->
7070
Math.round(((curve[j].0 - x1) / (x2 - x1)) / opt.precision) * opt.precision,
7171
Math.round(((curve[j].1 - y1) / (y2 - y1)) / opt.precision) * opt.precision
7272
]
73+
# if all y in ps are the same (flat line), then ncurve.*.1 will be NaN.
74+
# simply make it the same with ncurve.*.0 to make a straight line bezier-curve.
75+
if isNaN(ncurve.1.1) => ncurve.1.1 = ncurve.1.0
76+
if isNaN(ncurve.2.1) => ncurve.2.1 = ncurve.2.0
7377
keyframes.push do
7478
percent: round(x1 * 100)
7579
value: y1

0 commit comments

Comments
 (0)