2026-05-01 22:38:44 +08:00
|
|
|
package planet
|
|
|
|
|
|
2026-05-17 21:19:23 +08:00
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"sync"
|
|
|
|
|
)
|
2026-05-01 22:38:44 +08:00
|
|
|
|
|
|
|
|
type coordSeriesView struct {
|
|
|
|
|
orders [6][]float64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type planetView struct {
|
|
|
|
|
scale float64
|
|
|
|
|
coords [3]coordSeriesView
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-17 21:19:23 +08:00
|
|
|
var (
|
|
|
|
|
planetViewsOnce sync.Once
|
|
|
|
|
planetViewsCache []planetView
|
|
|
|
|
planetViewsErr error
|
|
|
|
|
)
|
2026-05-01 22:38:44 +08:00
|
|
|
|
2026-05-17 21:19:23 +08:00
|
|
|
func planetViews() []planetView {
|
|
|
|
|
planetViewsOnce.Do(func() {
|
|
|
|
|
planetViewsCache, planetViewsErr = buildPlanetViews(planetRawData)
|
|
|
|
|
})
|
|
|
|
|
if planetViewsErr != nil {
|
|
|
|
|
panic(planetViewsErr)
|
|
|
|
|
}
|
|
|
|
|
return planetViewsCache
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func buildPlanetViews(rawData [][]float64) ([]planetView, error) {
|
2026-05-01 22:38:44 +08:00
|
|
|
views := make([]planetView, len(rawData))
|
|
|
|
|
for bodyIndex, raw := range rawData {
|
|
|
|
|
if len(raw) < 20 {
|
2026-05-17 21:19:23 +08:00
|
|
|
return nil, fmt.Errorf("planet raw data %d too short: %d", bodyIndex, len(raw))
|
2026-05-01 22:38:44 +08:00
|
|
|
}
|
|
|
|
|
view := planetView{scale: raw[0]}
|
|
|
|
|
for zn := 0; zn < 3; zn++ {
|
|
|
|
|
pn := zn*6 + 1
|
|
|
|
|
for order := 0; order < 6; order++ {
|
|
|
|
|
start := int(raw[pn+order])
|
|
|
|
|
end := int(raw[pn+order+1])
|
|
|
|
|
if start < 0 || end < start || end > len(raw) {
|
2026-05-17 21:19:23 +08:00
|
|
|
return nil, fmt.Errorf("planet raw data %d coord %d order %d invalid cut: %d..%d (len=%d)", bodyIndex, zn, order, start, end, len(raw))
|
2026-05-01 22:38:44 +08:00
|
|
|
}
|
|
|
|
|
view.coords[zn].orders[order] = raw[start:end]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
views[bodyIndex] = view
|
|
|
|
|
}
|
2026-05-17 21:19:23 +08:00
|
|
|
return views, nil
|
2026-05-01 22:38:44 +08:00
|
|
|
}
|