fogleman / gg

Go Graphics - 2D rendering in Go with a simple API.
https://godoc.org/github.com/fogleman/gg
MIT License
4.39k stars 355 forks source link

Draw straight vertical\horizontal line 1px width #90

Closed fordarian closed 4 years ago

fordarian commented 4 years ago

Hello. I need to draw some grids with 1 pixel wide lines. But LineTo\DrawLine functions produce 2px wide lines, even with SetLineWidth(1). The coordinates have no fractured parts. The only way i managed to plot them correctly is using SetPixel function. Is it the only and correct way?

fogleman commented 4 years ago

You need to offset them by 0.5 to get crisp lines. This is common for antialiasing rasterizers: http://usefulangle.com/post/17/html5-canvas-drawing-1px-crisp-straight-lines

fogleman commented 4 years ago

There's already an example in the repo here:

https://github.com/fogleman/gg/blob/master/examples/crisp.go

fordarian commented 4 years ago

Works perfect, thank you!