-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoronoi.java
34 lines (25 loc) · 849 Bytes
/
Voronoi.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
import java.util.*;
// bounds: left, top, right, bottom.
public class Voronoi {
public static List<Cell> evaluate(List<Point> points, double[] bounds) {
final KdTree kdTree = new KdTree();
for(Point point : points) {
Cell parent = kdTree.getClosest(point);
if(parent == null) {
kdTree.add(new Cell(point, bounds));
} else {
final Cell cell = new Cell(point);
final Set<Cell> neighbours = parent.getNeighbours(cell);
for(Cell neighbour : neighbours) {
neighbour.split(cell);
}
kdTree.add(cell);
}
if(Main.counter >= Main.steps) {
break;
}
Main.counter++;
}
return kdTree.getAll();
}
}