Back to index

tetex-bin  3.0
Defines | Functions | Variables
regions.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "types.h"
#include "objects.h"
#include "spaces.h"
#include "regions.h"
#include "paths.h"
#include "curves.h"
#include "lines.h"
#include "pictures.h"
#include "fonts.h"
#include "hints.h"
#include "strokes.h"

Go to the source code of this file.

Defines

#define ISOPTIMIZED(flag)   ((flag)&0x10)
#define MAXEDGE   1000
#define TOP(e)   ((e)->ymin) /* the top of an edge (for readability */
#define BOTTOM(e)   ((e)->ymax) /* the bottom of an edge (for readability */
#define INSWATH(p, y0, y1)   (p != NULL && p->ymin == y0 && p->ymax == y1)

Functions

static int Unwind ()
static int newfilledge ()
static struct edgelistsplitedge ()
static int vertjoin ()
static int touches ()
static int crosses ()
static int edgemin ()
static int edgemax ()
static int discard ()
static int edgecheck ()
static struct edgelistNewEdge ()
struct edgelistswathxsort ()
void KillRegion (struct region *area)
struct regionCopyRegion (struct region *area)
static struct edgelistNewEdge (pel xmin, pel xmax, pel ymin, pel ymax, pel *xvalues, int isdown)
struct regionInterior (struct segment *p, int fillrule)
static int Unwind (struct edgelist *area)
void ChangeDirection (int type, struct region *R, fractpel x, fractpel y, fractpel dy, x2, y2)
static int newfilledge (struct region *R, fractpel xmin, fractpel xmax, fractpel ymin, fractpel ymax, int isdown, fractpel x1, fractpel y1, fractpel x2, fractpel y2)
struct edgelistSortSwath (struct edgelist *anchor, struct edgelist *edge, struct edgelist *(*swathfcn)())
static struct edgelistsplitedge (struct edgelist *list, pel y)
static int vertjoin (struct edgelist *top, struct edgelist *bottom)
struct edgelistswathxsort (struct edgelist *before0, struct edgelist *edge)
struct edgelistSwathUnion (struct edgelist *before0, struct edgelist *edge)
struct edgelistswathrightmost (struct edgelist *before, struct edgelist *edge)
static int touches (int h, pel *left, pel *right)
static int crosses (int h, pel *left, pel *right)
static int cedgemin (int h, pel *e1, pel x)
static int cedgemax (int h, pel *e1, pel x)
static int edgemin (int h, pel *e1, pel *e2)
static int edgemax (int h, pel *e1, pel *e2)
static int discard (struct edgelist *left, struct edgelist *right)
void MoveEdges (struct region *R, fractpel dx, fractpel dy)
void UnJumble (struct region *region)
void MoreWorkArea (struct region *R, fractpel x1, fractpel y1, fractpel x2, fractpel y2)
struct regionBoxClip (struct region *R, pel xmin, pel ymin, pel xmax, pel ymax)
struct segmentRegionBounds (struct region *R)
void DumpArea (struct region *area)
void DumpEdges (struct edgelist *edges)
static int edgecheck (struct edgelist *edge, int oldmin, int oldmax)

Variables

struct XYspaceIDENTITY
static struct region
struct regionT1_INFINITY = &infinity
static pel workedge [MAXEDGE]
static pelcurrentworkarea = workedge
static pel currentsize = MAXEDGE
static pel RegionDebugYMin = MINPEL
static pel RegionDebugYMax = MAXPEL

Define Documentation

#define BOTTOM (   e)    ((e)->ymax) /* the bottom of an edge (for readability */

Definition at line 796 of file regions.c.

#define INSWATH (   p,
  y0,
  y1 
)    (p != NULL && p->ymin == y0 && p->ymax == y1)

Definition at line 1700 of file regions.c.

#define ISOPTIMIZED (   flag)    ((flag)&0x10)

Definition at line 128 of file regions.c.

#define MAXEDGE   1000

Definition at line 586 of file regions.c.

#define TOP (   e)    ((e)->ymin) /* the top of an edge (for readability */

Definition at line 795 of file regions.c.


Function Documentation

struct region* BoxClip ( struct region R,
pel  xmin,
pel  ymin,
pel  xmax,
pel  ymax 
) [read]

Definition at line 1575 of file regions.c.

{
       struct edgelist anchor;  /* pretend edgelist to facilitate discards   */
       register struct edgelist *e,*laste;
 
       IfTrace1((OffPageDebug),"BoxClip of %p:\n", R);
 
       R = UniqueRegion(R);
 
       if (xmin > R->xmin) {
               IfTrace2((OffPageDebug),"BoxClip:  left clip old %d new %d\n",
                                            (LONG) R->xmin, (LONG) xmin);
               R->xmin = xmin;
       }
       if (xmax < R->xmax) {
               IfTrace2((OffPageDebug),"BoxClip:  right clip old %d new %d\n",
                                            (LONG) R->xmax, (LONG) xmax);
               R->xmax = xmax;
       }
 
       if (ymin > R->ymin) {
               IfTrace2((OffPageDebug),"BoxClip:  top clip old %d new %d\n",
                                            (LONG) R->ymin, (LONG) ymin);
               R->ymin = ymin;
       }
       if (ymax < R->ymax) {
               IfTrace2((OffPageDebug),"BoxClip:  bottom clip old %d new %d\n",
                                            (LONG) R->ymax, (LONG) ymax);
               R->ymax = ymax;
       }
 
 
       laste = &anchor;
       anchor.link = R->anchor;
 
       for (e = R->anchor; VALIDEDGE(e); e = e->link) {
               if (TOP(e) < ymin) {
                       e->xvalues += ymin - e->ymin;
                       e->ymin = ymin;
               }
               if (BOTTOM(e) > ymax)
                       e->ymax = ymax;
               if (TOP(e) >= BOTTOM(e)) {
                       discard(laste, e->link->link);
                       e = laste;
                       continue;
               }
               if (e->xmin < xmin) {
                       cedgemax(BOTTOM(e) - TOP(e), e->xvalues, xmin);
                       e->xmin = xmin;
                       e->xmax = TYPE1_MAX(e->xmax, xmin);
               }
               if (e->xmax > xmax) {
                       cedgemin(BOTTOM(e) - TOP(e), e->xvalues, xmax);
                       e->xmin = TYPE1_MIN(e->xmin, xmax);
                       e->xmax = xmax;
               }
               laste = e;
       }
 
       R->anchor = anchor.link;
 
       return(R);
}

