-
Notifications
You must be signed in to change notification settings - Fork 0
/
Edge.java
50 lines (40 loc) · 854 Bytes
/
Edge.java
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
public class Edge implements Comparable<Edge> {
private Vertex v1;
private Vertex v2;
private double weight;
public Edge (Vertex vert1, Vertex vert2){
v1 = vert1;
v2 = vert2;
calculateWeight();
}
public Edge (Vertex vert1, Vertex vert2, double dist){
v1 = vert1;
v2 = vert2;
weight = dist;
}
private void calculateWeight() {
weight = (v1.getX()-v2.getX())*(v1.getX()-v2.getX());
weight += (v1.getY()-v2.getY())*(v1.getY()-v2.getY());
weight = Math.sqrt(weight);
}
public Vertex getV1(){
return v1;
}
public Vertex getV2(){
return v2;
}
public double getWeight(){
return weight;
}
public String toString(){
return ("Edge: " + v1 + " " + v2);
}
public int compareTo(Edge v) {
if (this.weight < v.weight)
return -1;
else if (this.weight > v.weight)
return 1;
else
return 0;
}
}