-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathEdge.js
45 lines (39 loc) · 991 Bytes
/
Edge.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
class Edge { //section of road that connects nodes
constructor(from_, to_, wayid_) {
this.wayid = wayid_;
this.from = from_;
this.to = to_;
this.travels = 0;
this.distance = calcdistance(this.from.lat, this.from.lon, this.to.lat, this.to.lon);
if (!this.from.edges.includes(this)) {
this.from.edges.push(this);
}
if (!this.to.edges.includes(this)) {
this.to.edges.push(this);
}
}
show() {
strokeWeight(min(10, (this.travels + 1) * 2));
stroke(55, 255, 255, 0.8);
line(this.from.x, this.from.y, this.to.x, this.to.y);
fill(0);
noStroke();
}
highlight() {
strokeWeight(4);
stroke(20, 255, 255, 1);
line(this.from.x, this.from.y, this.to.x, this.to.y);
fill(0);
noStroke();
}
OtherNodeofEdge(node) {
if (node == this.from) {
return this.to;
} else {
return this.from;
}
}
distanceToPoint(x,y) { //distance from middle of this edge to give point
return(dist(x,y,(this.to.x+this.from.x)/2,(this.to.y+this.from.y)/2));
}
}