CLIM mail archive

[Prev][Next][Index][Thread]

Rendering of shapes and line style thickness



    Date: Thu, 16 Sep 1993 18:25 EDT
    From: Brian Anderson 234-0878 <bha@ata.ca.boeing.com>

    I am trying to draw concentric shapes (such as rectangles, ellipses,
    etc.) and am having problems with making them be drawn *truly*
    concentric.  It seems that very often I am wrong by one pixel on two
    of the axes depending on the line style thickness that I use to draw
    the (unfilled) shape.  I presume that CLIM's rendering model is biting
    me here.

    So, is the below analysis correct?

    Assume that I have a line style thickness of 3.
    The "x" symbol denotes the corner of the rectangle.
    Is the outline for the rectangle is then drawn as follows?

	 .......................
	 .x...................x.
	 .......................
	 ...                 ...
	 ...                 ...
	 ...                 ...
	 ...                 ...
	 ...                 ...
	 .......................
	 .x...................x.
	 .......................

The outline for a rectangle of thickness 3 is certainly defined to be
what you have drawn above.  Whether or not each CLIM port implements
this correctly is another question entirely.

    Assume that I have a line style thickness of 2.  Is the outline then
    drawn as follows?  That is, the inside of the shape does *not* include
    the bottom row or right column of pixels?  (Section 12.4 of the CLIM2
    spec on rendering conventions for geometric shapes.)

	 ........................
	 .x...................x..
	 ..                    ..
	 ..                    ..
	 ..                    ..
	 ..                    ..
	 ..                    ..
	 ..                    ..
	 ..                    ..
	 .x                   x..
	 ........................
	 ........................

Even though I wrote this part of the spec, I always get nailed by the
fencepost issues here.  But I think the above shape is not correct, and
the correct shape is actually the following.  Maybe <:-(

     ........................
     ........................
     ..x                   x.
     ..                    ..
     ..                    ..
     ..                    ..
     ..                    ..
     ..                    ..
     ..                    ..
     ..                    ..
     ..x...................x.
     ........................

    What I really want to do is draw an outline around the *outside* of a
    rectangle.  Something like:

In that case, you have to offset your coordinates by the "right" amount,
as you surmise below.  No matter what convention we had chosen for CLIM
(whether line thicknesses are centered, inside, or outside), there will
always be cases where the coordinates have to be offset.  The choice to
center the thickness was mostly arbitrary, although I think both Genera
and X Windows use this convention.

       ...........................
       ...........................
       ...........................
       ...x                   x...
       ...                     ...
       ...                     ...
       ...                     ...
       ...                     ...
       ...                     ...
       ...                     ...
       ...                     ...
       ...x                   x...
       ...........................
       ...........................
       ...........................

    And:

	.........................
	.........................
	..x                   x..
	..                     ..
	..                     ..
	..                     ..
	..                     ..
	..                     ..
	..                     ..
	..                     ..
	..x                   x..
	.........................
	.........................


    So, for line odd line thicknesses, I have to adjust the left, top,
    right and bottom coordinates that I draw at by:

      (1+ (- (floor line-thickness 2)))

    and for even line thickesses I have to adjust the left and top
    coordinates that I draw at by:

      (- (floor line-thickness 2))

    Is this correct?  Is there some other mechanism that I'm missing here?
    I presume that this will work similarly for ellipses?

Yes, the above is correct.  And it is supposed to work for ellipses.

One caveat, though.  It turns out to be much, much harder than it should
be to get the various window systems all to have consistent behavior,
even with "simple" shapes like rectangles and axis-aligned line
segments.  So you may have to mess around with stuff to get it just
right on all platforms.  If there are obvious mismatches, send more
mail detailing your results.

References:

Main Index | Thread Index