prevent crash if incorrect zone setup

This commit is contained in:
2024-04-19 22:42:35 +00:00
parent fac8c2002c
commit ff6a78b9af
2 changed files with 13 additions and 3 deletions

View File

@@ -108,7 +108,8 @@ export class ZoneManager {
this.nextZone = JSON.parse(JSON.stringify(this.zoneSettings.max));
this.currentStartZone = JSON.parse(JSON.stringify(this.zoneSettings.max));
this.currentZone = JSON.parse(JSON.stringify(this.zoneSettings.max));
this.setNextZone();
return this.setNextZone();
}
/**
@@ -121,11 +122,16 @@ export class ZoneManager {
getRandomNextCenter(newRadius) {
let ok = false;
let res = null
let tries = 0;
const MAX_TRIES = 1000
//take a random point satisfying both conditions
while (!ok) {
while (tries++<MAX_TRIES) {
res = randomCirclePoint({ latitude: this.currentZone.center.lat, longitude: this.currentZone.center.lng }, this.currentZone.radius - newRadius);
ok = (isInCircle({ lat: res.latitude, lng: res.longitude }, this.zoneSettings.min.center, newRadius - this.zoneSettings.min.radius))
}
if(tries>=MAX_TRIES) {
return false;
}
return {
lat: res.latitude,
lng: res.longitude