fix: 兼容 TinyGo wasm 编译行星星历初始化

- 将 planetViews 从包级初始化改为 sync.Once 懒加载,避免 TinyGo interp 在编译期处理大型 float64 表切片索引时触发 unsupported fcmp
- 将行星视图构建失败改为内部返回 error,并由兼容层统一 panic
- 补充无效行星数据切片边界测试
This commit is contained in:
2026-05-17 21:19:23 +08:00
parent bec7b8a0d8
commit d40c4dfcd9
3 changed files with 38 additions and 8 deletions
+14 -1
View File
@@ -25,8 +25,9 @@ func TestWherePlanetNFullMatchesDefault(t *testing.T) {
}
func TestPlanetViewsMatchRawCuts(t *testing.T) {
views := planetViews()
for bodyIndex, raw := range planetRawData {
view := planetViews[bodyIndex]
view := views[bodyIndex]
if math.Float64bits(view.scale) != math.Float64bits(raw[0]) {
t.Fatalf("body=%d scale mismatch", bodyIndex)
}
@@ -42,3 +43,15 @@ func TestPlanetViewsMatchRawCuts(t *testing.T) {
}
}
}
func TestBuildPlanetViewsRejectsInvalidCuts(t *testing.T) {
_, err := buildPlanetViews([][]float64{{
10000000000,
20, 21, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20,
}})
if err == nil {
t.Fatal("expected invalid cut error")
}
}