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