source: node_modules/d3-shape/src/curve/catmullRomOpen.js

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

Prototype 1.1

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[e4c61dd]1import {CardinalOpen} from "./cardinalOpen.js";
2import {point} from "./catmullRom.js";
3
4function CatmullRomOpen(context, alpha) {
5 this._context = context;
6 this._alpha = alpha;
7}
8
9CatmullRomOpen.prototype = {
10 areaStart: function() {
11 this._line = 0;
12 },
13 areaEnd: function() {
14 this._line = NaN;
15 },
16 lineStart: function() {
17 this._x0 = this._x1 = this._x2 =
18 this._y0 = this._y1 = this._y2 = NaN;
19 this._l01_a = this._l12_a = this._l23_a =
20 this._l01_2a = this._l12_2a = this._l23_2a =
21 this._point = 0;
22 },
23 lineEnd: function() {
24 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
25 this._line = 1 - this._line;
26 },
27 point: function(x, y) {
28 x = +x, y = +y;
29
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
36 switch (this._point) {
37 case 0: this._point = 1; break;
38 case 1: this._point = 2; break;
39 case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
40 case 3: this._point = 4; // falls through
41 default: point(this, x, y); break;
42 }
43
44 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
45 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
46 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
47 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
48 }
49};
50
51export default (function custom(alpha) {
52
53 function catmullRom(context) {
54 return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
55 }
56
57 catmullRom.alpha = function(alpha) {
58 return custom(+alpha);
59 };
60
61 return catmullRom;
62})(0.5);
Note: See TracBrowser for help on using the repository browser.