1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | exports.isBezierCurve = exports.BezierCurve = void 0;
|
---|
4 | var vector_1 = require("./vector");
|
---|
5 | var lerp = function (a, b, t) {
|
---|
6 | return new vector_1.Vector(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t);
|
---|
7 | };
|
---|
8 | var BezierCurve = /** @class */ (function () {
|
---|
9 | function BezierCurve(start, startControl, endControl, end) {
|
---|
10 | this.type = 1 /* BEZIER_CURVE */;
|
---|
11 | this.start = start;
|
---|
12 | this.startControl = startControl;
|
---|
13 | this.endControl = endControl;
|
---|
14 | this.end = end;
|
---|
15 | }
|
---|
16 | BezierCurve.prototype.subdivide = function (t, firstHalf) {
|
---|
17 | var ab = lerp(this.start, this.startControl, t);
|
---|
18 | var bc = lerp(this.startControl, this.endControl, t);
|
---|
19 | var cd = lerp(this.endControl, this.end, t);
|
---|
20 | var abbc = lerp(ab, bc, t);
|
---|
21 | var bccd = lerp(bc, cd, t);
|
---|
22 | var dest = lerp(abbc, bccd, t);
|
---|
23 | return firstHalf ? new BezierCurve(this.start, ab, abbc, dest) : new BezierCurve(dest, bccd, cd, this.end);
|
---|
24 | };
|
---|
25 | BezierCurve.prototype.add = function (deltaX, deltaY) {
|
---|
26 | return new BezierCurve(this.start.add(deltaX, deltaY), this.startControl.add(deltaX, deltaY), this.endControl.add(deltaX, deltaY), this.end.add(deltaX, deltaY));
|
---|
27 | };
|
---|
28 | BezierCurve.prototype.reverse = function () {
|
---|
29 | return new BezierCurve(this.end, this.endControl, this.startControl, this.start);
|
---|
30 | };
|
---|
31 | return BezierCurve;
|
---|
32 | }());
|
---|
33 | exports.BezierCurve = BezierCurve;
|
---|
34 | var isBezierCurve = function (path) { return path.type === 1 /* BEZIER_CURVE */; };
|
---|
35 | exports.isBezierCurve = isBezierCurve;
|
---|
36 | //# sourceMappingURL=bezier-curve.js.map |
---|