source: node_modules/d3-delaunay/src/path.js@ e4c61dd

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

Prototype 1.1

  • Property mode set to 100644
File size: 1.1 KB
Line 
1const epsilon = 1e-6;
2
3export default class Path {
4 constructor() {
5 this._x0 = this._y0 = // start of current subpath
6 this._x1 = this._y1 = null; // end of current subpath
7 this._ = "";
8 }
9 moveTo(x, y) {
10 this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
11 }
12 closePath() {
13 if (this._x1 !== null) {
14 this._x1 = this._x0, this._y1 = this._y0;
15 this._ += "Z";
16 }
17 }
18 lineTo(x, y) {
19 this._ += `L${this._x1 = +x},${this._y1 = +y}`;
20 }
21 arc(x, y, r) {
22 x = +x, y = +y, r = +r;
23 const x0 = x + r;
24 const y0 = y;
25 if (r < 0) throw new Error("negative radius");
26 if (this._x1 === null) this._ += `M${x0},${y0}`;
27 else if (Math.abs(this._x1 - x0) > epsilon || Math.abs(this._y1 - y0) > epsilon) this._ += "L" + x0 + "," + y0;
28 if (!r) return;
29 this._ += `A${r},${r},0,1,1,${x - r},${y}A${r},${r},0,1,1,${this._x1 = x0},${this._y1 = y0}`;
30 }
31 rect(x, y, w, h) {
32 this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${+w}v${+h}h${-w}Z`;
33 }
34 value() {
35 return this._ || null;
36 }
37}
Note: See TracBrowser for help on using the repository browser.