feat: 新增月掩与日月食地理绘图并提升观测计算精度
- 新增月掩恒星和行星:支持搜索、掩甚点、全球掩带及固定地点轨迹计算 - 支持恒星星表坐标转换、有限盘面行星接触事件和月掩 SVG 输出 - 新增日月食及月掩全球投影图、时间标记和 GeoJSON 地理数据接口 - 扩展日食中心线、南北界及偏食足迹采样,支持极区投影 - 修正站心时角、月出月落、月球视半径、折射和恒星自行计算 - 优化内外行星事件搜索、边界选择、极端输入处理和计算稳定性
This commit is contained in:
+67
-11
@@ -5,9 +5,17 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRefractionFromApparentAltitudeStandardAtmosphere(t *testing.T) {
|
||||
assertClose(t, "Refraction@0deg", RefractionFromApparentAltitude(0, 1010, 10), 0.483032, 0.0001)
|
||||
assertClose(t, "Refraction@45deg", RefractionFromApparentAltitude(45, 1010, 10), 0.016878, 0.0001)
|
||||
func TestRefractionFromTrueAltitudeStandardAtmosphere(t *testing.T) {
|
||||
assertClose(t, "RefractionFromTrue@0deg", RefractionFromTrueAltitude(0, 1010, 10), 0.483032, 0.0001)
|
||||
assertClose(t, "RefractionFromTrue@45deg", RefractionFromTrueAltitude(45, 1010, 10), 0.016878, 0.0001)
|
||||
assertClose(t, "ApparentAltitude@0deg", ApparentAltitude(0, 1010, 10), 0.483032, 0.0001)
|
||||
}
|
||||
|
||||
func TestRefractionFromApparentAltitudeUsesApparentInput(t *testing.T) {
|
||||
// 视地平线处修正约为 34.5 角分,而不是真高度角公式在 0 度返回的 29 角分 / At the apparent horizon the correction is about 34.5 arcminutes, not
|
||||
// 29 角分 / the 29 arcminutes returned by the true-altitude formula at 0 degrees.
|
||||
assertClose(t, "RefractionFromApparent@0deg", RefractionFromApparentAltitude(0, 1010, 10), 0.574, 0.001)
|
||||
assertClose(t, "TrueAltitude@0deg", TrueAltitude(0, 1010, 10), -0.574, 0.001)
|
||||
}
|
||||
|
||||
func TestRefractionRoundTrip(t *testing.T) {
|
||||
@@ -35,29 +43,77 @@ func TestRefractionRoundTrip(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRefractionRoundTripNearZenith(t *testing.T) {
|
||||
for _, trueAltitude := range []float64{89.90, 89.95, 89.99} {
|
||||
apparentAltitude := ApparentAltitude(trueAltitude, 1010, 10)
|
||||
if math.IsNaN(apparentAltitude) || math.IsInf(apparentAltitude, 0) {
|
||||
t.Fatalf("true altitude %.2f produced invalid apparent altitude %v", trueAltitude, apparentAltitude)
|
||||
}
|
||||
got := TrueAltitude(apparentAltitude, 1010, 10)
|
||||
if math.IsNaN(got) || math.IsInf(got, 0) {
|
||||
t.Fatalf("apparent altitude %.12f produced invalid true altitude %v", apparentAltitude, got)
|
||||
}
|
||||
assertClose(t, "NearZenithRoundTrip", got, trueAltitude, 1e-9)
|
||||
if refraction := RefractionFromApparentAltitude(apparentAltitude, 1010, 10); math.IsNaN(refraction) || math.IsInf(refraction, 0) {
|
||||
t.Fatalf("apparent altitude %.12f produced invalid refraction %v", apparentAltitude, refraction)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRefractionExtremeTemperatureInverse(t *testing.T) {
|
||||
const (
|
||||
apparentAltitude = 0.0
|
||||
pressureHPa = 1010.0
|
||||
)
|
||||
trueAltitude := TrueAltitude(apparentAltitude, pressureHPa, -273)
|
||||
if math.IsNaN(trueAltitude) || math.IsInf(trueAltitude, 0) {
|
||||
t.Fatalf("-273 C inverse returned invalid true altitude %v", trueAltitude)
|
||||
}
|
||||
assertClose(t, "ExtremeTemperatureRoundTrip",
|
||||
ApparentAltitude(trueAltitude, pressureHPa, -273), apparentAltitude, 1e-9)
|
||||
|
||||
for _, temperatureC := range []float64{-273.14, math.Nextafter(refractionAbsoluteZeroC, math.Inf(1))} {
|
||||
if got := TrueAltitude(apparentAltitude, pressureHPa, temperatureC); !math.IsNaN(got) {
|
||||
t.Errorf("temperature %.17g C inverse = %v, want NaN when the model has no root", temperatureC, got)
|
||||
}
|
||||
if got := RefractionFromApparentAltitude(apparentAltitude, pressureHPa, temperatureC); !math.IsNaN(got) {
|
||||
t.Errorf("temperature %.17g C apparent refraction = %v, want NaN when the model has no root", temperatureC, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRefractionScalingAndBounds(t *testing.T) {
|
||||
lowPressure := RefractionFromApparentAltitude(0, 980, 10)
|
||||
highPressure := RefractionFromApparentAltitude(0, 1030, 10)
|
||||
lowPressure := RefractionFromTrueAltitude(0, 980, 10)
|
||||
highPressure := RefractionFromTrueAltitude(0, 1030, 10)
|
||||
if !(lowPressure < highPressure) {
|
||||
t.Fatalf("pressure scaling mismatch: low %.12f high %.12f", lowPressure, highPressure)
|
||||
}
|
||||
|
||||
cold := RefractionFromApparentAltitude(0, 1010, 0)
|
||||
hot := RefractionFromApparentAltitude(0, 1010, 30)
|
||||
cold := RefractionFromTrueAltitude(0, 1010, 0)
|
||||
hot := RefractionFromTrueAltitude(0, 1010, 30)
|
||||
if !(cold > hot) {
|
||||
t.Fatalf("temperature scaling mismatch: cold %.12f hot %.12f", cold, hot)
|
||||
}
|
||||
|
||||
if RefractionFromApparentAltitude(-6, 1010, 10) != 0 {
|
||||
if RefractionFromTrueAltitude(-6, 1010, 10) != 0 {
|
||||
t.Fatalf("refraction below lower limit should be 0")
|
||||
}
|
||||
if RefractionFromApparentAltitude(95, 1010, 10) != 0 {
|
||||
if RefractionFromTrueAltitude(95, 1010, 10) != 0 {
|
||||
t.Fatalf("refraction above upper limit should be 0")
|
||||
}
|
||||
if !math.IsNaN(RefractionFromApparentAltitude(0, 0, 10)) {
|
||||
if !math.IsNaN(RefractionFromTrueAltitude(0, 0, 10)) {
|
||||
t.Fatalf("invalid pressure should produce NaN")
|
||||
}
|
||||
if !math.IsNaN(RefractionFromApparentAltitude(0, 1010, -274)) {
|
||||
if !math.IsNaN(RefractionFromTrueAltitude(0, 1010, -274)) {
|
||||
t.Fatalf("invalid temperature should produce NaN")
|
||||
}
|
||||
if !math.IsNaN(RefractionFromTrueAltitude(0, 1010, -273.15)) {
|
||||
t.Fatalf("absolute zero should produce NaN")
|
||||
}
|
||||
for _, temperatureC := range []float64{-273, -273.14} {
|
||||
refraction := RefractionFromTrueAltitude(0, 1010, temperatureC)
|
||||
if math.IsNaN(refraction) || math.IsInf(refraction, 0) || refraction <= 0 {
|
||||
t.Fatalf("temperature %.2f C produced invalid refraction %v", temperatureC, refraction)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user