1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-09-01 12:23:19 +02:00

curve fitting and assorted fixes

This commit is contained in:
Pomax
2018-06-19 21:03:58 -07:00
parent 0fec6be56f
commit a16142ab4a
41 changed files with 9989 additions and 299 deletions

View File

@@ -2356,6 +2356,64 @@ return {
api.drawCurve(curve);
}
}
};
}())
},
"curvefitting": {
handler: (function() { var fit = require('../../../lib/curve-fitter.js');
return {
setup: function(api) {
this.api = api;
this.reset();
},
reset: function() {
this.points = [];
this.curveset = false;
let api = this.api;
if (api) {
api.setCurve(false);
api.reset();
api.redraw();
}
},
draw: function(api, curve) {
api.setPanelCount(1);
api.reset();
api.setColor('lightgrey');
api.drawGrid(10,10);
api.setColor('black');
if (!this.curveset && this.points.length > 2) {
let bestFitData = fit(this.points),
x = bestFitData.C.x,
y = bestFitData.C.y,
bpoints = [];
x.forEach((r,i) => {
bpoints.push({
x: r[0],
y: y[i][0]
});
});
curve = new api.Bezier(bpoints);
api.setCurve(curve);
this.curveset = true;
}
if (curve) {
api.drawCurve(curve);
api.drawSkeleton(curve);
}
api.drawPoints(this.points);
},
onClick: function(evt, api) {
this.curveset = false;
this.points.push({x: api.mx, y: api.my });
api.redraw();
}
};
}())
},