Here is the call graph for this function:

static int cedgemax ( int  h,
pel e1,
pel  x 
) [static]

Definition at line 1320 of file regions.c.

{
       for (; --h >= 0; e1++)
               if (*e1 < x)
                       *e1 = x;
       return(0);
       
}

Here is the caller graph for this function:

static int cedgemin ( int  h,
pel e1,
pel  x 
) [static]

Definition at line 1305 of file regions.c.

{
       for (; --h >= 0; e1++)
               if (*e1 > x)
                       *e1 = x;
       return(0);
       
}

Here is the caller graph for this function:

void ChangeDirection ( int  type,
struct region R,
fractpel  x,
fractpel  y,
fractpel  dy,
x2  ,
y2   
)

Definition at line 602 of file regions.c.

{
       register fractpel ymin,ymax;  /* minimum and maximum Y since last call */
       register fractpel x_at_ymin,x_at_ymax;  /* their respective X's       */
       register pel iy;      /* nearest integer pel to 'y'                   */
       register pel idy;     /* nearest integer pel to 'dy'                  */
       register int ydiff;   /* allowed Y difference in 'currentworkarea'    */
 
       IfTrace4((RegionDebug>0),"Change Y direction (%d) from (%d,%d), dy=%d\n",
                                         (LONG) type, x, y, dy);
 
       if (type != CD_FIRST) {
 
               if (R->lastdy > 0) {
                       ymin = R->firsty;
                       x_at_ymin = R->firstx;
                       ymax = y;
                       x_at_ymax = x;
               }
               else {
                       ymin = y;
                       x_at_ymin = x;
                       ymax = R->firsty;
                       x_at_ymax = R->firstx;
               }
 
               if (ymax < ymin)
                       abort("negative sized edge?", 32);
 
 
               (*R->newedgefcn)(R, R->edgexmin, R->edgexmax, ymin, ymax,
                            R->lastdy > 0, x_at_ymin, x_at_ymax,
                            x, y, x2, y2);
 
       }
 
       R->firsty = y;
       R->firstx = x;
       R->lastdy = dy;
 
       iy = NEARESTPEL(y);
       idy = NEARESTPEL(dy);
       if (currentworkarea != workedge && idy < MAXEDGE && idy > -MAXEDGE) {
               NonObjectFree(currentworkarea);
               currentworkarea = workedge;
               currentsize = MAXEDGE;
       }
       ydiff = currentsize - 1;
       if (dy > 0) {
               R->edge = &currentworkarea[-iy];
               R->edgeYstop = TOFRACTPEL(ydiff + iy) + FPHALF;
       }
       else {
               R->edge = &currentworkarea[ydiff - iy];
               R->edgeYstop = TOFRACTPEL(iy - ydiff) - FPHALF;
       }
       R->edgexmax = R->edgexmin = x;
/*
If this is the end of a subpath, we complete the subpath circular
chain:
*/
       if (type == CD_LAST && R->lastedge != NULL) {
               register struct edgelist *e = R->firstedge;
 
               while (e->subpath != NULL)
                       e = e->subpath;
               e->subpath = R->lastedge;
               R->lastedge = R->firstedge = NULL;
       }
}

Here is the call graph for this function:

struct region* CopyRegion ( struct region area) [read]

Definition at line 258 of file regions.c.

{
        register struct region *r;  /* output region built here              */
        register struct edgelist *last=NULL;  /* loop variable                    */
        register struct edgelist *p,*newp;  /* loop variables                */
 
        r = (struct region *)Allocate(sizeof(struct region), area, 0);
        r->anchor = NULL;
 
        for (p=area->anchor; VALIDEDGE(p); p=p->link) {
 
               newp = NewEdge(p->xmin, p->xmax, p->ymin, p->ymax, p->xvalues, ISDOWN(p->flag));
              newp->fpx1 = p->fpx1;
              newp->fpx2 = p->fpx2;
              newp->fpy1 = p->fpy1;
              newp->fpy2 = p->fpy2;
              
               if (r->anchor == NULL)
                       r->anchor = last = newp;
               else
                       last->link = newp;
 
               last = newp;
        }
        if (area->thresholded != NULL)
    /* replaced DupPicture with Dup() 3-26-91 PNM */
               r->thresholded = (struct picture *)Dup(area->thresholded);
        return(r);
}

Here is the call graph for this function:

static int crosses ( ) [static]

Here is the caller graph for this function:

static int crosses ( int  h,
pel left,
pel right 
) [static]

Definition at line 1292 of file regions.c.

{
       for (; h > 0; h--)
               if (*left++ > *right++)
                       break;
       return(h);
}
static int discard ( ) [static]

Here is the caller graph for this function:

static int discard ( struct edgelist left,
struct edgelist right 
) [static]

Definition at line 1375 of file regions.c.

{
       register struct edgelist *beg,*end,*p;
 
       IfTrace2((RegionDebug > 0),"discard:  l=%p, r=%p\n", left, right);
 
       beg = left->link;
       if (beg == right)
               return(0);
 
       for (p = beg; p != right; p = p->link) {
               if (p->link == NULL && right != NULL)
                       abort("discard():  ran off end", 38);
               IfTrace1((RegionDebug > 0),"discarding %p\n", p);
               p->ymin = p->ymax = 32767;
               end = p;
       }
       /*
       * now put the chain beg/end at the end of right, if it is not
       * already there:
       */
       if (right != NULL) {
               left->link = right;
               while (right->link != NULL)
                       right = right->link;
               right->link = beg;
       }
       end->link = NULL;
       return(0);
       
}

