[comp.windows.x] X11 rectangles

RWS@ZERMATT.LCS.MIT.EDU (Robert Scheifler) (10/07/87)

    Date: Wed, 7 Oct 87 07:36:03 pdt
    From: sequent!gssc!rrs@decwrl.dec.com (Russ Sprunger)
	
    SYNOPSIS:
	    In the Xlib and Protocol Spec. documents, the definition of how 
	    a rectangle is drawn produces a rectangle with the width and height one
	    pixel larger than specified.  Is this correct behavior?

Yes, it is, and it is consistent with the rest of the protocol.  A rectangle
defined as [x,y,width,height] should first be viewed as an infinitely thin path
with vertices at [x,y] [x+width,y] [x+width,y+height] [x,y+height] [x,y].
Remember that in X coordinates are at the centers of the pixels.  If you view
the pixels as abutting circles (or ellipses), and you measure the width and
height of the path, you will find it is "width" units wide and "height" units
high.

Now, if you go to fill this path, the semantics of boundary inclusion for
filling a closed shape will cause the right and bottom edges to not be
included, so that actual number of pixels lit will be match width and height.
This is consistent with the definition of a rectangle as used elsewhere in the
protocol (e.g., for clipping).  However, when you go to draw a line on this
path, you superimpose an N-pixel-wide rectangle along each segment of the path,
and the result is as you indicate.  I believe this is all perfectly consistent,
although you may well find it counter-intuitive.

    REPEAT-BY:
	    I was using the XDrawRectangle function to draw an outline to a pixmap
	    that I created.  The following code was used to create the pixmap, draw
	    the outline and copy the pixmap to the screen.

It is important to note that X does not provide explicit support for
"outlining" (for which there are probably several definitions) or for the
edge/interior distinctions found in certain graphics standards, and that the
"obvious" attempts within X will probably fail.  That is, various people have
assumed that for a given shape, the pixels lit by drawing lines with that shape
are completely disjoint from (or are completely a subset of) the pixels lit by
filling that shape.  That is not the case.  One way to achieve such an effect
would be to specify non-integral coordinates, but that is not part of core X.