feat: 完善时标与天象几何计算并扩展输出接口
- 新增时标、ΔT 模型、质心时间与 UT1 支持 - 改进日月食、月掩、行星事件及路径边界计算 - 完善恒星三维自行与动态距离传播 - 扩展 SVG、GeoJSON、KML 输出与底层距离换算工具 - 整理中英文手册、示例资源及回归测试
This commit is contained in:
+2
-25
@@ -6,24 +6,7 @@ import (
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
// 视恒星时是 UT 的纯函数,但月掩全球路径会在同一条计算链里反复向它求值:
|
||||
// 地球自转、升落上下文、测地投影各自按自己的调用点重算同一个瞬时。实测单场 Saturn
|
||||
// 2025-01-05 的请求里,191,517 次求值只对应 51,308 个不同的儒略日(重复距离中位数只有
|
||||
// 2 次调用),而每次求值都要完整算一遍 77 项 IAU2000B 章动。
|
||||
//
|
||||
// 这里用一张有界直接映射表把结果记下来:无分配、容量固定(4096 槽 × 24 字节),
|
||||
// 用 RWMutex 保证 C 共享库被宿主多线程调用时安全。表项记录写入时的 ΔT 世代,
|
||||
// 因此 astro.SetDeltaT 覆盖之后旧条目自然失效,不会返回陈旧恒星时。
|
||||
//
|
||||
// Apparent sidereal time is a pure function of UT, yet one occultation path query evaluates
|
||||
// it many times for the same instant from independent code paths (Earth rotation, rise/set
|
||||
// contexts, geodetic projection). A single Saturn 2025-01-05 request performed 191,517
|
||||
// evaluations for only 51,308 distinct Julian days, and each evaluation ran the full
|
||||
// 77-term IAU2000B nutation. This bounded direct-mapped memo removes that redundancy without
|
||||
// allocating: a fixed 4096-slot table guarded by an RWMutex, with the ΔT generation stored in
|
||||
// each entry so an astro.SetDeltaT override invalidates stale values instead of replaying them.
|
||||
// 4096 槽对单场月掩的 5 万余个不同儒略日而言明显偏小(重复距离中位数只有 2 次调用),
|
||||
// 这里扩到 16384 槽(16384×24 B = 384 KB,BSS 静态数组,不参与初始化)。
|
||||
// 固定容量缓存以 ΔT 世代区分模型,RWMutex 保护宿主多线程访问。
|
||||
const siderealMemoBits = 14
|
||||
|
||||
const siderealMemoSize = 1 << siderealMemoBits
|
||||
@@ -43,14 +26,12 @@ var (
|
||||
)
|
||||
|
||||
// siderealMemoIndex 用高低位混合避免相邻儒略日落在相邻槽位而互相驱逐。
|
||||
// siderealMemoIndex mixes high and low bits so adjacent Julian days do not evict each other.
|
||||
func siderealMemoIndex(jd float64) uint64 {
|
||||
bits := math.Float64bits(jd)
|
||||
return (bits ^ (bits >> 29)) & (siderealMemoSize - 1)
|
||||
}
|
||||
|
||||
// siderealMemoLoad 返回缓存命中值;ΔT 世代不匹配时按未命中处理。
|
||||
// siderealMemoLoad returns a cached value; a generation mismatch counts as a miss.
|
||||
func siderealMemoLoad(jd float64) (float64, bool) {
|
||||
generation := deltaTGenerationValue()
|
||||
entry := &siderealMemoTable[siderealMemoIndex(jd)]
|
||||
@@ -65,11 +46,7 @@ func siderealMemoLoad(jd float64) (float64, bool) {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// siderealMemoStore 只在 ΔT 世代未变时写入:世代必须在**求值前**采样(见 siderealMemoGeneration),
|
||||
// 否则求值期间发生的 SetDeltaTFn 会把旧 ΔT 的结果打上新世代并长期回放。
|
||||
// siderealMemoStore writes only while the ΔT generation is unchanged; the generation must be sampled
|
||||
// before the evaluation, otherwise a SetDeltaTFn during the computation would stamp the old value
|
||||
// with the new generation and replay it.
|
||||
// 世代须在求值前采样,防止旧模型结果被缓存为新模型结果。
|
||||
func siderealMemoStore(jd, value float64, generation uint64) {
|
||||
if deltaTGenerationValue() != generation {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user