mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-09-02 21:02:49 +02:00
t-value control
This commit is contained in:
@@ -159,12 +159,20 @@ function computeBestFit(P, M, S, n) {
|
||||
}
|
||||
|
||||
function fit(points, mode) {
|
||||
// mode could be an int index to fit.modes, below,
|
||||
// which are used to abstract time values, OR it
|
||||
// could be a prespecified array of time values to
|
||||
// be used in the final curve fitting step.
|
||||
var TS;
|
||||
if (mode instanceof Array) {
|
||||
TS = mode;
|
||||
mode = false;
|
||||
}
|
||||
mode = mode || 0;
|
||||
console.log("mode: ", mode);
|
||||
var n = points.length,
|
||||
P = Array.from(points),
|
||||
M = computeBasisMatrix(n),
|
||||
S = computeTimeValues[fit.modes[mode]](P, n),
|
||||
S = TS || computeTimeValues[fit.modes[mode]](P, n),
|
||||
C = computeBestFit(P, M, S, n);
|
||||
return { n, P, M, S, C };
|
||||
}
|
||||
|
@@ -2382,6 +2382,7 @@ return {
|
||||
|
||||
toggle: function() {
|
||||
if (this.api) {
|
||||
this.customTimeValues = false;
|
||||
this.mode = (this.mode + 1) % fit.modes.length;
|
||||
this.fitCurve(this.api);
|
||||
this.api.redraw();
|
||||
@@ -2395,22 +2396,33 @@ return {
|
||||
api.drawGrid(10,10);
|
||||
|
||||
api.setColor('black');
|
||||
|
||||
if (!this.curveset && this.points.length > 2) {
|
||||
this.fitCurve(api);
|
||||
curve = this.fitCurve(api);
|
||||
}
|
||||
|
||||
if (curve) {
|
||||
api.drawCurve(curve);
|
||||
api.drawSkeleton(curve);
|
||||
}
|
||||
|
||||
api.drawPoints(this.points);
|
||||
|
||||
api.setFill(0);
|
||||
api.text("using "+fit.modes[this.mode]+" t values", {x: 5, y: 10});
|
||||
if (!this.customTimeValues) {
|
||||
api.setFill(0);
|
||||
api.text("using "+fit.modes[this.mode]+" t values", {x: 5, y: 10});
|
||||
}
|
||||
},
|
||||
|
||||
fitCurve(api) {
|
||||
let bestFitData = fit(this.points, this.mode),
|
||||
processTimeUpdate(sliderid, timeValues) {
|
||||
var api = this.api;
|
||||
this.customTimeValues = true;
|
||||
this.fitCurve(api, timeValues);
|
||||
api.redraw();
|
||||
},
|
||||
|
||||
fitCurve(api, timeValues) {
|
||||
let bestFitData = fit(this.points, timeValues || this.mode),
|
||||
x = bestFitData.C.x,
|
||||
y = bestFitData.C.y,
|
||||
bpoints = [];
|
||||
@@ -2423,6 +2435,8 @@ return {
|
||||
var curve = new api.Bezier(bpoints);
|
||||
api.setCurve(curve);
|
||||
this.curveset = true;
|
||||
this.sliders.setOptions(bestFitData.S);
|
||||
return curve;
|
||||
},
|
||||
|
||||
onClick: function(evt, api) {
|
||||
|
Reference in New Issue
Block a user