Its probably not a strange phenomenon but rather developer blunder. I am writing an app in which I can draw shapes on a canvas. I have a grid to which I am snapping 10 x 10 pixels. When I draw a line (see below) it is snapped to the grid, rectangle to grid, polygon snaps, oval snaps etc.
You will see though for some strange reason the bottom and right lines of the rect, rounded rect and oval are one pixel to the left and up from the grid.
I won’t post code as its massive but I have checked the values I am passing to canvas.drawrect and they are on the grid and also checked my grid and it is 10 x 10. Is there some simple reason I am missing that the shapes are missing the grid by 1 pixel.
[quote=112914:@Norman Palardy]the grid would be set from 0 - 9, 10-19, etc
and then make sure you’re 10 pixel wide item also draws from 0 - 9 and not 1 - 10[/quote]
Thanks Norman, I think that is the issue. I have just zoomed in and counted pixels and my grid is 11 pixels wide as I am looping 0 to 10. I’ll have a re-jig
You just have to draw one pixel wider and taller than you think, in order to encompass the grid lines. You’re drawing exactly right, if you wanted 2 rectangles side by side with no overlap. But you want the overlap.
[quote=112954:@Mike Charlesworth]This must be a bug. Try the following code in the paint event of a canvas:
Before you run it wouldn’t you expect the second rectangles left face line be on the same line as the first rectangles right hand face? or am I going mad?[/quote]
the first draws from 0-49 (50 pixels)
the second draws starting at 50 - 1 pixel over
No, your 10x10 grid is correct. There are indeed 10 pixels from one gridline to the next. But that doesn’t count both gridlines. If you want to encompass both gridlines, you have to draw an extra pixel to do it. It’s pretty standard stuff for drawing computer graphics. At least in my experience.