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

Respect world size in OSM movement

parent a53ed447
......@@ -284,6 +284,9 @@ public class DefaultTopologyComponent implements TopologyComponent {
@Override
public void requestLocationUpdates(LocationRequest request,
LocationListener listener) {
if (openRequests.containsKey(listener)) {
throw new AssertionError("This LocationListener is already in use.");
}
LocationRequestImpl req = (LocationRequestImpl) request;
openRequests.put(listener, req);
req.immunizeAndStart(listener);
......
......@@ -164,6 +164,10 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private PositionVector transformGPSWindowToOwnWorld(double lat, double lon) {
double x = worldDimensions.getX() * (lon - lonLeft)/(lonRight - lonLeft);
double y = worldDimensions.getY() - worldDimensions.getY() * (lat - latLeft)/(latRight - latLeft);
x = Math.max(0, x);
x = Math.min(worldDimensions.getX(), x);
y = Math.max(0, y);
y = Math.min(worldDimensions.getY(), y);
return new PositionVector(x, y);
}
......
......@@ -246,6 +246,11 @@ public class ModularMovementModel implements MovementModel, EventHandler {
.nextPosition(ms, destination);
if (either.hasLeft()) {
ms.getRealPosition().replace(either.getLeft());
/*
* Check for negative or out of bound coordinates!
*/
assert ms.getRealPosition().getX() >= 0.0 && ms.getRealPosition().getX() <= Binder.getComponentOrNull(Topology.class).getWorldDimensions().getX();
assert ms.getRealPosition().getY() >= 0.0 && ms.getRealPosition().getY() <= Binder.getComponentOrNull(Topology.class).getWorldDimensions().getY();
notifyPositionChange(ms);
} else {
transition.reachedAttractionPoint(ms);
......
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