fix(plot): keep extreme finite ranges drawable
Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -103,6 +103,39 @@ func TestWriteSVGErrors(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestWriteSVGExtremeFiniteValuesStayFinite pins the renderer against
|
||||
// the extreme-but-finite corner: data, or an explicit axis range, whose
|
||||
// span overflows float64 must not leak NaN or Inf coordinates into the
|
||||
// drawing, because no renderer displays them and the non-finite
|
||||
// refusal at the door guarantees every input point is finite.
|
||||
func TestWriteSVGExtremeFiniteValuesStayFinite(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
padded := sampleChart()
|
||||
padded.XRange = [2]float64{-1e308, 1e308}
|
||||
padded.YRange = [2]float64{-1e308, 1e308}
|
||||
charts := []struct {
|
||||
name string
|
||||
chart Chart
|
||||
}{
|
||||
{"wide-data.svg", Chart{Series: []Series{{Name: "wide",
|
||||
Points: []Point{{X: 0, Y: -1e308}, {X: 1, Y: 1e308}}}}}},
|
||||
{"wide-range.svg", padded},
|
||||
}
|
||||
for _, tc := range charts {
|
||||
path := filepath.Join(dir, tc.name)
|
||||
if err := tc.chart.WriteSVG(path); err != nil {
|
||||
t.Fatalf("%s: %v", tc.name, err)
|
||||
}
|
||||
body, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v", tc.name, err)
|
||||
}
|
||||
if s := string(body); strings.Contains(s, "NaN") || strings.Contains(s, "Inf") {
|
||||
t.Fatalf("%s: the rendering leaked a non-finite coordinate: %s", tc.name, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mustFromFloats(t *testing.T, values []float64, shape ...int) *core.Array {
|
||||
t.Helper()
|
||||
a, err := core.FromFloats(values, shape...)
|
||||
|
||||
Reference in New Issue
Block a user