-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
44 lines (34 loc) · 956 Bytes
/
Copy pathNode.java
File metadata and controls
44 lines (34 loc) · 956 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cph.instance;
public class Node {
private int index;
private Instance instance;
public Node(int index, Instance instance) {
this.index = index;
this.instance = instance;
}
public int getDistanceTo(Node node) {
// Euclidean distance between the coordinates of the two nodes
double dx = Math.pow(instance.getX(node.index) - instance.getX(index), 2);
double dy = Math.pow(instance.getY(node.index) - instance.getY(index), 2);
return (int) Math.sqrt(dx + dy);
}
public int getIndex() {
return index;
}
@Override
public int hashCode() {
return index;
}
@Override
public boolean equals(Object o) {
if (o instanceof Node node) {
return index == node.index;
} else {
return false;
}
}
@Override
public String toString() {
return Integer.toString(index);
}
}