Check and clamp bearing range each time it's set (#248)

This commit is contained in:
Izumi Kawashima 2016-11-22 01:32:43 +09:00 committed by Emux
parent bf8f0745a6
commit f6dbeba3d8

View File

@ -90,7 +90,7 @@ public class MapPosition {
} }
public MapPosition setBearing(float bearing) { public MapPosition setBearing(float bearing) {
this.bearing = bearing; this.bearing = clampBearing(bearing);
return this; return this;
} }
@ -149,14 +149,17 @@ public class MapPosition {
this.y = y; this.y = y;
this.scale = scale; this.scale = scale;
this.bearing = clampBearing(bearing);
this.tilt = tilt;
this.zoomLevel = FastMath.log2((int) scale);
}
private static float clampBearing(float bearing) {
while (bearing > 180) while (bearing > 180)
bearing -= 360; bearing -= 360;
while (bearing < -180) while (bearing < -180)
bearing += 360; bearing += 360;
this.bearing = bearing; return bearing;
this.tilt = tilt;
this.zoomLevel = FastMath.log2((int) scale);
} }
/** /**