16c62a97d5
- 新增时标、ΔT 模型、质心时间与 UT1 支持 - 改进日月食、月掩、行星事件及路径边界计算 - 完善恒星三维自行与动态距离传播 - 扩展 SVG、GeoJSON、KML 输出与底层距离换算工具 - 整理中英文手册、示例资源及回归测试
58 lines
2.1 KiB
Go
58 lines
2.1 KiB
Go
package geodata
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
)
|
|
|
|
// 居中后的等经纬接缝必须落在视图中心对面;旋转前后地理点集合应当一致。
|
|
func TestPolygonFragmentsCentredSeamKeepsGeometry(t *testing.T) {
|
|
// 密集采样,避免矩形边在大圆上鼓向极点——库按大圆处理边,稀疏顶点会放大这个效应。
|
|
ring := make([]GeoPoint, 0, 240)
|
|
for longitude := -60.0; longitude <= 60; longitude += 2 {
|
|
ring = append(ring, GeoPoint{Longitude: longitude, Latitude: -30})
|
|
}
|
|
for longitude := 60.0; longitude >= -60; longitude -= 2 {
|
|
ring = append(ring, GeoPoint{Longitude: longitude, Latitude: 30})
|
|
}
|
|
plain := PolygonFragments(ring, ClipView{Projection: ProjectionEquirectangular})
|
|
if len(plain) != 1 {
|
|
t.Fatalf("uncentred: got %d fragments, want 1", len(plain))
|
|
}
|
|
// 中心放在 176.269°E 时接缝落到 -3.73°,这个环横跨接缝,应当被切成两段。
|
|
centred := PolygonFragments(ring, ClipView{
|
|
Projection: ProjectionEquirectangular,
|
|
Center: GeoPoint{Longitude: 176.269},
|
|
})
|
|
if len(centred) != 2 {
|
|
t.Fatalf("centred: got %d fragments, want 2", len(centred))
|
|
}
|
|
for _, fragment := range centred {
|
|
if len(fragment) < 3 {
|
|
t.Fatalf("fragment has %d points", len(fragment))
|
|
}
|
|
for _, point := range fragment {
|
|
// 分段用地图窗口坐标表示(居中经线 ±180),折回 -180…180 后再比对。
|
|
if longitude := normalizeLongitude180(point.Longitude); longitude < -60-1e-6 || longitude > 60+1e-6 {
|
|
t.Fatalf("fragment longitude %.3f escaped the ring", longitude)
|
|
}
|
|
if math.Abs(point.Latitude) > 30+0.5 {
|
|
t.Fatalf("fragment latitude %.3f escaped the ring", point.Latitude)
|
|
}
|
|
}
|
|
}
|
|
// 两段拼起来的经度跨度和应等于原环的 120°。
|
|
total := 0.0
|
|
for _, fragment := range centred {
|
|
minLon, maxLon := fragment[0].Longitude, fragment[0].Longitude
|
|
for _, point := range fragment[1:] {
|
|
minLon = math.Min(minLon, point.Longitude)
|
|
maxLon = math.Max(maxLon, point.Longitude)
|
|
}
|
|
total += maxLon - minLon
|
|
}
|
|
if math.Abs(total-120) > 4 {
|
|
t.Fatalf("fragment longitude span %.3f, want about 120", total)
|
|
}
|
|
}
|