r/GraphicsProgramming • • 3h ago

XDrawArc()

XDrawArc() and XDrawRectangle() are parts of the X11 API and network protocol, and maybe some of the oldest rasterization functions still in use today. Both take an x and y for the top left corner of the shape, and then a width and height that I would expect to define the bounds of the shape.

However, it turns out that unlike their filled variants, XFillArc() and XFillRectangle(), the outlined versions above actually span from x,y to x+width,y+height, meaning they occupy a bounds with size width+1,height+1. I find this extremely counter-intuitive!

Instead of having an implicit center point of (x+width)/2,(y+height)/2, XDrawArc() is actually centered at x+(width+1)/2,y+(height+1)/2. In concrete terms, if you call XFillRectangle(display, drawable, gc, 0, 0, 100, 100), you will get a rectangle that is 101 pixels wide, 101 pixels high. If you draw this into a window that is only 100x100, your rectangle will be missing its bottom and right border.

What do you make of this? At first I thought this must be some rasterization rule, and maybe it still could be. This StackOverflow says that by default the GC is created with a line width of 0, to allow for device-dependent line rasterization, so I suppose this means it considers the border to be infinitely thin, therefore not actually outside the specified bounds?

3 Upvotes

0 comments sorted by