Here is the call graph for this function:

void DumpArea ( struct region area)

Definition at line 1689 of file regions.c.

{
       IfTrace1(TRUE,"Dumping area %p,", area);
       IfTrace4(TRUE," X %d:%d Y %d:%d;", (LONG) area->xmin,
                      (LONG) area->xmax, (LONG) area->ymin,(LONG) area->ymax);
       IfTrace4(TRUE," origin=(%d,%d), ending=(%d,%d)\n",
               area->origin.x, area->origin.y, area->ending.x, area->ending.y);
       DumpEdges(area->anchor);
}
void DumpEdges ( struct edgelist edges)

Definition at line 1708 of file regions.c.

{
       register struct edgelist *p,*p2;
       register pel ymin = MINPEL;
       register pel ymax = MINPEL;
       register int y;
 
       if (edges == NULL) {
               IfTrace0(TRUE,"    NULL area.\n");
               return;
       }
       if (RegionDebug <= 1) {
               for (p=edges; p != NULL; p = p->link) {
                       edgecheck(p, ymin, ymax);
                       ymin = p->ymin;  ymax = p->ymax;
                       IfTrace3(TRUE,". at %p type=%d flag=%x",
                                        p, (LONG) p->type,(LONG) p->flag);
                       IfTrace4(TRUE," bounding box HxW is %dx%d at (%d,%d)\n",
                               (LONG) ymax - ymin, (LONG) p->xmax - p->xmin,
                               (LONG) p->xmin, (LONG) ymin);
               }
       }
       else {
 
               for (p2=edges; p2 != NULL; ) {
 
                       edgecheck(p2, ymin, ymax);
                       ymin = p2->ymin;
                       ymax = p2->ymax;
 
                       if (RegionDebug > 3 || (ymax > RegionDebugYMin
                                   && ymin < RegionDebugYMax)) {
                               IfTrace2 (TRUE,". Swath from %d to %d:\n",
                                                              ymin, ymax);
                               for (p=p2; INSWATH(p,ymin,ymax); p = p->link) {
                                       IfTrace4(TRUE,". . at %p[%x] range %d:%d, ",
                                                 p, (LONG) p->flag,
                                                 (LONG) p->xmin, (LONG)p->xmax);
                                       IfTrace1(TRUE, "subpath=%p,\n", p->subpath);
                               }
                       }
                       for (y=TYPE1_MAX(ymin,RegionDebugYMin); y < TYPE1_MIN(ymax, RegionDebugYMax); y++) {
                               IfTrace1(TRUE,". . . Y[%5d] ", (LONG) y);
                               for (p=p2; INSWATH(p,ymin,ymax); p = p->link)
                                       IfTrace1(TRUE,"%5d ",
                                                (LONG) p->xvalues[y - ymin]);
                               IfTrace0(TRUE,"\n");
                       }
                       while (INSWATH(p2, ymin, ymax))
                               p2 = p2->link;
               }
       }
}

Here is the call graph for this function:

static int edgecheck ( ) [static]

Here is the caller graph for this function:

static int edgecheck ( struct edgelist edge,
int  oldmin,
int  oldmax 
) [static]

Definition at line 1768 of file regions.c.

{
       if (edge->type != EDGETYPE)
               abort("EDGE ERROR: non EDGETYPE in list", 42);
/*
The following check is not valid if the region is jumbled so I took it
out:
*/
/*     if (edge->ymin < oldmax && edge->ymin != oldmin)
               abort("EDGE ERROR: overlapping swaths", 43); */
       return(0);
       
}

Here is the call graph for this function:

static int edgemax ( ) [static]

Here is the caller graph for this function:

static int edgemax ( int  h,
pel e1,
pel e2 
) [static]

Definition at line 1349 of file regions.c.

{
       for (; --h >= 0; e1++,e2++)
               if (*e1 < *e2)
                       *e1 = *e2;
       return(0);
       
}
static int edgemin ( ) [static]

Here is the caller graph for this function:

static int edgemin ( int  h,
pel e1,
pel e2 
) [static]

Definition at line 1335 of file regions.c.

{
       for (; --h >= 0; e1++,e2++)
               if (*e1 > *e2)
                       *e1 = *e2;
       return(0);
       
}
struct region* Interior ( struct segment p,
int  fillrule 
) [read]

Definition at line 377 of file regions.c.

