plotter: HeatMap panics if h.Min = -inf
- Dominant language
- Go
- Stars
- 3k
- Forks
- 201
- PR merge metrics
- No merged PRs in 30d
Description
While calling plot.Save
```
gonum.org/v1/plot/plotter.(*HeatMap).Plot(0xc42006a360, 0x13d8220, 0xc42052c420, 0x403e70933333332f, 0x4037d0c666666662, 0x4071f23ecccccccd, 0x4071f3fb9999999a, 0xc42042e000)
/Users/brendan/Documents/mygo/src/gonum.org/v1/plot/plotter/heat.go:171 +0x1268
gonum.org/v1/plot.(*Plot).Draw(0xc42042e000, 0x13d8120, 0xc420088d80, 0x0, 0x0, 0x4072000000000000, 0x4072000000000000)
/Users/brendan/Documents/mygo/src/gonum.org/v1/plot/plot.go:165 +0x84c
gonum.org/v1/plot.(*Plot).WriterTo(0xc42042e000, 0x4072000000000000, 0x4072000000000000, 0x1396f61, 0x3, 0x1, 0x1, 0xc42000e790, 0xc42042e398)
/Users/brendan/Documents/mygo/src/gonum.org/v1/plot/plot.go:445 +0x136
gonum.org/v1/plot.(*Plot).Save(0xc42042e000, 0x4072000000000000, 0x4072000000000000, 0x1396f5b, 0x9, 0x0, 0x0)
/Users/brendan/Documents/mygo/src/gonum.org/v1/plot/plot.go:471 +0x130
```
The problem is that the calculation on heat.go171 is `fmt.Println(int((v-h.Min)*ps + 0.5))`. When `h.Min = -inf`, then `ps = 0`, which means the calculation is `NaN`, and the interpreted integer is a very negative integer which panics on the bound.
I'm not sure what the fix is, Scatter et. al. have errors returned in creation, maybe this should be the case as well? Or maybe the non-inf min should be calculated to allow default special casing.
Contributor guide
Assessment
This issue has not been assessed yet.