| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.CardinalClosed = CardinalClosed;
|
|---|
| 7 | exports.default = void 0;
|
|---|
| 8 | var _noop = _interopRequireDefault(require("../noop.js"));
|
|---|
| 9 | var _cardinal = require("./cardinal.js");
|
|---|
| 10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|---|
| 11 | function CardinalClosed(context, tension) {
|
|---|
| 12 | this._context = context;
|
|---|
| 13 | this._k = (1 - tension) / 6;
|
|---|
| 14 | }
|
|---|
| 15 | CardinalClosed.prototype = {
|
|---|
| 16 | areaStart: _noop.default,
|
|---|
| 17 | areaEnd: _noop.default,
|
|---|
| 18 | lineStart: function () {
|
|---|
| 19 | this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 = this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
|
|---|
| 20 | this._point = 0;
|
|---|
| 21 | },
|
|---|
| 22 | lineEnd: function () {
|
|---|
| 23 | switch (this._point) {
|
|---|
| 24 | case 1:
|
|---|
| 25 | {
|
|---|
| 26 | this._context.moveTo(this._x3, this._y3);
|
|---|
| 27 | this._context.closePath();
|
|---|
| 28 | break;
|
|---|
| 29 | }
|
|---|
| 30 | case 2:
|
|---|
| 31 | {
|
|---|
| 32 | this._context.lineTo(this._x3, this._y3);
|
|---|
| 33 | this._context.closePath();
|
|---|
| 34 | break;
|
|---|
| 35 | }
|
|---|
| 36 | case 3:
|
|---|
| 37 | {
|
|---|
| 38 | this.point(this._x3, this._y3);
|
|---|
| 39 | this.point(this._x4, this._y4);
|
|---|
| 40 | this.point(this._x5, this._y5);
|
|---|
| 41 | break;
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 | },
|
|---|
| 45 | point: function (x, y) {
|
|---|
| 46 | x = +x, y = +y;
|
|---|
| 47 | switch (this._point) {
|
|---|
| 48 | case 0:
|
|---|
| 49 | this._point = 1;
|
|---|
| 50 | this._x3 = x, this._y3 = y;
|
|---|
| 51 | break;
|
|---|
| 52 | case 1:
|
|---|
| 53 | this._point = 2;
|
|---|
| 54 | this._context.moveTo(this._x4 = x, this._y4 = y);
|
|---|
| 55 | break;
|
|---|
| 56 | case 2:
|
|---|
| 57 | this._point = 3;
|
|---|
| 58 | this._x5 = x, this._y5 = y;
|
|---|
| 59 | break;
|
|---|
| 60 | default:
|
|---|
| 61 | (0, _cardinal.point)(this, x, y);
|
|---|
| 62 | break;
|
|---|
| 63 | }
|
|---|
| 64 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
|---|
| 65 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
|---|
| 66 | }
|
|---|
| 67 | };
|
|---|
| 68 | var _default = exports.default = function custom(tension) {
|
|---|
| 69 | function cardinal(context) {
|
|---|
| 70 | return new CardinalClosed(context, tension);
|
|---|
| 71 | }
|
|---|
| 72 | cardinal.tension = function (tension) {
|
|---|
| 73 | return custom(+tension);
|
|---|
| 74 | };
|
|---|
| 75 | return cardinal;
|
|---|
| 76 | }(0); |
|---|