{
  register fractpel x,y;  /* keeps ending point of path segment         */
  fractpel lastx,lasty; /* previous x,y from path segment before        */
  register struct region *R;  /* region I will build                    */
  register struct segment *nextP; /* next segment of path */
  char tempflag;        /* flag; is path temporary?                     */
  char Cflag;           /* flag; should we apply continuity?            */
  
  IfTrace2((MustTraceCalls),".  INTERIOR(%p, %d)\n", p, (LONG) fillrule);
  
  if (p == NULL)
    return(NULL);
  /*
    Establish the 'Cflag' continuity flag based on user's fill rule and
    our own 'Continuity' pragmatic (0: never do continuity, 1: do what
    user asked, >1: do it regardless).
  */
  if (fillrule > 0) {
    Cflag = Continuity > 0;
    fillrule -= CONTINUITY;
  }
  else
    Cflag = Continuity > 1;
 
  ARGCHECK((fillrule != WINDINGRULE && fillrule != EVENODDRULE),
          "Interior: bad fill rule", NULL, NULL, (1,p), struct region *);
  
  if (p->type == TEXTTYPE)
    /*             if (fillrule != EVENODDRULE)
                 else */
    return((struct region *)UniquePath(p));
  if (p->type == STROKEPATHTYPE){
    if (fillrule == WINDINGRULE)
      return((struct region *)DoStroke(p));
    else
      p = CoercePath(p);
  }
  
 
  R = (struct region *)Allocate(sizeof(struct region), &EmptyRegion, 0);
  
  ARGCHECK(!ISPATHANCHOR(p), "Interior:  bad path", p, R, (0), struct region *);
  ARGCHECK((p->type != MOVETYPE), "Interior:  path not closed", p, R, (0), struct region *);
  
  
  /* changed definition from !ISPERMANENT to references <= 1 3-26-91 PNM */
  tempflag =  (p->references <= 1); /* only first segment in path is so marked */
  if (!ISPERMANENT(p->flag)) p->references -= 1;
  
  R->newedgefcn = newfilledge;
  /*
    Believe it or not, "R" is now completely initialized.  We are counting
    on the copy of template to get other fields the way we want them,
    namely
    :ol.
    :li.anchor = NULL
    :li.xmin, ymin, xmax, ymax, to minimum and maximum values respectively.
    :eol.
    Anchor = NULL is very
    important to ChangeDirection.
    See :hdref refid=CD..
    
    To minimize problems of "wrapping" in our pel arithmetic, we keep an
    origin of the region which is the first move.  Hopefully, that keeps
    numbers within plus or minus 32K pels.
  */
  R->origin.x = 0/*TOFRACTPEL(NEARESTPEL(p->dest.x))*/;
  R->origin.y = 0/*TOFRACTPEL(NEARESTPEL(p->dest.y))*/;
  lastx = - R->origin.x;
  lasty = - R->origin.y;
  /*
    ChangeDirection initializes other important fields in R, such as
    lastdy, edge, edgeYstop, edgexmin, and edgexmax.  The first segment
    is a MOVETYPE, so it will be called first.
  */
  /*
    Note: Hinting is completely performed in charspace coordinates
          in the Type 1 module. Therefore, I have removed the code
         to handle hint segments. (2002-08-11)
  */
  
  while (p != NULL)  {
 
    x = lastx + p->dest.x;
    y = lasty + p->dest.y;
    
    nextP = p->link;
 
    switch(p->type) {
      
    case LINETYPE:
      StepLine(R, lastx, lasty, x, y);
      break;
      
    case CONICTYPE:
       /* 2nd order Beziers not implemented! */
      break;
      
    case BEZIERTYPE:
      {
       register struct beziersegment *bp = (struct beziersegment *) p;
       
       StepBezier(R, lastx, lasty,
                 lastx + bp->B.x, lasty + bp->B.y,
                 lastx + bp->C.x,
                 lasty + bp->C.y,
                 x, y);
      }
      break;
 
    case MOVETYPE:
      /* At this point we have encountered a MOVE segment.  This breaks the
        path, making it disjoint. */
      if (p->last == NULL) /* i.e., not first in path */
       ChangeDirection(CD_LAST, R, lastx, lasty, (fractpel) 0, (fractpel) 0, (fractpel) 0);
      
      ChangeDirection(CD_FIRST, R, x, y, (fractpel) 0, (fractpel) 0, (fractpel) 0);
      /* We'll just double check for closure here.  We forgive an appended
        MOVETYPE at the end of the path, if it isn't closed: */
      if (!ISCLOSED(p->flag) && p->link != NULL)
       return((struct region *)ArgErr("Fill: sub-path not closed", p, NULL));
      break;
      
    default:
      abort("Interior: path type error", 30);
    }
    /*  We're done with this segment.  Advance to the next path segment in
       the list, freeing this one if necessary: */
    lastx = x;  lasty = y;
    
    if (tempflag)
      Free(p);
    p = nextP;
  }
  ChangeDirection(CD_LAST, R, lastx, lasty, (fractpel) 0, (fractpel) 0, (fractpel) 0);
  R->ending.x = lastx;
  R->ending.y = lasty;


  /*  Finally, clean up the region's based on the user's 'fillrule' request: */
  if (Cflag)
    ApplyContinuity(R);

  if (fillrule == WINDINGRULE)
    Unwind(R->anchor);

  return R;
}

Here is the call graph for this function:

void KillRegion ( struct region area)

Definition at line 233 of file regions.c.

{
        register struct edgelist *p;  /* loop variable                       */
        register struct edgelist *next;  /* loop variable                    */
 
        if (area->references < 0)
               abort("KillRegion:  negative reference count", 28);
        if ( (--(area->references) > 1) ||
           ( (area->references == 1) && !ISPERMANENT(area->flag) ) )
            return;
 
        for (p=area->anchor; p != NULL; p=next) {
               next = p->link;
               Free(p);
        }
       /* KillPicture-macro removed from sources (RMz, 2001-04-01)
        if (area->thresholded != NULL)
                 KillPicture(area->thresholded);
       */
        Free(area);
}

Here is the call graph for this function:

void MoreWorkArea ( struct region R,
fractpel  x1,
fractpel  y1,
fractpel  x2,
fractpel  y2 
)

Definition at line 1543 of file regions.c.

{
       register int idy;     /* integer dy of line                           */
 
       idy = NEARESTPEL(y1) - NEARESTPEL(y2);
       if (idy < 0)  idy = - idy;
 
       /*
       * we must add one to the delta for the number of run ends we
       * need to store:
       */
       if (++idy > currentsize) {
               IfTrace1((RegionDebug > 0),"Allocating edge of %d pels\n", idy);
               if (currentworkarea != workedge)
                       NonObjectFree(currentworkarea);
               currentworkarea = (pel *)Allocate(0, NULL, idy * sizeof(pel));
               currentsize = idy;
       }
       ChangeDirection(CD_CONTINUE, R, x1, y1, y2 - y1, x2, y2);
}
void MoveEdges ( struct region R,
fractpel  dx,
fractpel  dy 
)

Definition at line 1419 of file regions.c.

