home *** CD-ROM | disk | FTP | other *** search
/ gdead.berkeley.edu / gdead.berkeley.edu.tar / gdead.berkeley.edu / pub / cad-tools / ciftomann.tar / edger_dir / proc_polygon.c < prev    next >
C/C++ Source or Header  |  1988-01-28  |  2KB  |  106 lines

  1. #include "parser.h"
  2. #include "ciftomann.h"
  3.  
  4. #define EdgeType(first,last) ( first->x == last->x ? \
  5.                 ( first->y == last->y ? IDENTICAL : VERTICAL ) :\
  6.                 ( first->y == last->y ? HORIZONTAL : NON_MANHATTEN ) )
  7.  
  8. #define MAXEDGES  128
  9.  
  10. #define HORIZONTAL    0
  11. #define VERTICAL    1
  12. #define IDENTICAL    2
  13. #define NON_MANHATTEN    3
  14.  
  15. EDGE EdgeArray[MAXEDGES];
  16. int NumEdges;
  17. int ArrayIndex;
  18.  
  19. int comparer();
  20.  
  21. proc_polygon(path)
  22. point *path;
  23. {
  24.     
  25.     NumEdges = 0;
  26.     ArrayIndex = 0;
  27.  
  28.     if ( BuildList(path) == ERROR || NumEdges < 2) 
  29.     return(ERROR);
  30.     
  31.     qsort(EdgeArray,NumEdges,sizeof(EDGE),comparer);
  32.  
  33. #ifdef DEBUG
  34.     {
  35.     int i;
  36.     for (i=0;i<NumEdges;i++) 
  37.         fprintf(stderr,"%d,%d at %d : sense = %d\n",EdgeArray[i].x,
  38.             EdgeArray[i].xend, EdgeArray[i].y,EdgeArray[i].sense);
  39.     }
  40. #endif
  41.  
  42.     edge_polygon();
  43.     return(GOOD);
  44.  
  45. }
  46.     
  47. BuildList(path)
  48. point *path;
  49. {
  50.  
  51.     point *first,*last;
  52.  
  53.     last = first = path;
  54.  
  55.     while (path->next  != 0) {
  56.  
  57.     path = path->next;
  58.  
  59.     if (CheckAsEdge(last,path) == ERROR)
  60.         return(ERROR);
  61.     last = path;
  62.     }
  63.  
  64.     if (CheckAsEdge(last,first) == ERROR)
  65.     return(ERROR);
  66.  
  67.     return(GOOD);
  68. }
  69.  
  70. CheckAsEdge(last,next)
  71. point *last,*next;
  72. {
  73.  
  74.     switch ( EdgeType(last,next) ) {
  75.     
  76.     case HORIZONTAL :
  77.     
  78.         EdgeArray[NumEdges].y = last->y;
  79.  
  80.         if (last->x < next->x) {
  81.         EdgeArray[NumEdges].sense = 1;
  82.         EdgeArray[NumEdges].x = last->x;
  83.         EdgeArray[NumEdges].xend = next->x;
  84.         }
  85.         else {
  86.         EdgeArray[NumEdges].sense = -1;
  87.         EdgeArray[NumEdges].x = next->x;
  88.         EdgeArray[NumEdges].xend = last->x;
  89.         }
  90.     
  91.         NumEdges++;
  92.  
  93.         break;
  94.  
  95.     case VERTICAL :
  96.     case IDENTICAL :
  97.         break;
  98.  
  99.     case NON_MANHATTEN :
  100.         error("Non-Manhatten edge in polygon at (%d,%d)\n",next->x,next->y);
  101.         return(ERROR);
  102.     
  103.     }
  104.     return(GOOD);
  105. }
  106.