-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKDNode.java
More file actions
46 lines (37 loc) · 980 Bytes
/
KDNode.java
File metadata and controls
46 lines (37 loc) · 980 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
45
46
package final_project;
public class KDNode {
private final int label;
private final float[] coordinates;
private KDNode right;
private KDNode left;
public KDNode(float[] coordinates, int label) {
this.coordinates = coordinates;
this.label = label;
}
public void setRight(KDNode right) {
this.right = right;
}
public void setLeft(KDNode left) {
this.left = left;
}
public float[] getCoordinates() {
return coordinates;
}
public KDNode getRight() {
return right;
}
public KDNode getLeft() {
return left;
}
public int getLabel() {
return label;
}
float distance(KDNode node) {
float dist = 0;
for (int i = 0; i < coordinates.length; ++i) {
double d = coordinates[i] - node.getCoordinates()[i];
dist += d * d;
}
return dist;
}
}