Commit c8217a74 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Fixed potential AssertionError for out-of-world coordinates

parent 8853adf6
......@@ -239,12 +239,32 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
* host.
*/
PositionVector attractionCenter = (PositionVector) newAssignment;
PositionVector destination = new PositionVector(attractionCenter);
// Gaussian with std = 1 --> >99% of nodes
PositionVector offset = new PositionVector(
rand.nextGaussian() * newAssignment.getRadius() / 3,
rand.nextGaussian() * newAssignment.getRadius() / 3);
destination.add(offset);
PositionVector destination = null;
int tries = 0;
do {
destination = new PositionVector(attractionCenter);
// Gaussian with std = 1 --> >99% of nodes
PositionVector offset = new PositionVector(
rand.nextGaussian() * newAssignment.getRadius() / 3,
rand.nextGaussian() * newAssignment.getRadius() / 3);
destination.add(offset);
// Check constraints
if (destination.getX() < 0.0
|| destination.getX() > Binder
.getComponentOrNull(Topology.class)
.getWorldDimensions().getX() || destination.getY() < 0.0
|| destination.getY() > Binder
.getComponentOrNull(Topology.class)
.getWorldDimensions().getY()) {
destination = null;
if (tries > 100) {
throw new AssertionError("Unable to find a valid target destination within <100 tries.");
}
}
tries++;
} while (destination == null);
currentTarget.put(component, destination);
}
......
Markdown is supported
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