Back to index

tetex-bin  3.0
Defines | Functions
lines.c File Reference
#include <stdio.h>
#include "types.h"
#include "objects.h"
#include "spaces.h"
#include "regions.h"
#include "lines.h"

Go to the source code of this file.

Defines

#define PREC   8 /* we'll keep fraction pels in 8 bit precision */
#define RoundFP(xy, b)   (((xy)+(1<<((b)-1)))>>(b))
#define TruncFP(xy, b)   ((xy)>>(b))
#define P   PREC
#define P   PREC

Functions

void StepLine (struct region *R, fractpel x1, fractpel y1, fractpel x2, fractpel y2)
void Bresenham (pel *edgeP, fractpel x1, fractpel y1, fractpel x2, fractpel y2)

Define Documentation

#define P   PREC
#define P   PREC
#define PREC   8 /* we'll keep fraction pels in 8 bit precision */

Definition at line 115 of file lines.c.

#define RoundFP (   xy,
  b 
)    (((xy)+(1<<((b)-1)))>>(b))

Definition at line 119 of file lines.c.

#define TruncFP (   xy,
  b 
)    ((xy)>>(b))

Definition at line 124 of file lines.c.


Function Documentation

void Bresenham ( pel edgeP,
fractpel  x1,
fractpel  y1,
fractpel  x2,
fractpel  y2 
)

Definition at line 127 of file lines.c.

{
       register LONG dx,dy;  /* change in x and y, in my own precision       */
       register LONG x,y;    /* integer pel starting point                   */
       register int count;   /* integer pel delta y                          */
       register LONG d;      /* the Bresenham algorithm error term           */
 
       x1 = TruncFP(x1, FRACTBITS-PREC);
       y1 = TruncFP(y1, FRACTBITS-PREC);
       x2 = TruncFP(x2, FRACTBITS-PREC);
       y2 = TruncFP(y2, FRACTBITS-PREC);
 
       dx = x2 - x1;
       dy = y2 - y1;
/*
Find the starting x and y integer pel coordinates:
*/
 
 x = RoundFP(x1,PREC);
 y = RoundFP(y1,PREC);

 edgeP += y;
 count = RoundFP(y2,PREC) - y;
/*------------------------------------------------------------------*/
/* Force dx to be positive so that dfy will be negative             */
/*       this means that vertical moves will decrease d             */
/*------------------------------------------------------------------*/
 if (dx<0)
 {
  dx = -dx;
#define P PREC
  d=(dy*(x1-(x<<P)+(1<<(P-1)))-dx*((y<<P)-y1+(1<<(P-1))))>>P;
#undef P
  while(--count >= 0 )
  {
   while(d<0)
   {
    --x;
    d += dy;
   }
   *(edgeP++) = x;
   d -= dx;
  }
 }
 else  /* positive dx */
 {
   
   if ( dx == 0 ) {
     while(--count >= 0 ) {
       *(edgeP++) = x;
     }
     return;
     
   }
   
#define P PREC
  d = (dy*((x<<P)-x1+(1<<(P-1)))-dx*((y<<P)-y1+(1<<(P-1))))>>P;
#undef P
  while(--count >= 0 )
  {
   while(d<0)
   {
    ++x;
    d += dy;
   }
   *(edgeP++) = x;
   d -= dx;
  }
 }
}
void StepLine ( struct region R,
fractpel  x1,
fractpel  y1,
fractpel  x2,
fractpel  y2 
)

Definition at line 76 of file lines.c.

{
       register fractpel dy;
 
       IfTrace4((LineDebug > 0), ".....StepLine: (%d,%d) to (%d,%d)\n",
                                            x1, y1, x2, y2);
 
       dy = y2 - y1;
 
/*
We execute the "GOING_TO" macro to call back the REGIONS module, if
necessary (like if the Y direction of the edge has changed):
*/
       GOING_TO(R, x1, y1, x2, y2, dy);
 
       if (dy == 0)
               return;
 
       if (dy < 0)
               Bresenham(R->edge, x2, y2, x1, y1);
       else
               Bresenham(R->edge, x1, y1, x2, y2);
       return;
}