Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

贝塞尔点计算时的阶乘尾调用优化 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bezierMaker.js
Original file line number Diff line number Diff line change
@@ -21,8 +21,8 @@ BezierMaker.prototype.bezier = function(t) { //贝塞尔公式调用
x += item.x * Math.pow(( 1 - t ), n - index) * Math.pow(t, index)
y += item.y * Math.pow(( 1 - t ), n - index) * Math.pow(t, index)
} else {
x += self.factorial(n) / self.factorial(index) / self.factorial(n - index) * item.x * Math.pow(( 1 - t ), n - index) * Math.pow(t, index)
y += self.factorial(n) / self.factorial(index) / self.factorial(n - index) * item.y * Math.pow(( 1 - t ), n - index) * Math.pow(t, index)
x += self.factorial(n, 1) / self.factorial(index, 1) / self.factorial(n - index, 1) * item.x * Math.pow(( 1 - t ), n - index) * Math.pow(t, index)
y += self.factorial(n, 1) / self.factorial(index, 1) / self.factorial(n - index, 1) * item.y * Math.pow(( 1 - t ), n - index) * Math.pow(t, index)
}
})
return {
@@ -80,10 +80,10 @@ BezierMaker.prototype.drawBezier = function() { //通过控制点算出实时xy
}

}
BezierMaker.prototype.factorial = function(num) { //递归阶乘
BezierMaker.prototype.factorial = function(num, total) { //递归阶乘
if (num <= 1) {
return 1;
return total;
} else {
return num * this.factorial(num - 1);
return this.factorial(num - 1, num * total);
}
}