vislite
Version:
灵活、快速、简单的数据可视化交互式跨端前端库
38 lines (36 loc) • 1.21 kB
JavaScript
var Hermite = (function () {
function Hermite(u) {
if (u === void 0) { u = 0.5; }
this.name = 'Hermite';
this.__u = u;
}
Hermite.prototype.setP = function (x1, y1, x2, y2, s1, s2) {
if (x1 < x2) {
this.__a = x1;
this.__b = x2;
var p3 = this.__u * s1, p4 = this.__u * s2;
y1 /= (x2 - x1);
y2 /= (x2 - x1);
this.__MR = [
2 * y1 - 2 * y2 + p3 + p4,
3 * y2 - 3 * y1 - 2 * p3 - p4,
p3,
y1
];
}
else
throw new Error('The point x-position should be increamented!');
return this;
};
Hermite.prototype.use = function (x) {
if (this.__MR) {
var sx = (x - this.__a) / (this.__b - this.__a), sx2 = sx * sx, sx3 = sx * sx2;
var sResult = sx3 * this.__MR[0] + sx2 * this.__MR[1] + sx * this.__MR[2] + this.__MR[3];
return sResult * (this.__b - this.__a);
}
else
throw new Error('You shoud first set the position!');
};
return Hermite;
}());
export { Hermite as default };