fix(geo): 修复香港等节点地图质心缺失落到南美占位

补全 Hong Kong/Singapore/Taiwan 质心数据,并改进复合地名与 ISO 匹配,
避免 geo 无精确经纬度时错误回退到巴西等地的占位坐标。
This commit is contained in:
ryan
2026-07-18 13:52:20 +08:00
parent 26057514a1
commit a0ccafc6ee
5 changed files with 792 additions and 180 deletions
+31
View File
@@ -11,3 +11,34 @@ func TestCountryCentroidGermany(t *testing.T) {
t.Fatalf("unexpected Germany centroid: %f,%f", lat, lon)
}
}
func TestCountryCentroidHongKongSingaporeTaiwan(t *testing.T) {
cases := []struct {
iso string
name string
minLat float64
maxLat float64
minLon float64
maxLon float64
}{
{iso: "HK", name: "Hong Kong", minLat: 22, maxLat: 23, minLon: 113, maxLon: 115},
{iso: "SG", name: "Singapore", minLat: 1, maxLat: 2, minLon: 103, maxLon: 104},
{iso: "TW", name: "Taiwan", minLat: 22, maxLat: 26, minLon: 119, maxLon: 122},
}
for _, tc := range cases {
lat, lon, ok := CountryCentroidByISO(tc.iso)
if !ok {
t.Fatalf("expected %s centroid by ISO", tc.iso)
}
if lat < tc.minLat || lat > tc.maxLat || lon < tc.minLon || lon > tc.maxLon {
t.Fatalf("%s ISO centroid out of range: %f,%f", tc.iso, lat, lon)
}
lat, lon, ok = CountryCentroidByName(tc.name)
if !ok {
t.Fatalf("expected %s centroid by name", tc.name)
}
if lat < tc.minLat || lat > tc.maxLat || lon < tc.minLon || lon > tc.maxLon {
t.Fatalf("%s name centroid out of range: %f,%f", tc.name, lat, lon)
}
}
}