source: node_modules/d3-shape/src/curve/basisClosed.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.5 KB
Line 
1import noop from "../noop.js";
2import {point} from "./basis.js";
3
4function BasisClosed(context) {
5 this._context = context;
6}
7
8BasisClosed.prototype = {
9 areaStart: noop,
10 areaEnd: noop,
11 lineStart: function() {
12 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
13 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
14 this._point = 0;
15 },
16 lineEnd: function() {
17 switch (this._point) {
18 case 1: {
19 this._context.moveTo(this._x2, this._y2);
20 this._context.closePath();
21 break;
22 }
23 case 2: {
24 this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
25 this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
26 this._context.closePath();
27 break;
28 }
29 case 3: {
30 this.point(this._x2, this._y2);
31 this.point(this._x3, this._y3);
32 this.point(this._x4, this._y4);
33 break;
34 }
35 }
36 },
37 point: function(x, y) {
38 x = +x, y = +y;
39 switch (this._point) {
40 case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
41 case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
42 case 2: this._point = 3; this._x4 = x, this._y4 = y; this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6); break;
43 default: point(this, x, y); break;
44 }
45 this._x0 = this._x1, this._x1 = x;
46 this._y0 = this._y1, this._y1 = y;
47 }
48};
49
50export default function(context) {
51 return new BasisClosed(context);
52}
Note: See TracBrowser for help on using the repository browser.