width of rectangle
sounds like very easy question but very often I am confused by this. Please catch where I am wrong.
left = 0
right = 10 width = right - left = 10 (used by android)Now, if we draw this rectangle on screen, it goes from 0th pixel to 10th pixel, which means it occupies total of 11 pixels, so it's width is 11.开发者_JS百科
right should be left + width - 1 => width = right - left + 1 so when left = 0, right = 9 and we're happy.
Try drawing a rectangle with left = right and both should be 0. I have forgotten but sometime back while using QT, I had found a problem because of this. it was returning width as 0 for 1x1 rectangle.I think for frameworks following former approach, it's assumed that left is included and right is excluded in all drawing functions so that only pixels = width are affected?
When drawing lines on a raster, such as a pixel screen, the common convention is that integer coordinates lie on pixel centers, not corners.
Have a look at Bresenham's line algorithm.
A very good definition of pixel coordinates can be found in Paul S. Heckbert's article in Graphics Gems 4: "What are the coordinates of a pixel?"
Unfortunately it sounds like Android is giving you a non-standard definition.
精彩评论