Commit 18471e3b authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

add Random Version of function

parent 12d985cf
......@@ -8,10 +8,13 @@ import org.vadere.util.geometry.shapes.VRectangle;
import sun.java2d.pipe.ValidatePipe;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* Defines spawn points for a source and returns valid coordinates for spawning.
......@@ -77,7 +80,7 @@ public class SpawnArray {
return ret;
}
public VPoint getNextRandomPoint(Random rnd) {
public VPoint getNextRandomSpawnPoint(Random rnd) {
int index = rnd.nextInt(spawnPoints.length);
return spawnPoints[index];
}
......@@ -119,6 +122,24 @@ public class SpawnArray {
return points;
}
public LinkedList<VPoint> getNextFreeRandomPoints(int maxPoints, Random rnd, final List<DynamicElement> neighbours) {
double d = getMaxElementDim() / 2; // radius.
LinkedList<VPoint> points = new LinkedList<>();
List<Integer> randInt = IntStream.range(0, spawnPoints.length).boxed().collect(Collectors.toList());
Collections.shuffle(randInt);
for (Integer i : randInt) {
VPoint p = spawnPoints[i];
boolean overlap = neighbours.parallelStream().anyMatch(n -> ((n.getShape().distance(p) < d) || n.getShape().contains(p)));
if (!overlap) {
points.add(p);
if (points.size() == maxPoints) {
break;
}
}
}
return points;
}
/**
* This function only spawns non overlapping groups. This means that for instance within a
* source of the size 4x4 there are only 4 possible locations to spawn a group of the size 4
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment