generated from Grigo/AndroidTemplate
Ковырял декодер строк
This commit is contained in:
@@ -69,11 +69,27 @@ public class CompassView extends BaseDockWidget {
|
||||
}
|
||||
|
||||
private float getShortestRotation(float start, float end) {
|
||||
// Нормализуем углы к диапазону 0-360
|
||||
start = normalizeAngle(start);
|
||||
end = normalizeAngle(end);
|
||||
|
||||
float diff = end - start;
|
||||
while (diff > 180) diff -= 360;
|
||||
while (diff < -180) diff += 360;
|
||||
|
||||
// Если разность больше 180°, идем в обратную сторону
|
||||
if (diff > 180) {
|
||||
diff -= 360;
|
||||
} else if (diff < -180) {
|
||||
diff += 360;
|
||||
}
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
private float normalizeAngle(float angle) {
|
||||
while (angle < 0) angle += 360;
|
||||
while (angle >= 360) angle -= 360;
|
||||
return angle;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -109,9 +125,11 @@ public class CompassView extends BaseDockWidget {
|
||||
// Плавное обновление азимута
|
||||
float diff = getShortestRotation(currentAzimuth, targetAzimuth);
|
||||
if (Math.abs(diff) > 0.1f) {
|
||||
currentAzimuth += diff * SMOOTHING_FACTOR;
|
||||
if (currentAzimuth > 360) currentAzimuth -= 360;
|
||||
if (currentAzimuth < 0) currentAzimuth += 360;
|
||||
// Ограничиваем максимальное изменение за один кадр
|
||||
float maxChange = 3.0f; // максимальное изменение в градусах за кадр
|
||||
float change = Math.signum(diff) * Math.min(Math.abs(diff * SMOOTHING_FACTOR), maxChange);
|
||||
currentAzimuth += change;
|
||||
currentAzimuth = normalizeAngle(currentAzimuth);
|
||||
postInvalidateOnAnimation();
|
||||
}
|
||||
|
||||
@@ -123,8 +141,7 @@ public class CompassView extends BaseDockWidget {
|
||||
// Рисуем деления шкалы
|
||||
for (int degree = 0; degree < 360; degree += 15) {
|
||||
// Вычисляем относительное положение деления
|
||||
float relativeDegree = (degree - currentAzimuth + 360) % 360;
|
||||
if (relativeDegree > 180) relativeDegree -= 360;
|
||||
float relativeDegree = getShortestRotation(currentAzimuth, degree);
|
||||
|
||||
// Рисуем только видимые деления
|
||||
if (Math.abs(relativeDegree) <= visibleDegrees / 2) {
|
||||
@@ -149,8 +166,7 @@ public class CompassView extends BaseDockWidget {
|
||||
|
||||
// Рисуем суда
|
||||
for (AISVessel vessel : nearbyVessels) {
|
||||
float relativeBearing = (float) ((vessel.getCourse() - currentAzimuth + 360) % 360);
|
||||
if (relativeBearing > 180) relativeBearing -= 360;
|
||||
float relativeBearing = getShortestRotation(currentAzimuth, (float) vessel.getCourse());
|
||||
if (Math.abs(relativeBearing) <= visibleDegrees / 2) {
|
||||
float x = centerX + (relativeBearing / (visibleDegrees / 2)) * (w / 2);
|
||||
double distance = ourVessel != null ? GeoUtils.calculateDistance(ourVessel, vessel) : 0;
|
||||
@@ -218,9 +234,11 @@ public class CompassView extends BaseDockWidget {
|
||||
// Плавное обновление азимута
|
||||
float diff = getShortestRotation(currentAzimuth, targetAzimuth);
|
||||
if (Math.abs(diff) > 0.1f) {
|
||||
currentAzimuth += diff * SMOOTHING_FACTOR;
|
||||
if (currentAzimuth > 360) currentAzimuth -= 360;
|
||||
if (currentAzimuth < 0) currentAzimuth += 360;
|
||||
// Ограничиваем максимальное изменение за один кадр
|
||||
float maxChange = 3.0f; // максимальное изменение в градусах за кадр
|
||||
float change = Math.signum(diff) * Math.min(Math.abs(diff * SMOOTHING_FACTOR), maxChange);
|
||||
currentAzimuth += change;
|
||||
currentAzimuth = normalizeAngle(currentAzimuth);
|
||||
postInvalidateOnAnimation();
|
||||
}
|
||||
|
||||
@@ -246,7 +264,7 @@ public class CompassView extends BaseDockWidget {
|
||||
|
||||
// Рисуем суда по кругу
|
||||
for (AISVessel vessel : nearbyVessels) {
|
||||
float bearing = (float) ((vessel.getCourse() - currentAzimuth + 360) % 360);
|
||||
float bearing = getShortestRotation(currentAzimuth, (float) vessel.getCourse());
|
||||
float angle = (float) Math.toRadians(bearing);
|
||||
float vesselRadius = radius * 0.6f;
|
||||
float vx = cx + (float) Math.sin(angle) * vesselRadius;
|
||||
@@ -313,7 +331,25 @@ public class CompassView extends BaseDockWidget {
|
||||
}
|
||||
|
||||
public void setAzimuth(float azimuth) {
|
||||
this.targetAzimuth = azimuth;
|
||||
// Проверяем на валидность азимута
|
||||
if (Float.isNaN(azimuth) || Float.isInfinite(azimuth)) {
|
||||
return; // Игнорируем невалидные значения
|
||||
}
|
||||
|
||||
// Нормализуем входящий азимут
|
||||
this.targetAzimuth = normalizeAngle(azimuth);
|
||||
|
||||
// Если текущий азимут еще не инициализирован, устанавливаем его сразу
|
||||
if (currentAzimuth == 0 && targetAzimuth != 0) {
|
||||
currentAzimuth = targetAzimuth;
|
||||
}
|
||||
|
||||
// Специальная обработка для 0° - если текущий азимут близок к 360°,
|
||||
// то 0° должен интерпретироваться как 360°
|
||||
if (targetAzimuth == 0 && currentAzimuth > 350) {
|
||||
this.targetAzimuth = 360;
|
||||
}
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user