044f2f4381
- 新增半解析、旧模型、自定义与多源堆叠星历实例,提供 Context、Instance、SPK 读取及状态与视位置计算 - 统一太阳、月球和行星实例接口,扩展黄经穿越、留、相位、最近角距、偕日可见、任意高度升落、轨道节点及凌日等天象查询 - 完善日月食、月掩与凌日的月缘剖面、有限盘面接触、站心修正、局地可见性、全球路径和地图输出 - 新增 SVG、GeoJSON、KML 天象输出及凌日、月掩和月缘地形相关缓存与几何求解 - 新增恒星星表导入与查询,支持 CSV、Hipparcos、BSC5、Stellarium 等格式及名称、交叉标识、锥面检索和星等过滤 - 补充 IAU 2006、地球定向、折射消光、大气观测、轨道传播及半解析行星/月球数据支持 - 将默认未来民用时标切换为 TimeScaleLeapHour,更新 2027–2400 农历速查表、中文日期解析和时区边界处理 - 增加事件基线、跨模型回归、几何边界、月缘地形和输出契约测试,完善中英文手册、示例资源、NOTICE 与忽略规则
92 lines
3.9 KiB
Go
92 lines
3.9 KiB
Go
package svg
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"b612.me/astro"
|
|
"b612.me/astro/basic"
|
|
"b612.me/astro/internal/svgmap"
|
|
)
|
|
|
|
func TestTransitMapSVGRendersRegionsAndIsochrones(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
planet TransitPlanet
|
|
date time.Time
|
|
}{
|
|
{"venus-2012", TransitVenus, time.Date(2012, 6, 6, 0, 0, 0, 0, time.UTC)},
|
|
{"mercury-2019", TransitMercury, time.Date(2019, 11, 11, 0, 0, 0, 0, time.UTC)},
|
|
}
|
|
for _, tc := range cases {
|
|
for _, projection := range []EclipseMapProjection{"", EclipseMapProjectionOrthographic, EclipseMapProjectionNorthPolar} {
|
|
chart, ok := TransitMapSVG(tc.planet, tc.date, TransitMapSVGOptions{Location: time.UTC, Projection: projection, Isochrones: TransitIsochroneAll})
|
|
if !ok {
|
|
t.Fatalf("%s %q: render failed", tc.name, projection)
|
|
}
|
|
for _, want := range []string{"transit-entire-region", "transit-sunrise-region", "transit-sunset-region",
|
|
"c1-horizon", "c4-horizon", `class="c1-isochrone"`, `class="c2-isochrone"`, `class="c3-isochrone"`,
|
|
`class="c4-isochrone"`, "c1-isochrone-label"} {
|
|
if !strings.Contains(chart, want) {
|
|
t.Fatalf("%s %q: missing %s", tc.name, projection, want)
|
|
}
|
|
}
|
|
if strings.Contains(chart, "NaN") || strings.Contains(chart, "Inf") {
|
|
t.Fatalf("%s %q: non-finite coordinate", tc.name, projection)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTransitMapSVGOptions(t *testing.T) {
|
|
date := time.Date(2012, 6, 6, 0, 0, 0, 0, time.UTC)
|
|
if _, ok := TransitMapSVG(3, date, TransitMapSVGOptions{}); ok {
|
|
t.Fatal("unsupported planet must fail")
|
|
}
|
|
if _, ok := TransitMapSVG(TransitVenus, date, TransitMapSVGOptions{
|
|
TimeScale: astro.TimeScaleUT1, Location: time.FixedZone("CST", 8*3600)}); ok {
|
|
t.Fatal("UT1 with non-UTC location must fail")
|
|
}
|
|
chart, ok := TransitMapSVG(TransitVenus, date, TransitMapSVGOptions{Location: time.UTC, Language: "en"})
|
|
if !ok || strings.Contains(chart, "isochrone") || !strings.Contains(chart, "Transit of Venus") {
|
|
t.Fatal("isochrones must be off by default and English labels kept")
|
|
}
|
|
chart, ok = TransitMapSVG(TransitVenus, date, TransitMapSVGOptions{Location: time.UTC, Isochrones: TransitIsochroneC2, IsochroneStep: 5 * time.Minute})
|
|
if !ok || !strings.Contains(chart, `class="c2-isochrone"`) || strings.Contains(chart, `class="c1-isochrone"`) ||
|
|
!strings.Contains(chart, "二触等时线") || strings.Contains(chart, "一触等时线") {
|
|
t.Fatal("only the selected contact must be drawn and listed in the legend")
|
|
}
|
|
}
|
|
|
|
// 太阳在视地平上的区域由图框减去对日点夜冠得到,边界距直射点 90°+地平折射。
|
|
// 曾直接画 90° 半球环,拆分日界线时分不清内外而整片填反。
|
|
func TestTransitMapSunUpBoundaryIncludesRefraction(t *testing.T) {
|
|
transit := basic.ClosestVenusTransit(basic.Date2JD(time.Date(2012, 6, 6, 0, 0, 0, 0, time.UTC)))
|
|
contacts := transitMapContactsOf(transit)
|
|
radius := 90 + basic.RefractionFromApparentAltitude(0, transitMapRefractionPressureHPa, transitMapRefractionTemperatureC)
|
|
frame := eclipseMapFrame(960, 640, svgmap.ProjectionEquirectangular, 142, 92)
|
|
for _, at := range []time.Time{contacts.start, contacts.greatest, contacts.end} {
|
|
path, _ := transitMapSunUpPath(at, frame)
|
|
if !strings.HasPrefix(path, fmt.Sprintf("M %.3f %.3f H", frame.X, frame.Y)) {
|
|
t.Fatalf("%v: sun-up path must start with the frame rectangle", at)
|
|
}
|
|
subsolar := solarEclipseSubsolarPoint(at)
|
|
_, boundary := transitMapSunUpPath(at, frame)
|
|
for _, point := range boundary {
|
|
distance := transitMapTestAngularDistance(point, subsolar)
|
|
if math.Abs(distance-radius) > 1e-6 {
|
|
t.Fatalf("%v: boundary point %.4f deg from subsolar point, want %.4f", at, distance, radius)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func transitMapTestAngularDistance(a, b svgmap.GeoPoint) float64 {
|
|
r := math.Pi / 180
|
|
cosine := math.Sin(a.Latitude*r)*math.Sin(b.Latitude*r) + math.Cos(a.Latitude*r)*math.Cos(b.Latitude*r)*math.Cos((a.Longitude-b.Longitude)*r)
|
|
return math.Acos(math.Max(-1, math.Min(1, cosine))) / r
|
|
}
|