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

projection, half moulding

This commit is contained in:
Pomax
2020-08-30 17:08:43 -07:00
parent 10148f46b1
commit e6608d65af
72 changed files with 448 additions and 251 deletions

View File

@@ -32,7 +32,7 @@ function getABC(n, S, B, E, t) {
x: B.x + (B.x - C.x) / s,
y: B.y + (B.y - C.y) / s,
};
return { A: A, B: B, C: C };
return { A, B, C };
}
/**
@@ -238,6 +238,15 @@ class Bezier {
return utils.length(this.derivative.bind(this));
}
getABC(t, B) {
let S = this.points[0];
let E = this.points[this.order];
let ret = getABC(this.order, S, B || this.get(t), E, t);
ret.S = S;
ret.E = E;
return ret;
}
getLUT(steps) {
this.verify();
steps = steps || 100;
@@ -248,8 +257,11 @@ class Bezier {
// We want a range from 0 to 1 inclusive, so
// we decrement and then use <= rather than <:
steps--;
for (let t = 0; t <= steps; t++) {
this._lut.push(this.compute(t / steps));
for (let i = 0, p, t; i < steps; i++) {
t = i / (steps - 1);
p = this.compute(t);
p.t = t;
this._lut.push(p);
}
return this._lut;
}

View File

@@ -90,12 +90,14 @@ const utils = {
compute: function (t, points, _3d) {
// shortcuts
if (t === 0) {
points[0].t = 0;
return points[0];
}
const order = points.length - 1;
if (t === 1) {
points[order].t = 1;
return points[order];
}
@@ -104,6 +106,7 @@ const utils = {
// constant?
if (order === 0) {
points[0].t = t;
return points[0];
}
@@ -112,6 +115,7 @@ const utils = {
const ret = {
x: mt * p[0].x + t * p[1].x,
y: mt * p[0].y + t * p[1].y,
t: t,
};
if (_3d) {
ret.z = mt * p[0].z + t * p[1].z;
@@ -141,6 +145,7 @@ const utils = {
const ret = {
x: a * p[0].x + b * p[1].x + c * p[2].x + d * p[3].x,
y: a * p[0].y + b * p[1].y + c * p[2].y + d * p[3].y,
t: t,
};
if (_3d) {
ret.z = a * p[0].z + b * p[1].z + c * p[2].z + d * p[3].z;
@@ -162,6 +167,7 @@ const utils = {
}
dCpts.splice(dCpts.length - 1, 1);
}
dCpts[0].t = t;
return dCpts[0];
},
@@ -186,6 +192,7 @@ const utils = {
x: (f1 * p[0].x + f2 * p[1].x) / d,
y: (f1 * p[0].y + f2 * p[1].y) / d,
z: !_3d ? false : (f1 * p[0].z + f2 * p[1].z) / d,
t: t,
};
}
@@ -200,6 +207,7 @@ const utils = {
x: (f1 * p[0].x + f2 * p[1].x + f3 * p[2].x) / d,
y: (f1 * p[0].y + f2 * p[1].y + f3 * p[2].y) / d,
z: !_3d ? false : (f1 * p[0].z + f2 * p[1].z + f3 * p[2].z) / d,
t: t,
};
}
@@ -217,6 +225,7 @@ const utils = {
z: !_3d
? false
: (f1 * p[0].z + f2 * p[1].z + f3 * p[2].z + f4 * p[3].z) / d,
t: t,
};
}
},