feat: 完善日月食与月掩几何链路并扩展历法接口
- 新增日月食中心带、偏食带、阴影足迹、等时线、食分线及升落边界计算,支持极区与混合食拓扑 - 新增日食单时刻阴影求解器、站心状态查询、批量采样和 ΔT 覆盖接口 - 重构恒星与行星月掩路径,补充有限盘面接触、站心修正、掩带宽度、极区投影及升落边界 - 扩展 SVG 与 GeoJSON 输出,支持详细面板、全球/极区/地球投影、边界闭合、时间标记和拓扑签名 - 扩展日月食候选搜索、局地搜索、沙罗序列预计算与范围外推,补充系列锚点和成员一致性校验 - 补齐古历纪年、儒略历独有闰日、多公历候选、历法改革跨日及精确日期运算接口 - 优化 ΔT、章动、恒星时、月球地平线、事件根搜索和本地星历缓存,降低重复计算开销并提升边界稳定
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
// Package planet 用内置 VSOP87 截断级数求行星黄经、黄纬与日心距离;jd 为 TT 儒略日,角度单位为度,距离单位为 AU。
|
||||
// Package planet evaluates the built-in truncated VSOP87 series for planetary longitude, latitude and heliocentric distance; jd is a TT Julian day, angles are degrees and distances are AU.
|
||||
package planet
|
||||
+14
-5
@@ -5,16 +5,25 @@ import (
|
||||
"math"
|
||||
)
|
||||
|
||||
// WherePlanet returns the full VSOP result for the selected body and coordinate.
|
||||
// WherePlanet 天体 xt 在儒略日 jd 的 VSOP 结果 / VSOP result for body xt at Julian day jd.
|
||||
//
|
||||
// xt 取 -1 或 0..7:0 为地球,1..7 依次为水星、金星、火星、木星、土星、天王星、海王星;-1 表示地球,zn 取 0 时给日心黄经。
|
||||
// zn 取 0 黄经、1 黄纬、2 日心距(AU);xt 或 zn 越界返回 NaN 而不 panic。
|
||||
// xt is -1 or 0..7 (0 Earth, 1..7 Mercury through Neptune; -1 selects Earth, giving its heliocentric longitude for zn 0).
|
||||
// zn is 0 longitude, 1 latitude, 2 heliocentric distance in AU; an out-of-range xt or zn yields NaN instead of panicking.
|
||||
func WherePlanet(xt, zn int, jd float64) float64 {
|
||||
return WherePlanetN(xt, zn, jd, -1)
|
||||
}
|
||||
|
||||
// WherePlanetN returns the VSOP result for the selected body and coordinate.
|
||||
// When n < 0, all terms are used. Otherwise n follows the original eph0.js
|
||||
// truncation semantics: keep roughly n principal terms from the 0th order
|
||||
// series and scale higher-order series proportionally.
|
||||
// WherePlanetN 同 WherePlanet 的截断版 / truncated form of WherePlanet.
|
||||
//
|
||||
// n < 0 时使用全部项;否则保留约 n 个主项并按比例缩短高阶项。取值域与越界行为同 WherePlanet。
|
||||
// When n < 0 all terms are used; otherwise roughly n principal terms are kept and higher orders scaled proportionally. Domain and out-of-range behavior match WherePlanet.
|
||||
func WherePlanetN(xt, zn int, jd float64, n int) float64 {
|
||||
if xt < -1 || xt > 7 || zn < 0 || zn > 2 {
|
||||
return math.NaN()
|
||||
}
|
||||
|
||||
sata := 0
|
||||
if xt == -1 {
|
||||
xt = 0
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package planet
|
||||
|
||||
import "testing"
|
||||
|
||||
func BenchmarkWherePlanet(b *testing.B) {
|
||||
const jd = 2451545.0
|
||||
var sink float64
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
sink += WherePlanet(4, 0, jd)
|
||||
}
|
||||
_ = sink
|
||||
}
|
||||
+66
-19
@@ -5,25 +5,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWherePlanetNFullMatchesDefault(t *testing.T) {
|
||||
jds := []float64{
|
||||
2415020.123456789,
|
||||
2451545.0,
|
||||
2469808.7654321,
|
||||
}
|
||||
for _, jd := range jds {
|
||||
for xt := -1; xt < 8; xt++ {
|
||||
for zn := 0; zn < 3; zn++ {
|
||||
got := WherePlanet(xt, zn, jd)
|
||||
gotN := WherePlanetN(xt, zn, jd, -1)
|
||||
if math.Float64bits(got) != math.Float64bits(gotN) {
|
||||
t.Fatalf("jd=%f xt=%d zn=%d full mismatch: got=%v gotN=%v", jd, xt, zn, got, gotN)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanetViewsMatchRawCuts(t *testing.T) {
|
||||
views := planetViews()
|
||||
for bodyIndex, raw := range planetRawData {
|
||||
@@ -55,3 +36,69 @@ func TestBuildPlanetViewsRejectsInvalidCuts(t *testing.T) {
|
||||
t.Fatal("expected invalid cut error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWherePlanetDomainGuards(t *testing.T) {
|
||||
jds := []float64{2415020.123456789, 2451545.0, 2469808.7654321}
|
||||
for _, jd := range jds {
|
||||
for xt := -1; xt <= 7; xt++ {
|
||||
for zn := 0; zn <= 2; zn++ {
|
||||
for _, n := range []int{-1, 0, 3, 100} {
|
||||
got := WherePlanetN(xt, zn, jd, n)
|
||||
if math.IsNaN(got) || math.IsInf(got, 0) {
|
||||
t.Fatalf("in-domain WherePlanetN(%d, %d, %v, %d) = %v", xt, zn, jd, n, got)
|
||||
}
|
||||
}
|
||||
got := WherePlanet(xt, zn, jd)
|
||||
if math.IsNaN(got) || math.IsInf(got, 0) {
|
||||
t.Fatalf("in-domain WherePlanet(%d, %d, %v) = %v", xt, zn, jd, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, xt := range []int{-2, -100, 8, 9, 100} {
|
||||
for zn := 0; zn <= 2; zn++ {
|
||||
assertWherePlanetNaN(t, xt, zn, jd)
|
||||
}
|
||||
}
|
||||
for _, zn := range []int{-1, -100, 3, 100} {
|
||||
for xt := -1; xt <= 7; xt++ {
|
||||
assertWherePlanetNaN(t, xt, zn, jd)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func assertWherePlanetNaN(t *testing.T, xt, zn int, jd float64) {
|
||||
t.Helper()
|
||||
if got := WherePlanet(xt, zn, jd); !math.IsNaN(got) {
|
||||
t.Fatalf("WherePlanet(%d, %d, %v) = %v, want NaN", xt, zn, jd, got)
|
||||
}
|
||||
for _, n := range []int{-1, 0, 6} {
|
||||
if got := WherePlanetN(xt, zn, jd, n); !math.IsNaN(got) {
|
||||
t.Fatalf("WherePlanetN(%d, %d, %v, %d) = %v, want NaN", xt, zn, jd, n, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWherePlanetGoldenValues(t *testing.T) {
|
||||
jd := 2451545.0
|
||||
cases := []struct {
|
||||
xt, zn int
|
||||
want float64
|
||||
}{
|
||||
{-1, 0, 100.37782037193487},
|
||||
{-1, 1, -0.00022991463883506049},
|
||||
{-1, 2, 0.98332764743480028},
|
||||
{0, 0, 280.37782037193489},
|
||||
{0, 1, 0.00022991463883506049},
|
||||
{0, 2, 0.98332764743480028},
|
||||
{4, 0, 36.29462069188007},
|
||||
{4, 1, -1.1745385942079292},
|
||||
{4, 2, 4.9653814383525443},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got := WherePlanet(tc.xt, tc.zn, jd)
|
||||
if math.Abs(got-tc.want) > 1e-12 {
|
||||
t.Fatalf("WherePlanet(%d, %d, %v) = %.17g, want %.17g", tc.xt, tc.zn, jd, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ func Earthe(JD float64) float64 {
|
||||
|
||||
func EarthPI(JD float64) float64 {
|
||||
T := (JD - 2451545) / 36525
|
||||
return 102.93735 + 1.71953*T + 000046*T*T
|
||||
return 102.93735 + 1.71953*T + 0.00046*T*T
|
||||
}
|
||||
|
||||
func SunMidFun(JD float64) float64 {
|
||||
|
||||
Reference in New Issue
Block a user