{
       register struct edgelist *edge;  /* for looping through edges         */
 
       R->origin.x += dx;
       R->origin.y += dy;
       R->ending.x += dx;
       R->ending.y += dy;
       if (R->thresholded != NULL) {
               R->thresholded->origin.x -= dx;
               R->thresholded->origin.y -= dy;
       }
/*
From now on we will deal with dx and dy as integer pel values:
*/
       dx = NEARESTPEL(dx);
       dy = NEARESTPEL(dy);
       if (dx == 0 && dy == 0)
               return;
 
       R->xmin += dx;
       R->xmax += dx;
       R->ymin += dy;
       R->ymax += dy;
 
       for (edge = R->anchor; VALIDEDGE(edge); edge = edge->link) {
               edge->ymin += dy;
               edge->ymax += dy;
               if (dx != 0) {
                       register int h;  /* loop index; height of edge        */
                       register pel *Xp;  /* loop pointer to X values        */
 
                       edge->xmin += dx;
                       edge->xmax += dx;
                       for (Xp = edge->xvalues, h = edge->ymax - edge->ymin;
                                     --h >= 0; )
                               *Xp++ += dx;
               }
       }
}
static struct edgelist* NewEdge ( ) [static, read]

Here is the caller graph for this function:

static struct edgelist* NewEdge ( pel  xmin,
pel  xmax,
pel  ymin,
pel  ymax,
pel xvalues,
int  isdown 
) [static, read]

Definition at line 297 of file regions.c.

{
       static struct edgelist template = {
                 EDGETYPE, 0, 1, NULL, NULL,
                 0, 0, 0, 0, NULL };
 
       register struct edgelist *r;  /* returned structure                   */
       register int iy;      /* ymin adjusted for 'long' alignment purposes  */
 
       IfTrace2((RegionDebug),"....new edge: ymin=%d, ymax=%d ",
                                              (LONG)ymin, (LONG) ymax);
       if (ymin >= ymax)
               abort("newedge: height not positive", 29);
/*
We are going to copy the xvalues into a newly allocated area.  It
helps performance if the values are all "long" aligned.  We can test
if the xvalues are long aligned by ANDing the address with the
(sizeof(long) - 1)--if non zero, the xvalues are not aligned well.  We
set 'iy' to the ymin value that would give us good alignment:
*/
       iy = ymin - (((unsigned long) xvalues) & (sizeof(LONG) - 1)) / sizeof(pel);
 
       r = (struct edgelist *)Allocate(sizeof(struct edgelist), &template,
                             (ymax - iy) * sizeof(pel));
 
       if (isdown) r->flag = ISDOWN(ON);
       r->xmin = xmin;
       r->xmax = xmax;
       r->ymin = ymin;
       r->ymax = ymax;
 
       r->xvalues = (pel *) FOLLOWING(r);
       if (ymin != iy) {
               r->xvalues += ymin - iy;
               xvalues -= ymin - iy;
       }
 
/*
We must round up (ymax - iy) so we get the ceiling of the number of
longs.  The destination must be able to hold these extra bytes because
Allocate() makes everything it allocates be in multiples of longs.
*/
       LONGCOPY(&r[1], xvalues, (ymax - iy) * sizeof(pel) + sizeof(LONG) - 1);
 
       IfTrace1((RegionDebug),"result=%p\n", r);
       return(r);
}

Here is the call graph for this function:

static int newfilledge ( ) [static]

Here is the caller graph for this function:

static int newfilledge ( struct region R,
fractpel  xmin,
fractpel  xmax,
fractpel  ymin,
fractpel  ymax,
int  isdown,
fractpel  x1,
fractpel  y1,
fractpel  x2,
fractpel  y2 
) [static]

Definition at line 689 of file regions.c.

{
  
  register pel pelxmin,pelymin,pelxmax,pelymax;  /* pel versions of bounds */
  register struct edgelist *edge;  /* newly created edge                */
  
  pelymin = NEARESTPEL(ymin);
  pelymax = NEARESTPEL(ymax);
  if (pelymin == pelymax)
    return(0);
  
  pelxmin = NEARESTPEL(xmin);
  pelxmax = NEARESTPEL(xmax);
  
  if (pelxmin < R->xmin)  R->xmin = pelxmin;
  if (pelxmax > R->xmax)  R->xmax = pelxmax;
  if (pelymin < R->ymin)  R->ymin = pelymin;
  if (pelymax > R->ymax)  R->ymax = pelymax;
  
  edge = NewEdge(pelxmin, pelxmax, pelymin, pelymax, &R->edge[pelymin], isdown);

  /* Save maximum and minimum values of edge in order to be able to
     use them in ApplyContinity. */
  edge->fpx1 = x1;
  edge->fpy1 = y1;
  edge->fpx2 = x2;
  edge->fpy2 = y2;
  
  edge->subpath = R->lastedge;
  R->lastedge = edge;
  if (R->firstedge == NULL)
    R->firstedge = edge;
   
  R->anchor = SortSwath(R->anchor, edge, swathxsort);

  /*
  { 
    struct region*   r  = (struct region*) R;
    struct edgelist* el = (struct edgelist*) (r->anchor);
    
    while ( el != 0 )
      {
       long i = 0;
       short int* spl;
       short int* spr;
       int xl;
       int xr;
       
       printf( "Region after Sort (NE=%ld) : ymin=%d, ymax=%d, xmin=%d, xmax=%d\n",
              callcount, el->ymin, el->ymax, el->xmin, el->xmax);
       for ( i=0; i<((el->ymax)-(el->ymin)); i++ ) {
         spl = el->xvalues;
         if ( el->link != NULL ) {
           spr = el->link->xvalues;
           xl = spl[i];
           xr = spr[i];
           printf( "Region after Sort (NE=%ld): y=%ld              xleft=%d, xright=%d\n",
                  callcount, el->ymin + i, xl, xr);
         }
         else {
           printf( "Region after Sort (NE=%ld): y=%ld              xval=%d\n",
                  callcount, el->ymin + i, spl[i]);
         }
       }
       if ( el->link != 0 )
         el = el->link->link;
       else
         break;
      }
  }

  ++callcount;
  */
  
  return 0;
}

Here is the call graph for this function:

struct segment* RegionBounds ( struct region R) [read]

Definition at line 1671 of file regions.c.

{
 
       register struct segment *path;  /* returned path                      */
 
       path = BoxPath(IDENTITY, R->ymax - R->ymin, R->xmax - R->xmin);
       path = Join(PathSegment(MOVETYPE, R->origin.x + TOFRACTPEL(R->xmin),
                                         R->origin.y + TOFRACTPEL(R->ymin) ),
                   path);
       return(path);
}
struct edgelist* SortSwath ( struct edgelist anchor,
struct edgelist edge,
struct edgelist *(*)()  swathfcn 
) [read]

Definition at line 798 of file regions.c.

{
  register struct edgelist *before,*after;
  struct edgelist base;
  
  if (RegionDebug > 0) {
    if (RegionDebug > 2)  {
      IfTrace3(TRUE,"SortSwath(anchor=%p, edge=%p, fcn=%p)\n",
              anchor, edge, swathfcn);
    }
    else  {
      IfTrace3(TRUE,"SortSwath(anchor=%p, edge=%p, fcn=%p)\n",
              anchor, edge, swathfcn);
    }
  }
  if (anchor == NULL)
    return(edge);
  
  before = &base;
  before->ymin = before->ymax = MINPEL;
  before->link = after = anchor;
  
  /*
    If the incoming edge is above the current list, we connect the current
    list to the bottom of the incoming edge.  One slight complication is
    if the incoming edge overlaps into the current list.  Then, we
    first split the incoming edge in two at the point of overlap and recursively
    call ourselves to sort the bottom of the split into the current list:
  */
  if (TOP(edge) < TOP(after)) {
    if (BOTTOM(edge) > TOP(after)) {
      after = SortSwath(after, splitedge(edge, TOP(after)), swathfcn);
    }
    vertjoin(edge, after);
    return(edge);
  }
  
  /*
    At this point the top of edge is not higher than the top of the list,
    which we keep in 'after'.  We move the 'after' point down the list,
    until the top of the edge occurs in the swath beginning with 'after'.
    
    If the bottom of 'after' is below the bottom of the edge, we have to
    split the 'after' swath into two parts, at the bottom of the edge.
    If the bottom of 'after' is above the bottom of the swath,
  */
 
  while (VALIDEDGE(after)) {
    
    if (TOP(after) == TOP(edge)) {
      if (BOTTOM(after) > BOTTOM(edge))
       vertjoin(after, splitedge(after, BOTTOM(edge)));
      else if (BOTTOM(after) < BOTTOM(edge)) {
       after = SortSwath(after,
                       splitedge(edge, BOTTOM(after)), swathfcn);
      }
      break;
    }
    else if (TOP(after) > TOP(edge)) {
      IfTrace0((BOTTOM(edge) < TOP(after) && RegionDebug > 0),
              "SortSwath:  disjoint edges\n");
      if (BOTTOM(edge) > TOP(after)) {
       after = SortSwath(after,
                       splitedge(edge, TOP(after)), swathfcn);
      }
      break;
    }
    else if (BOTTOM(after) > TOP(edge))
      vertjoin(after, splitedge(after, TOP(edge)));
    
    before = after;
    after = after->link;
  }
  
  /*
    At this point 'edge' exactly corresponds in height to the current
    swath pointed to by 'after'.
  */
  if (after != NULL && TOP(after) == TOP(edge)) {
    before = (*swathfcn)(before, edge);
    after = before->link;
  }
  /*
    At this point 'after' contains all the edges after 'edge', and 'before'
    contains all the edges before.  Whew!  A simple matter now of adding
    'edge' to the linked list in its rightful place:
  */
  before->link = edge;
  if (RegionDebug > 1) {
    IfTrace3(TRUE,"SortSwath:  in between %p and %p are %p",
            before, after, edge);
    while (edge->link != NULL) {
      edge = edge->link;
      IfTrace1(TRUE," and %p", edge);
    }
    IfTrace0(TRUE,"\n");
  }
  else
    for (; edge->link != NULL; edge = edge->link) { ; }
  
  edge->link = after;

  return base.link;
  
}

Here is the call graph for this function:

static struct edgelist* splitedge ( ) [static, read]

Here is the caller graph for this function:

static struct edgelist* splitedge ( struct edgelist list,
pel  y 
) [static, read]

Definition at line 915 of file regions.c.

{
  register struct edgelist *new;  /* anchor for newly built list        */
  register struct edgelist *last=NULL;  /* end of newly built list           */
  register struct edgelist *r;  /* temp pointer to new structure        */
  register struct edgelist *lastlist;  /* temp pointer to last 'list' value */
  
  IfTrace2((RegionDebug > 1),"splitedge of %p at %d ", list, (LONG) y);
  
  lastlist = new = NULL;
  
  while (list != NULL) {
    if (y < list->ymin)
      break;
    
    if (y >= list->ymax)
      abort("splitedge: above top of list", 33);
    if (y == list->ymin)
      abort("splitedge: would be null", 34);
    
    r = (struct edgelist *)Allocate(sizeof(struct edgelist), list, 0);
    /*
      At this point 'r' points to a copy of the single structure at 'list'.
      We will make 'r' be the new split 'edgelist'--the lower half.
      We don't bother to correct 'xmin' and 'xmax', we'll take the
      the pessimistic answer that results from using the old values.
    */
    r->ymin = y;
    r->xvalues = list->xvalues + (y - list->ymin);
    
    /*
      Update the fpx values so that ApplyContinuity() will continue
      to work. Note that high precision is a fake, here!
    */
    r->fpx1 = (r->xvalues[0]) << FRACTBITS;
    r->fpx2 = (list->xvalues[list->ymax - list->ymin - 1]) << FRACTBITS;
    list->fpx2 = (list->xvalues[y - list->ymin -1]) << FRACTBITS;
    
    /*
      Note that we do not need to allocate new memory for the X values,
      they can remain with the old "edgelist" structure.  We do have to
      update that old structure so it is not as high:
    */
    list->ymax = y;
    
    /*
      Insert 'r' in the subpath chain:
    */
    r->subpath = list->subpath;
    list->subpath = r;
    /*
      Now attach 'r' to the list we are building at 'new', and advance
      'list' to point to the next element in the old list:
    */
    if (new == NULL) {
      new = r;
    }
    else
      last->link = r;
    last = r;
    lastlist = list;
    list = list->link;
  }
  /*
    At this point we have a new list built at 'new'.  We break the old
    list at 'lastlist', and add the broken off part to the end of 'new'.
    Then, we return the caller a pointer to 'new':
  */
  if (new == NULL)
    abort("null splitedge", 35);
  lastlist->link = NULL;
  last->link = list;
  IfTrace1((RegionDebug > 1),"yields %p\n", new);
  return(new);
}

Here is the call graph for this function:

struct edgelist* swathrightmost ( struct edgelist before,
struct edgelist edge 
) [read]

Definition at line 1254 of file regions.c.

{
       register struct edgelist *after;
 
       after = before->link;
 
       while (after != NULL && TOP(after) == TOP(edge)) {
               before = after;
               after = after->link;
       }
 
       return(before);
 
}
struct edgelist* SwathUnion ( struct edgelist before0,
struct edgelist edge 
) [read]

Definition at line 1097 of file regions.c.

{
       register int h;       /* saves height of edge                         */
       register struct edgelist *rightedge;  /* saves right edge of 'edge'   */
       register struct edgelist *before,*after;  /* edge before and after    */
       int h0;               /* saves initial height                         */
 
       IfTrace2((RegionDebug > 1),"SwathUnion entered, before=%p, edge=%p\n",
                      before0, edge);
 
       h0 = h = edge->ymax - edge->ymin;
       if (h <= 0)
               abort("SwathUnion:  0 height swath?", 37);
 
       before = before0;
       after = before->link;
 
       while (after != NULL && TOP(after) == TOP(edge)) {
               register struct edgelist *right;
 
               right = after->link;
               if (right->xvalues[0] >= edge->xvalues[0])
                       break;
               before = right;
               after = before->link;
       }
/*
This is the picture at this point.  'L' indicates a left hand edge,
'R' indicates the right hand edge.
'<--->' indicates the degree of uncertainty as to its placement
relative to other edges:
:xmp atomic.
   before           after
     R            <---L---->  R             L   R    L   R
              <---L--->  <------R-------------------------->
                 edge
:exmp.
In case the left of 'edge' touches 'before', we need to reduce
the height by that amount.
*/
       if (TOP(before) == TOP(edge))
               h -= touches(h, before->xvalues, edge->xvalues);
 
       rightedge = edge->link;
 
       if (after == NULL || TOP(after) != TOP(edge) ||
                   after->xvalues[0] > rightedge->xvalues[0]) {
              IfTrace2((RegionDebug > 1),
                       "SwathUnion starts disjoint: before=%p after=%p\n",
                                     before, after);
/*
On this side of the the above 'if', the new edge is disjoint from the
existing edges in the swath.  This is the picture:
:xmp atomic.
   before           after
     R                L    R     L   R    L   R
              L    R
             edge
:exmp.
We will verify it remains disjoint for the entire height.  If the
situation changes somewhere down the edge, we split the edge at that
point and recursively call ourselves (through 'SortSwath') to figure
out the new situation:
*/
               if (after != NULL && TOP(after) == TOP(edge))
                       h -= touches(h, rightedge->xvalues, after->xvalues);
               if (h < h0)
                       SortSwath(before0->link, splitedge(edge, edge->ymin + h), t1_SwathUnion);
               /* go to "return" this edge pair; it is totally disjoint */
       }
       else {
/*
At this point, at the 'else', we know that the
new edge overlaps one or more pairs in the existing swath.  Here is
a picture of our knowledge and uncertainties:
:xmp atomic.
   before       after
     R            L        R     L   R    L   R
            <---L--->   <---R------------------->
               edge
:exmp.
We need to move 'after' along until it is to the right of the
right of 'edge'.  ('After' should always point to a left edge of a pair:)
*/
               register struct edgelist *left;  /* variable to keep left edge in */
 
               do {
                        left = after;
                        after = (after->link)->link;
 
               } while  (after != NULL && TOP(after) == TOP(edge)
                               && after->xvalues[0] <= rightedge->xvalues[0]);
/*
At this point this is the picture:
:xmp atomic.
   before                 left        after
     R            L    R   L      R     L   R
            <---L--->        <---R--->
               edge
:exmp.
We need to verify that the situation stays like this all the way
down the edge.  Again, if the
situation changes somewhere down the edge, we split the edge at that
point and recursively call ourselves (through 'SortSwath') to figure
out the new situation:
*/
 
               h -= crosses(h, left->xvalues, rightedge->xvalues);
               h -= crosses(h, edge->xvalues, ((before->link)->link)->xvalues);
 
               if (after != NULL && TOP(after) == TOP(edge))
 
                       h -= touches(h, rightedge->xvalues, after->xvalues);
 
               IfTrace3((RegionDebug > 1),
                      "SwathUnion is overlapped until %d: before=%p after=%p\n",
                                          (LONG) TOP(edge) + h, before, after);
/*
OK, if we touched either of our neighbors we need to split at that point
and recursively sort the split edge onto the list.  One tricky part
is that when we recursively sort, 'after' will change if it was not
in our current swath:
*/
               if (h < h0) {
                       SortSwath(before0->link,
                                 splitedge(edge, edge->ymin + h),
                                 t1_SwathUnion);
 
                       if (after == NULL || TOP(after) != TOP(edge))
                                 for (after = before0->link;
                                      TOP(after) == TOP(edge);
                                      after = after->link) { ; }
               }
/*
Now we need to augment 'edge' by the left and right of the overlapped
swath, and to discard all edges between before and after, because they
were overlapped and have been combined with the new incoming 'edge':
*/
               edge->xmin = TYPE1_MIN(edge->xmin, (before->link)->xmin);
               edge->xmax = TYPE1_MIN(edge->xmax, (before->link)->xmax);
               edgemin(h, edge->xvalues, (before->link)->xvalues);
               rightedge->xmin = TYPE1_MAX(rightedge->xmin, (left->link)->xmin);
               rightedge->xmax = TYPE1_MAX(rightedge->xmax, (left->link)->xmax);
               edgemax(h, rightedge->xvalues, (left->link)->xvalues);
               discard(before, after);
       }
       return(before);
}

Here is the call graph for this function:

struct edgelist* swathxsort ( ) [read]

Here is the caller graph for this function:

struct edgelist* swathxsort ( struct edgelist before0,
struct edgelist edge 
) [read]

Definition at line 1021 of file regions.c.

{
       register struct edgelist *before;
       register struct edgelist *after;
       register pel y=0;
 
       before = before0;
       after = before->link;
 
       while (after != NULL && TOP(after) == TOP(edge)) {
 
               register pel *x1,*x2;
 
               y = TOP(edge);
               x1 = after->xvalues;
               x2 = edge->xvalues;
 
               while (y < BOTTOM(edge) && *x1 == *x2) {
                       x1++; x2++; y++;
               }
               if (y >= BOTTOM(edge)) {
                       edge->flag |= ISAMBIGUOUS(ON);
                       after->flag |= ISAMBIGUOUS(ON);
                       break;
               }
 
               if (*x1 >= *x2)
                       break;
 
               before = after;
               after = after->link;
       }
 
/*
At this point, 'edge' is between 'before' and 'after'.  If 'edge' didn't
cross either of those other edges, we would be done.  We check for
crossing.  If it does cross, we split the problem up by calling SortSwath
recursively with the part of the edge that is below the crossing point:
*/
{
       register int h0,h;    /* height of edge--number of scans              */
 
       h0 = h = BOTTOM(edge) - y;
       y -= TOP(edge);
 
       if (h0 <= 0) {
               IfTrace0((RegionDebug>0),"swathxsort: exactly equal edges\n");
               return(before);
       }
 
       if (TOP(before) == TOP(edge))
               h -= crosses(h, &before->xvalues[y], &edge->xvalues[y]);
       if (after != NULL && TOP(after) == TOP(edge))
               h -= crosses(h, &edge->xvalues[y], &after->xvalues[y]);
 
       if (h < h0) {
               SortSwath(before0->link,
                         splitedge(edge, TOP(edge) + y + h),
                         swathxsort);
 
       }
}
 
       return(before);
}
static int touches ( ) [static]

Here is the caller graph for this function:

static int touches ( int  h,
pel left,
pel right 
) [static]

Definition at line 1277 of file regions.c.

{
       for (; h > 0; h--)
               if (*left++ >= *right++)
                       break;
       return(h);
}
void UnJumble ( struct region region)

Definition at line 1468 of file regions.c.

{
       register struct edgelist *anchor;  /* new lists built here            */
       register struct edgelist *edge;  /* edge pointer for loop             */
       register struct edgelist *next;  /* ditto                             */
 
       anchor = NULL;
 
       for (edge=region->anchor; VALIDEDGE(edge); edge=next) {
               if (edge->link == NULL)
                       abort("UnJumble:  unpaired edge?", 39);
               next = edge->link->link;
               edge->link->link = NULL;
               anchor = SortSwath(anchor, edge, t1_SwathUnion);
       }
 
       if (edge != NULL)
               vertjoin(anchor, edge);
 
       region->anchor = anchor;
       region->flag &= ~ISJUMBLED(ON);
}

Here is the call graph for this function:

static int Unwind ( ) [static]

Here is the caller graph for this function:

static int Unwind ( struct edgelist area) [static]

Definition at line 539 of file regions.c.

{
       register struct edgelist *last=NULL,*next;  /* struct before and after current one */
       register int y;       /* ymin of current swath                        */
       register int count,newcount;  /* winding count registers              */
 
       IfTrace1((RegionDebug>0),"...Unwind(%p)\n", area);
 
       while (VALIDEDGE(area)) {
 
               count = 0;
               y = area->ymin;
 
               do {
                       next = area->link;
 
                       if (ISDOWN(area->flag))
                               newcount = count + 1;
                       else
                               newcount = count - 1;
 
                       if (count == 0 || newcount == 0)
                               last = area;
                       else
                               discard(last, next);
 
                       count = newcount;
                       area = next;
 
               } while (area != NULL && area->ymin == y);
 
               if (count != 0)
                       abort("Unwind:  uneven edges", 31);
       }
       /* We retunr a value for ANSI-C-compiler */
       return(0);
       
}

Here is the call graph for this function:

static int vertjoin ( ) [static]

Here is the caller graph for this function:

static int vertjoin ( struct edgelist top,
struct edgelist bottom 
) [static]

Definition at line 998 of file regions.c.

{
       if (BOTTOM(top) > TOP(bottom))
               abort("vertjoin not disjoint", 36);
 
       for (; top->link != NULL; top=top->link) { ; }
 
       top->link = bottom;
       return(0);
}

Here is the call graph for this function:


Variable Documentation

pel currentsize = MAXEDGE [static]

Definition at line 591 of file regions.c.

Definition at line 590 of file regions.c.

struct XYspace* IDENTITY

Definition at line 178 of file spaces.c.

struct region [static]
Initial value:
 { REGIONTYPE,
                           ISCOMPLEMENT(ON)+ISINFINITE(ON)+ISPERMANENT(ON)+ISIMMORTAL(ON), 2,
                           {0, 0}, {0, 0},
                           0, 0, 0, 0,
                           NULL, NULL,
                           0, 0, 0, 0, 0, NULL, NULL,
                           NULL, 0, NULL, NULL }

Definition at line 144 of file regions.c.

Definition at line 1706 of file regions.c.

Definition at line 1705 of file regions.c.

struct region* T1_INFINITY = &infinity

Definition at line 152 of file regions.c.

pel workedge[MAXEDGE] [static]

Definition at line 589 of file regions.c.