/// <summary> /// Used internally by the Map Editor. It will recalculate de boundaries and optimize frontiers based on new data of provinces array /// </summary> public void RefreshProvinceDefinition(int provinceIndex) { lastProvinceLookupCount = -1; if (provinceIndex < 0 || provinceIndex >= provinces.Length) { return; } float maxArea = 0; Province province = provinces [provinceIndex]; if (province.regions == null) { ReadProvincePackedString(province); // safe check for specific map editor situations } int regionCount = province.regions.Count; for (int r = 0; r < regionCount; r++) { Vector2 minMaxLat = new Vector2(float.MaxValue, float.MinValue); Vector4 minMaxLon = new Vector2(float.MaxValue, float.MinValue); Region provinceRegion = province.regions[r]; provinceRegion.entity = province; provinceRegion.regionIndex = r; int coorCount = provinceRegion.latlon.Length; for (int c = 0; c < coorCount; c++) { PolygonPoint latlon = provinceRegion.latlon[c]; latlon.Reset(); float lat = latlon.Xf; float lon = latlon.Yf; if (lat < minMaxLat.x) { minMaxLat.x = lat; } if (lat > minMaxLat.y) { minMaxLat.y = lat; } if (lon < minMaxLon.x) { minMaxLon.x = lon; } if (lon > minMaxLon.y) { minMaxLon.y = lon; } } provinceRegion.minMaxLat = minMaxLat; provinceRegion.minMaxLon = minMaxLon; provinceRegion.rect2D = GetRect2DFromMinMaxLatLon(minMaxLat, minMaxLon); Vector2 midLatLon = new Vector2((minMaxLat.x + minMaxLat.y) / 2, (minMaxLon.x + minMaxLon.y) / 2); Vector3 normRegionCenter = GetSpherePointFromLatLon(midLatLon.x, midLatLon.y); provinceRegion.center = normRegionCenter; float area = provinceRegion.rect2D.size.sqrMagnitude; if (area > maxArea) { maxArea = area; province.mainRegionIndex = r; province.center = provinceRegion.center; } } DrawProvinces(provinces [provinceIndex].countryIndex, true, true); }
/// <summary> /// Used internally by the Map Editor. It will recalculate de boundaries and optimize frontiers based on new data of countries array /// </summary> public void RefreshCountryDefinition(int countryIndex, List <Region> filterRegions) { lastCountryLookupCount = -1; if (countryIndex >= 0 && countryIndex < countries.Length) { float maxArea = 0; Country country = countries [countryIndex]; int regionCount = country.regions.Count; for (int r = 0; r < regionCount; r++) { Vector2 minMaxLat = new Vector2(float.MaxValue, float.MinValue); Vector2 minMaxLon = new Vector2(float.MaxValue, float.MinValue); Region countryRegion = country.regions[r]; int coorCount = countryRegion.latlon.Length; for (int c = 0; c < coorCount; c++) { PolygonPoint latlon = countryRegion.latlon[c]; latlon.Reset(); float lat = latlon.Xf; float lon = latlon.Yf; if (lat < minMaxLat.x) { minMaxLat.x = lat; } if (lat > minMaxLat.y) { minMaxLat.y = lat; } if (lon < minMaxLon.x) { minMaxLon.x = lon; } if (lon > minMaxLon.y) { minMaxLon.y = lon; } } countryRegion.minMaxLat = minMaxLat; countryRegion.minMaxLon = minMaxLon; countryRegion.rect2D = GetRect2DFromMinMaxLatLon(minMaxLat, minMaxLon); Vector2 midLatLon = new Vector2((minMaxLat.x + minMaxLat.y) / 2, (minMaxLon.x + minMaxLon.y) / 2); Vector3 normRegionCenter = GetSpherePointFromLatLon2(midLatLon.x, midLatLon.y); countryRegion.center = normRegionCenter; float area = countryRegion.rect2D.width * countryRegion.rect2D.height; if (area > maxArea) { maxArea = area; country.mainRegionIndex = r; country.center = countryRegion.center; } } } // Refresh latlongs if (filterRegions != null) { for (int k = 0; k < filterRegions.Count; k++) { Region region = filterRegions[k]; for (int p = 0; p < region.latlon.Length; p++) { region.latlon[p].Reset(); } } } OptimizeFrontiers(filterRegions); DrawFrontiers(); }