| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = void 0;
|
|---|
| 7 | var _cardinalOpen = require("./cardinalOpen.js");
|
|---|
| 8 | var _catmullRom = require("./catmullRom.js");
|
|---|
| 9 | function CatmullRomOpen(context, alpha) {
|
|---|
| 10 | this._context = context;
|
|---|
| 11 | this._alpha = alpha;
|
|---|
| 12 | }
|
|---|
| 13 | CatmullRomOpen.prototype = {
|
|---|
| 14 | areaStart: function () {
|
|---|
| 15 | this._line = 0;
|
|---|
| 16 | },
|
|---|
| 17 | areaEnd: function () {
|
|---|
| 18 | this._line = NaN;
|
|---|
| 19 | },
|
|---|
| 20 | lineStart: function () {
|
|---|
| 21 | this._x0 = this._x1 = this._x2 = this._y0 = this._y1 = this._y2 = NaN;
|
|---|
| 22 | this._l01_a = this._l12_a = this._l23_a = this._l01_2a = this._l12_2a = this._l23_2a = this._point = 0;
|
|---|
| 23 | },
|
|---|
| 24 | lineEnd: function () {
|
|---|
| 25 | if (this._line || this._line !== 0 && this._point === 3) this._context.closePath();
|
|---|
| 26 | this._line = 1 - this._line;
|
|---|
| 27 | },
|
|---|
| 28 | point: function (x, y) {
|
|---|
| 29 | x = +x, y = +y;
|
|---|
| 30 | if (this._point) {
|
|---|
| 31 | var x23 = this._x2 - x,
|
|---|
| 32 | y23 = this._y2 - y;
|
|---|
| 33 | this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
|
|---|
| 34 | }
|
|---|
| 35 | switch (this._point) {
|
|---|
| 36 | case 0:
|
|---|
| 37 | this._point = 1;
|
|---|
| 38 | break;
|
|---|
| 39 | case 1:
|
|---|
| 40 | this._point = 2;
|
|---|
| 41 | break;
|
|---|
| 42 | case 2:
|
|---|
| 43 | this._point = 3;
|
|---|
| 44 | this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2);
|
|---|
| 45 | break;
|
|---|
| 46 | case 3:
|
|---|
| 47 | this._point = 4;
|
|---|
| 48 | // falls through
|
|---|
| 49 | default:
|
|---|
| 50 | (0, _catmullRom.point)(this, x, y);
|
|---|
| 51 | break;
|
|---|
| 52 | }
|
|---|
| 53 | this._l01_a = this._l12_a, this._l12_a = this._l23_a;
|
|---|
| 54 | this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
|
|---|
| 55 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
|---|
| 56 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
|---|
| 57 | }
|
|---|
| 58 | };
|
|---|
| 59 | var _default = exports.default = function custom(alpha) {
|
|---|
| 60 | function catmullRom(context) {
|
|---|
| 61 | return alpha ? new CatmullRomOpen(context, alpha) : new _cardinalOpen.CardinalOpen(context, 0);
|
|---|
| 62 | }
|
|---|
| 63 | catmullRom.alpha = function (alpha) {
|
|---|
| 64 | return custom(+alpha);
|
|---|
| 65 | };
|
|---|
| 66 | return catmullRom;
|
|---|
| 67 | }(0.5); |
|---|