source: node_modules/victory-vendor/lib-vendor/d3-shape/src/curve/catmullRom.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 2.8 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7exports.point = point;
8var _math = require("../math.js");
9var _cardinal = require("./cardinal.js");
10function point(that, x, y) {
11 var x1 = that._x1,
12 y1 = that._y1,
13 x2 = that._x2,
14 y2 = that._y2;
15 if (that._l01_a > _math.epsilon) {
16 var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
17 n = 3 * that._l01_a * (that._l01_a + that._l12_a);
18 x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
19 y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
20 }
21 if (that._l23_a > _math.epsilon) {
22 var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
23 m = 3 * that._l23_a * (that._l23_a + that._l12_a);
24 x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
25 y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
26 }
27 that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
28}
29function CatmullRom(context, alpha) {
30 this._context = context;
31 this._alpha = alpha;
32}
33CatmullRom.prototype = {
34 areaStart: function () {
35 this._line = 0;
36 },
37 areaEnd: function () {
38 this._line = NaN;
39 },
40 lineStart: function () {
41 this._x0 = this._x1 = this._x2 = this._y0 = this._y1 = this._y2 = NaN;
42 this._l01_a = this._l12_a = this._l23_a = this._l01_2a = this._l12_2a = this._l23_2a = this._point = 0;
43 },
44 lineEnd: function () {
45 switch (this._point) {
46 case 2:
47 this._context.lineTo(this._x2, this._y2);
48 break;
49 case 3:
50 this.point(this._x2, this._y2);
51 break;
52 }
53 if (this._line || this._line !== 0 && this._point === 1) this._context.closePath();
54 this._line = 1 - this._line;
55 },
56 point: function (x, y) {
57 x = +x, y = +y;
58 if (this._point) {
59 var x23 = this._x2 - x,
60 y23 = this._y2 - y;
61 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
62 }
63 switch (this._point) {
64 case 0:
65 this._point = 1;
66 this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y);
67 break;
68 case 1:
69 this._point = 2;
70 break;
71 case 2:
72 this._point = 3;
73 // falls through
74 default:
75 point(this, x, y);
76 break;
77 }
78 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
79 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
80 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
81 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
82 }
83};
84var _default = exports.default = function custom(alpha) {
85 function catmullRom(context) {
86 return alpha ? new CatmullRom(context, alpha) : new _cardinal.Cardinal(context, 0);
87 }
88 catmullRom.alpha = function (alpha) {
89 return custom(+alpha);
90 };
91 return catmullRom;
92}(0.5);
Note: See TracBrowser for help on using the repository browser.