UNPKG

986 BJavaScriptView Raw
1export default class svgline {
2
3 constructor(x1, y1, x2, y2) {
4 this.x1 = x1;
5 this.y1 = y1;
6 this.x2 = x2;
7 this.y2 = y2;
8 }
9
10 getX1() {
11 return this.x1;
12 }
13
14 getY1() {
15 return this.y1;
16 }
17
18 getX2() {
19 return this.x2;
20 }
21
22 getY2() {
23 return this.y2;
24 }
25
26 mergeLine(x1, y1, x2, y2) {
27 if (x1 == x2 && this.x1 == this.x2 && x1 == this.x1) {
28 if (y2 >= this.y1 - 1 && y1 <= this.y2 + 1) {
29 this.y1 = Math.min(this.y1, y1);
30 this.y2 = Math.max(this.y2, y2);
31 return true;
32 }
33 } else if (y1 == y2 && this.y1 == this.y2 && y1 == this.y1) {
34 if (x2 >= this.x1 - 1 && x1 <= this.x2 + 1) {
35 this.x1 = Math.min(this.x1, x1);
36 this.x2 = Math.max(this.x2, x2);
37 return true;
38 }
39 }
40 return false;
41 }
42
43}
\No newline at end of file