-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEdge.java
More file actions
30 lines (26 loc) · 1009 Bytes
/
Edge.java
File metadata and controls
30 lines (26 loc) · 1009 Bytes
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
// Maddie London and Berke Nuri
import java.awt.Point;
import java.util.ArrayList;
public class Edge implements Comparable
{
Vertex v1; // represents one of the vertices at the end of the edge
Vertex v2; // represents one of the vertices at the end of the edge
boolean hovered; // represents whether or not the user's cursor is hovering of the edge
double weight; // the weight associated with the edge
public Edge(Vertex x, Vertex y) {
// constructor when given two vertices
v1 = x;
v2 = y;
hovered = false;
weight = 1.0; // default edge weight is 1
}
public int compareTo(Object o) {
// overriding
return (this.weight < ((Edge) o).weight ? -1 : (this.weight == ((Edge) o).weight ? 0 : 1));
}
public Point midPoint() {
// find the midpoint of an edge to add the weight label
return new Point((int)(0.5 * (this.v1.p.x + this.v2.p.x)),
(int)(0.5 * (this.v1.p.y + this.v2.p.y)));
}
}