Files
astro/internal/geodata/sphere_test.go
T
b612 044f2f4381 feat: 引入可切换星历模型并扩展天象观测链路
- 新增半解析、旧模型、自定义与多源堆叠星历实例,提供 Context、Instance、SPK 读取及状态与视位置计算
- 统一太阳、月球和行星实例接口,扩展黄经穿越、留、相位、最近角距、偕日可见、任意高度升落、轨道节点及凌日等天象查询
- 完善日月食、月掩与凌日的月缘剖面、有限盘面接触、站心修正、局地可见性、全球路径和地图输出
- 新增 SVG、GeoJSON、KML 天象输出及凌日、月掩和月缘地形相关缓存与几何求解
- 新增恒星星表导入与查询,支持 CSV、Hipparcos、BSC5、Stellarium 等格式及名称、交叉标识、锥面检索和星等过滤
- 补充 IAU 2006、地球定向、折射消光、大气观测、轨道传播及半解析行星/月球数据支持
- 将默认未来民用时标切换为 TimeScaleLeapHour,更新 2027–2400 农历速查表、中文日期解析和时区边界处理
- 增加事件基线、跨模型回归、几何边界、月缘地形和输出契约测试,完善中英文手册、示例资源、NOTICE 与忽略规则
2026-10-15 23:54:15 +08:00

127 lines
4.4 KiB
Go

package geodata
import (
"math"
"testing"
)
func TestJoinPolylineSegmentsUsesBothResultEndpoints(t *testing.T) {
segments := [][]GeoPoint{
{
{Longitude: -179, Latitude: 16},
{Longitude: -41, Latitude: 64},
},
{
{Longitude: 51, Latitude: 60},
{Longitude: 179, Latitude: 16},
},
}
joined := JoinPolylineSegments(segments)
if len(joined) != 4 {
t.Fatalf("joined point count = %d, want 4", len(joined))
}
if absoluteLongitude(joined[0].Longitude) > 90 || absoluteLongitude(joined[len(joined)-1].Longitude) > 90 {
t.Fatalf("joined open endpoints are on the antimeridian: first=%+v last=%+v", joined[0], joined[len(joined)-1])
}
if angularDistanceDegrees(joined[1], joined[2]) > 3 {
t.Fatalf("nearest antimeridian endpoints were not joined: %+v -> %+v", joined[1], joined[2])
}
}
func TestSphericalPolygonsContainPointsMatchesIndividualPathChecks(t *testing.T) {
polygons := [][]GeoPoint{{
{Longitude: -20, Latitude: -10},
{Longitude: 20, Latitude: -10},
{Longitude: 20, Latitude: 10},
{Longitude: -20, Latitude: 10},
}}
points := []GeoPoint{
{Longitude: 0, Latitude: 0},
{Longitude: 20, Latitude: 0},
{Longitude: 40, Latitude: 0},
}
got := SphericalPolygonsContainPoints(polygons, points)
if len(got) != len(points) {
t.Fatalf("result count=%d, want %d", len(got), len(points))
}
for index, point := range points {
want := SphericalPolygonsContainPaths(polygons, [][]GeoPoint{{point}}, false)
if got[index] != want {
t.Fatalf("point %d result=%v, want %v", index, got[index], want)
}
}
}
func absoluteLongitude(value float64) float64 {
if value < 0 {
return -value
}
return value
}
func TestSphericalContainmentRejectsAntipodalInterior(t *testing.T) {
for _, center := range []GeoPoint{{}, {Longitude: 179, Latitude: 70}, {Latitude: -90}} {
polygon := SphericalCircle(center, 12, 48)
antipode := GeoPoint{Longitude: NormalizeLongitude(center.Longitude + 180), Latitude: -center.Latitude}
for _, reversed := range []bool{false, true} {
if reversed {
for first, last := 0, len(polygon)-1; first < last; first, last = first+1, last-1 {
polygon[first], polygon[last] = polygon[last], polygon[first]
}
}
if !sphericalPolygonContainsOrTouches(polygon, center) || sphericalPolygonContainsOrTouches(polygon, antipode) {
t.Errorf("center=%+v reversed=%v: direct containment must distinguish the antipode", center, reversed)
}
points := []GeoPoint{center, antipode, polygon[0], {
Longitude: NormalizeLongitude(polygon[0].Longitude + 180), Latitude: -polygon[0].Latitude,
}}
got := SphericalPolygonsContainPoints([][]GeoPoint{polygon}, points)
for index, want := range []bool{true, false, true, false} {
if got[index] != want {
t.Errorf("center=%+v reversed=%v point=%+v contains=%v want=%v", center, reversed, points[index], got[index], want)
}
}
}
}
// These components cannot share a gnomonic chart. The spherical fallback
// must also distinguish each component from its antipodal image.
polygons := [][]GeoPoint{
SphericalCircle(GeoPoint{}, 12, 48),
SphericalCircle(GeoPoint{Longitude: 160}, 12, 48),
}
got := SphericalPolygonsContainPoints(polygons, []GeoPoint{{}, {Longitude: 160}, {Longitude: 180}, {Longitude: -20}})
for index, want := range []bool{true, true, false, false} {
if got[index] != want {
t.Errorf("disjoint components: point %d contains=%v want=%v", index, got[index], want)
}
}
}
func TestSphericalCircleRejectsDegenerateRadii(t *testing.T) {
center := GeoPoint{Longitude: 10, Latitude: 20}
for _, radius := range []float64{0, -1, 180, 181, math.Inf(1), math.NaN()} {
if circle := SphericalCircle(center, radius, 32); len(circle) != 0 {
t.Fatalf("radius %v produced %d points, want none", radius, len(circle))
}
}
if circle := SphericalCircle(center, 1, 32); len(circle) != 32 {
t.Fatalf("valid radius produced %d points, want 32", len(circle))
}
}
func TestJoinPolylineSegmentsDropsSharedJunctionVertex(t *testing.T) {
first := []GeoPoint{{Longitude: 0, Latitude: 0}, {Longitude: 1, Latitude: 1}}
second := []GeoPoint{{Longitude: 1, Latitude: 1}, {Longitude: 2, Latitude: 0}}
for _, segments := range [][][]GeoPoint{{first, second}, {second, first}} {
joined := JoinPolylineSegments(segments)
if len(joined) != 3 {
t.Fatalf("joined=%v, want three points", joined)
}
for index := 1; index < len(joined); index++ {
if SameGeoPoint(joined[index-1], joined[index]) {
t.Fatalf("joined=%v keeps the shared junction twice", joined)
}
}
}
}