[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

720.0. "Polygon Filling problem" by AVIATE::SHAH (LDP Technical Consulting Group) Wed May 03 1989 09:17

I'm supporting a partner who's having problems filling polygons.  He's 
provided a simple application that he claims is creating problems.  I've
attached the C code to the end of this note.  The following inputs
to the program create the problem:

	1) XPRIMIT 30 30 0 360 0
		- should be a circle but isn't symmetrical

	2) XPRIMIT 19 19 90 90 0
		- should fill in an arc, but some dots aren't filled

	3) XPRIMIT 45 55 90 90 10
		- should be a filled arc, but the filling is incorrect

He claims that except for filling rectangles, there seems to be no way
of filling without the fill overlapping the outside frame.  Has anyone
else experienced this problem?  


To use the program, just click within the window.  This will magnify the
image to show how the pixels are filled.

Thanks in advance,
-Pratish

------------------------------ XPRIMIT.C --------------------------------------

#include <decw$include/xlib.h>
#include <decw$include/xutil.h>
#include <stdio.h>

#define SIZE 64

#define screen DefaultScreen(display)
#define rootWindow RootWindow(display, screen)
#define displayWidth DisplayWidth(display, screen)
#define displayHeight DisplayHeight(display, screen)
#define blackPixel BlackPixel(display, screen)
#define whitePixel WhitePixel(display, screen)
#define defaultGC DefaultGC(display, screen)
#define forever while(1)

GC gc;
Pixmap bit;
Display *display;
Window window;

main(argc, argv)
int argc;
char *argv[];
{
   XColor colorDef, dummy;
   unsigned long redPixel;
   int arcX, arcY, arcWidth, arcHeight, arcAngle1, arcAngle2, fudge;

   if (!(display = XOpenDisplay(NULL))) {
      printf("Can't open display!\n");
      exit(0);
   }

   arcWidth = atoi(argv[1]);
   arcHeight = atoi(argv[2]);
   arcAngle1 = atoi(argv[3]) * 64;
   arcAngle2 = atoi(argv[4]) * 64;
   fudge = atoi(argv[5]) * 64;
   arcX = (SIZE - arcWidth) / 2;
   arcY = (SIZE - arcHeight) / 2;
   bit = XCreatePixmap(display, rootWindow, SIZE, SIZE,
                       DefaultDepth(display, screen));

   gc = XCreateGC(display, rootWindow, NULL, NULL);

   XAllocNamedColor(display, DefaultColormap(display, screen), "Red",
                    &colorDef, &dummy);
                    
   redPixel = colorDef.pixel;

   XSetForeground(display, gc, whitePixel);
   XSetBackground(display, gc, whitePixel);
   XFillRectangle(display, bit, gc, 0, 0, SIZE, SIZE);
   
   XSetForeground(display, gc, blackPixel);
   XFillArc(display, bit, gc, arcX, arcY,
            arcWidth, arcHeight, arcAngle1 - fudge, arcAngle2 + 2 * fudge);

   XSetForeground(display, gc, redPixel);
   XDrawArc(display, bit, gc, arcX, arcY,
            arcWidth, arcHeight, arcAngle1, arcAngle2);
   XDrawPoint(display, bit, gc, arcX, arcY);

   window = XCreateSimpleWindow(display, rootWindow, 150, 150, 449, 449, 1,
                                blackPixel, whitePixel);

   XSelectInput(display, window,
                ExposureMask | ButtonPressMask);

   XMapWindow(display, window);
   forever {
      XEvent event;
      static int firstTime = TRUE;

      XNextEvent(display, &event);
      switch (event.type) {
         case Expose:
            if (firstTime) {
               XCopyArea(display, bit, window, gc, 0, 0, SIZE, SIZE, 200, 200);
            } else {
               DrawGrid();
               FillGrid();
            }
            break;
         case ButtonPress:
            if (firstTime) {
               XClearWindow(display, window);
               DrawGrid();
               FillGrid();
               firstTime = FALSE;
            } else {
               exit(1);
            }
            break;
      }
   }
}

DrawGrid()
{
   int i;

   XSetForeground(display, gc, blackPixel);
   for (i = 0; i < 65; ++i) {
      XDrawLine(display, window, gc, 0, i * 7, 448, i * 7);
      XDrawLine(display, window, gc, i * 7, 0, i * 7, 448);
   }
}

FillGrid()
{
   static XImage *pixImage;
   static int firstTime = TRUE;
   int i, j;
   static unsigned long pix[SIZE][SIZE];

   if (firstTime) {
      pixImage = XGetImage(display, bit, 0, 0, SIZE, SIZE, AllPlanes, ZPixmap);
   }
   for (i = 0; i < SIZE; ++i) {
      for (j = 0; j < SIZE; ++j) {
         if (firstTime) {
            pix[i][j] = XGetPixel(pixImage, i, j);
         }
         XSetForeground(display, gc, pix[i][j]);
         XFillRectangle(display, window, gc, i*7 + 1, j*7 + 1, 6, 6);
      }
   }
   if (firstTime) {
      XDestroyImage(pixImage);
      firstTime = FALSE;
   }
   
}


T.RTitleUserPersonal
Name
DateLines
720.1Asking again...22082::SHAHLDP Technical Consulting GroupMon May 15 1989 12:0713

I know if the same variables are sent to a FILL routine as to a DRAW routine,
the fill and the line from the DRAW won't exactly coincide.  My CMP is trying
to draw arcs that are filled with a color and then they want the ouline of the 
arc another color.  Since FILL and DRAW don't exactly overlap, is there a work 
around to this problem?  This problem was shown in the previous note with an
example code....Any help is appreciated.....


Thank,
-Pratish

720.2narrow it down?32291::FRANCUSMets in &#039;89Mon May 15 1989 14:027
    Take it one step further. The fill problem seems to appear only
    when you are filling in an arc that has its starting point somewhere
    between 270 and 360.
    
    yoseff
    

720.3fixed in upgrade32291::FRANCUSMets in &#039;89Sun May 21 1989 20:275
    Problem appears to be fixed in UWS2.1 (maintenance release to UWS2.0)
    
    yoseff