Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fixed curvePoint and curveTangent ignoring curveTightness #5638

Merged
merged 4 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -3018,6 +3018,15 @@
"bug"
]
},
{
"login": "sparshg",
"name": "sparshg",
"avatar_url": "https://avatars.githubusercontent.com/u/43041139?v=4",
"profile": "https://sparshg.github.io",
"contributions": [
"bug"
]
},
{
"login": "liz-peng",
"name": "Liz Peng",
Expand Down
24 changes: 13 additions & 11 deletions src/core/shape/curves.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,13 @@ p5.prototype.curveTightness = function(t) {
*/
p5.prototype.curvePoint = function(a, b, c, d, t) {
p5._validateParameters('curvePoint', arguments);

const t3 = t * t * t,
const s = this._renderer._curveTightness,
t3 = t * t * t,
t2 = t * t,
f1 = -0.5 * t3 + t2 - 0.5 * t,
f2 = 1.5 * t3 - 2.5 * t2 + 1.0,
f3 = -1.5 * t3 + 2.0 * t2 + 0.5 * t,
f4 = 0.5 * t3 - 0.5 * t2;
f1 = (s - 1) / 2 * t3 + (1 - s) * t2 + (s - 1) / 2 * t,
f2 = (s + 3) / 2 * t3 + (-5 - s) / 2 * t2 + 1.0,
f3 = (-3 - s) / 2 * t3 + (s + 2) * t2 + (1 - s) / 2 * t,
f4 = (1 - s) / 2 * t3 + (s - 1) / 2 * t2;
return a * f1 + b * f2 + c * f3 + d * f4;
};

Expand Down Expand Up @@ -529,11 +529,13 @@ p5.prototype.curvePoint = function(a, b, c, d, t) {
p5.prototype.curveTangent = function(a, b, c, d, t) {
p5._validateParameters('curveTangent', arguments);

const t2 = t * t,
f1 = -3 * t2 / 2 + 2 * t - 0.5,
f2 = 9 * t2 / 2 - 5 * t,
f3 = -9 * t2 / 2 + 4 * t + 0.5,
f4 = 3 * t2 / 2 - t;
const s = this._renderer._curveTightness,
tt3 = t * t * 3,
t2 = t * 2,
f1 = (s - 1) / 2 * tt3 + (1 - s) * t2 + (s - 1) / 2,
f2 = (s + 3) / 2 * tt3 + (-5 - s) / 2 * t2,
f3 = (-3 - s) / 2 * tt3 + (s + 2) * t2 + (1 - s) / 2,
f4 = (1 - s) / 2 * tt3 + (s - 1) / 2 * t2;
return a * f1 + b * f2 + c * f3 + d * f4;
};

Expand Down