gg
gg copied to clipboard
invalid plot when increasing number of lines
hi there,
running the following program:
package main
import (
"flag"
"github.com/fogleman/gg"
)
func main() {
const (
W = 1024.0
H = 1024.0
)
nn := flag.Int("n", 1000, "number of lines")
flag.Parse()
var (
N = float64(*nn)
dx = float64(W) / float64(*nn)
ylow = H / 3.0
yhi = 2.0 * H / 3.0
)
dc := gg.NewContext(W, H)
dc.SetRGB(1, 1, 1)
dc.Clear()
dc.SetRGB(0, 0, 0)
dc.SetLineWidth(1)
var (
x = 0.0
y = ylow
)
dc.MoveTo(x, y)
for i := 1; i < *nn; i++ {
j := float64(i)
x += dx
switch {
case j < 0.1*N:
y = ylow
case 0.1*N <= j && j < 0.5*N:
y = yhi
case 0.5*N <= j && j < 0.55*N:
y = ylow
case 0.55*N <= j && j < 0.9*N:
y = yhi
default:
y = ylow
}
dc.LineTo(x, y)
}
dc.Stroke()
dc.SavePNG("out.png")
}
with -n=1000
draws the following plot:
but when increasing to e.g. 10000, it gives the following one:
behaviour uncovered in gonum/plot#559
(this was using [email protected]
)
gentle ping :)
I don't know where to begin with... but if you give me a hand I could try to help tackle this
That's strange indeed. I suspect it may be a bug in the underlying freetype/raster
package.
This effect occurs near around 8200 with a significant discontinuity at 8192. Given the precision of fixed.Int26_6
, this piqued my curiosity as to whether there was adjacent comparisons between values in this type. Yep! Removing this call to flattenPath
fixes the rendering issue here. Reducing the constant here to 4 also fixes the problem — this was previously 4, but there is no issue associated with the change, so I can't see what happens when I do this (as far as I can see, there is no substantive change to the test images).
I took upon myself to steal @kortschak fix and provide it as a PR: https://github.com/fogleman/gg/pull/148
@kortschak it seems gg
isn't a super reactive repo anymore...
(my other PR, sent in Dec 2020, to add Go-modules support hasn't been merged yet)
I'll give it another 2 weeks but... pfff. what should we do here? (I know I can't correctly maintain yet another fork)
Yeah. I don't know. There aren't any others are there?
I have forked fogleman/gg
to https://sr.ht/~sbinet/gg