feat: 完善日月食与月掩几何链路并扩展历法接口
- 新增日月食中心带、偏食带、阴影足迹、等时线、食分线及升落边界计算,支持极区与混合食拓扑 - 新增日食单时刻阴影求解器、站心状态查询、批量采样和 ΔT 覆盖接口 - 重构恒星与行星月掩路径,补充有限盘面接触、站心修正、掩带宽度、极区投影及升落边界 - 扩展 SVG 与 GeoJSON 输出,支持详细面板、全球/极区/地球投影、边界闭合、时间标记和拓扑签名 - 扩展日月食候选搜索、局地搜索、沙罗序列预计算与范围外推,补充系列锚点和成员一致性校验 - 补齐古历纪年、儒略历独有闰日、多公历候选、历法改革跨日及精确日期运算接口 - 优化 ΔT、章动、恒星时、月球地平线、事件根搜索和本地星历缓存,降低重复计算开销并提升边界稳定
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package geodata
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestJoinPolylineSegmentsUsesBothResultEndpoints(t *testing.T) {
|
||||
segments := [][]GeoPoint{
|
||||
@@ -25,9 +28,99 @@ func TestJoinPolylineSegmentsUsesBothResultEndpoints(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user