Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix half-pixel offsets #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Pascal-So
Copy link

In plotters-rs/plotters#165 the tick lines look like they're two pixels wide instead of one as intended, as well as at half opacity, which would indicate that the error comes from the line being rendered on the border between two pixel rows instead of within one row of pixels.

This change moves line endpoints by +0.5 in both the x and y direction so that the endpoints lie in the centers of pixels. That by itself however would leave the pixels at the line ends only half-covered, so we need to add the square linecap to the lines which then completely fills up the endpoint pixels.

Here is the new behaviour of the wasm-demo example when selecting "Graph of y=x^3" in the drop-down.
canvas-1
canvas-2
canvas-3

A downside of this approach is that this slightly changes the behaviour of line-width. A LineSeries with width 20 will now continue for 10 more pixels on either side. Is this a problem? See example here:

image

@redforks
Copy link
Contributor

Maybe no need to offset 0.5 pixel everywhere, hack vertical/horizontal line would fix most problems,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants