-
Notifications
You must be signed in to change notification settings - Fork 0
/
interval.js
121 lines (110 loc) · 3.3 KB
/
interval.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
class Interval {
constructor(y1, y2, parent) {
if (y1 > y2) {
let pom = y1;
y1 = y2;
y2 = pom;
}
this.start = new IntervalEdge('start', y1, this);
this.end = new IntervalEdge('end', y2, this);
this.parent = parent;
this.projection = null;
}
contains(queryPoint) {
if (this.start.getPosition() - queryPoint > Number.EPSILON) // start is below v
return -1;
if (this.end.getPosition() - queryPoint < -Number.EPSILON) // end is iznad v
return 1;
return 0;
}
static compare(a, b) {
console.log("a");
console.log(a);
console.log("b");
console.log(b);
if (a === b) {
console.log("A === B");
return 0;
}
var res1 = 1;
var res0 = -1;
var x = -1;
var deviation = -1;
if (a.projection === 'left') {
res1 = -1;
res0 = 1;
}
if (a.contains(b.getStart().getPosition()) === 0) {
console.log("a sadrzi b.start");
x = a.parent.getXForY(b.getStart().getPosition());
deviation = x - b.getParent().getTopx();
if (deviation < -0.001) {
console.log(res1 + "**");
return res1;
}
if (deviation > 0.001) {
console.log(res0 + "**");
return res0;
}
}
if (a.contains(b.getEnd().getPosition()) === 0) {
console.log("a sadrzi b.end");
x = a.parent.getXForY(b.getEnd().getPosition());
deviation = x - b.getParent().getBottomx();
if (deviation < -0.001) {
console.log(res1 + "***");
return res1;
}
if (deviation > 0.001) {
console.log(res0 + "***");
return res0;
}
}
if (b.contains(a.getStart().getPosition()) === 0) {
console.log("b sadrzi a.start");
x = b.parent.getXForY(a.getStart().getPosition());
deviation = x - a.getParent().getTopx();
if (deviation < -0.001) {
console.log(res0 + "****");
return res0;
}
if (deviation > 0.001) {
console.log(res1 + "****");
return res1;
}
}
if (b.contains(a.getEnd().getPosition()) === 0) {
console.log("b sadrzi a.end");
x = b.parent.getXForY(a.getEnd().getPosition());
deviation = x - a.getParent().getBottomx();
if (deviation < -0.001) {
console.log(res0 + "*****");
return res0;
}
if (deviation > 0.001) {
console.log(res1 + "*****");
return res1;
}
}
if (a.end.getPosition() - b.end.getPosition() > 0.01) {
console.log(res0 + "-");
return res0;
}
return res1;
}
getProjection() {
return this.projection;
}
getParent() {
return this.parent;
}
setProjection(projection) {
this.projection = projection;
}
getStart() {
return this.start;
}
getEnd() {
return this.end;
}
}