2bf8478639
- 新增日月食中心带、偏食带、阴影足迹、等时线、食分线及升落边界计算,支持极区与混合食拓扑 - 新增日食单时刻阴影求解器、站心状态查询、批量采样和 ΔT 覆盖接口 - 重构恒星与行星月掩路径,补充有限盘面接触、站心修正、掩带宽度、极区投影及升落边界 - 扩展 SVG 与 GeoJSON 输出,支持详细面板、全球/极区/地球投影、边界闭合、时间标记和拓扑签名 - 扩展日月食候选搜索、局地搜索、沙罗序列预计算与范围外推,补充系列锚点和成员一致性校验 - 补齐古历纪年、儒略历独有闰日、多公历候选、历法改革跨日及精确日期运算接口 - 优化 ΔT、章动、恒星时、月球地平线、事件根搜索和本地星历缓存,降低重复计算开销并提升边界稳定
76 lines
2.7 KiB
Go
76 lines
2.7 KiB
Go
package svgchart
|
|
|
|
import (
|
|
"math"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestEstimatedTextWidthUsesSeparateAsciiAndWideRuneUnits(t *testing.T) {
|
|
if got := EstimatedTextWidth("", 10); got != 0 {
|
|
t.Fatalf("empty text width = %v, want 0", got)
|
|
}
|
|
if got := EstimatedTextWidth("AB", 10); math.Abs(got-12.4) > 1e-9 {
|
|
t.Fatalf("two ASCII runes = %v, want 12.4", got)
|
|
}
|
|
if got := EstimatedTextWidth("中文", 10); math.Abs(got-21) > 1e-9 {
|
|
t.Fatalf("two wide runes = %v, want 21", got)
|
|
}
|
|
above, below := EstimatedTextExtents(10)
|
|
if math.Abs(above-8.5) > 1e-9 || math.Abs(below-3) > 1e-9 {
|
|
t.Fatalf("extents = %v/%v, want 8.5/3", above, below)
|
|
}
|
|
}
|
|
|
|
func TestPanelRowFontSizeShrinksUntilLabelAndValueFit(t *testing.T) {
|
|
row := PanelRow{Label: "地平视差 H.P.", Value: "00°16'21.4\""}
|
|
if got := PanelRowFontSize(320, row); got != panelRowLabelSize {
|
|
t.Fatalf("wide box font = %v, want the base size", got)
|
|
}
|
|
narrow := 170.0
|
|
size := PanelRowFontSize(narrow, row)
|
|
if size >= panelRowLabelSize || size < panelMinimumFontSize {
|
|
t.Fatalf("narrow box font = %v, want a size in [%v,%v)", size, panelMinimumFontSize, panelRowLabelSize)
|
|
}
|
|
content := narrow - 2*panelBoxPadding
|
|
pair := EstimatedTextWidth(row.Label, size) + EstimatedTextWidth(row.Value, size)
|
|
if pair+panelLabelValueGap > content {
|
|
t.Fatalf("shrunk label %v + value %v + gap does not fit %v", pair, panelLabelValueGap, content)
|
|
}
|
|
}
|
|
|
|
func TestPanelBoxOverlapsDetectsCrowdedRows(t *testing.T) {
|
|
rows := []PanelRow{
|
|
{Label: "赤经 R.A.", Value: "23h21m52.2s"},
|
|
{Label: "赤纬 Dec.", Value: "-05°59'26.5\""},
|
|
{Label: "掩甚", Value: "04:28:23", Detail: "90.9407°E, 11.7283°N"},
|
|
{Label: "视半径 S.D.", Value: "00°16'21.4\""},
|
|
}
|
|
if PanelBoxOverlaps(0, 0, 230, 200, "月亮(地心坐标)", rows) {
|
|
t.Fatal("tall box reported overlapping rows")
|
|
}
|
|
if !PanelBoxOverlaps(0, 0, 230, 34, "月亮(地心坐标)", rows) {
|
|
t.Fatal("box too short for its rows reported no overlap")
|
|
}
|
|
if !PanelBoxOverlaps(0, 0, 120, 200, "月亮(地心坐标)", rows) {
|
|
t.Fatal("box too narrow for label and value reported no overlap")
|
|
}
|
|
if PanelBoxOverlaps(0, 0, 230, 200, "标题", nil) {
|
|
t.Fatal("empty block reported an overlap")
|
|
}
|
|
}
|
|
|
|
func TestWritePanelBoxKeepsEveryTextInsideTheBlockWidth(t *testing.T) {
|
|
row := PanelRow{Label: "地平视差 H.P.", Value: "00°16'21.4\""}
|
|
var builder strings.Builder
|
|
WritePanelBox(&builder, "panel", 0, 0, 170, 200, "月亮(地心坐标)", []PanelRow{row})
|
|
document := builder.String()
|
|
labelX := strings.Index(document, `x="12.000"`)
|
|
if labelX < 0 {
|
|
t.Fatalf("label is not drawn at the block padding: %s", document)
|
|
}
|
|
if !strings.Contains(document, `text-anchor="end"`) {
|
|
t.Fatalf("value is not right-anchored: %s", document)
|
|
}
|
|
}
|