Back to index

radiance  4R0+20100331
Defines | Functions | Variables
plotin.c File Reference
#include <string.h>
#include "meta.h"
#include "plot.h"

Go to the source code of this file.

Defines

#define getsi(f, m)   ICONV(geti(f)-(m), size)

Functions

static void convert (FILE *infp)
static int geti (FILE *fp)
static int quadr (int x, int y, int xp, int yp)
static void step (int d)
static void linemod (char s[])
static void erase (void)
static void space (int xmn, int ymn, int xmx, int ymx)
static void move (int x, int y)
static void cont (int x, int y)
static void line (int x0, int y0, int x1, int y1)
static void label (register char *s)
static void point (int x, int y)
static void arc (int x, int y, int x0, int y0, int x1, int y1)
static void circle (int x, int y, int r)
int main (int argc, char **argv)
int geti (register FILE *fp)
void move (register int x, register int y)
void cont (register int x, register int y)
void point (register int x, register int y)

Variables

static const char RCSid [] = "$Id: plotin.c,v 1.2 2003/11/15 02:13:37 schorsch Exp $"
char * progname
static int xmin = 0
static int ymin = 0
static int size = XYSIZE
static int curx = -1
static int cury = -1
static short curmod = 0
static int del = 100

Define Documentation

#define getsi (   f,
 
)    ICONV(geti(f)-(m), size)

Definition at line 17 of file plotin.c.


Function Documentation

void arc ( int  x,
int  y,
int  x0,
int  y0,
int  x1,
int  y1 
) [static]

Definition at line 254 of file plotin.c.

{
       double pc;
       double sqrt();
       int flg,m,xc,yc,xs,ys,qs,qf;
       float dx,dy,r;
       char use;
       dx = x-x0;
       dy = y-y0;
       r = dx*dx+dy*dy;
       pc = r;
       pc = sqrt(pc);
       flg = pc/4;
       if(flg == 0)step(1);
       else if(flg < del)step(flg);
       xc = xs = x0;
       yc = ys = y0;
       move(xs,ys);
       if(x0 == x1 && y0 == y1)flg=0;
       else flg=1;
       qs = quadr(x,y,x0,y0);
       qf = quadr(x,y,x1,y1);
       if(abs(x-x1) < abs(y-y1)){
              use = 'x';
              if(qs == 2 || qs ==3)m = -1;
              else m=1;
       }
       else {
              use = 'y';
              if(qs > 2)m= -1;
              else m= 1;
       }
       while(1){
              switch(use){
              case 'x':     
                     if(qs == 2 || qs == 3)yc -= del;
                     else yc += del;
                     dy = yc-y;
                     pc = r-dy*dy;
                     xc = m*sqrt(pc)+x;
                     if((x < xs && x >= xc) || ( x > xs && x <= xc) ||
                         (y < ys && y >= yc) || ( y > ys && y <=  yc) )
                     {
                            if(++qs > 4)qs=1;
                            if(qs == 2 || qs == 3)m= -1;
                            else m=1;
                            flg=1;
                     }
                     cont(xc,yc);
                     xs = xc; 
                     ys = yc;
                     if(qs == qf && flg == 1)
                            switch(qf){
                            case 3:
                            case 4:       
                                   if(xs >= x1)return;
                                   continue;
                            case 1:
                            case 2:
                                   if(xs <= x1)return;
                            }
                     continue;
              case 'y':     
                     if(qs > 2)xc += del;
                     else xc -= del;
                     dx = xc-x;
                     pc = r-dx*dx;
                     yc = m*sqrt(pc)+y;
                     if((x < xs && x >= xc) || ( x > xs && x <= xc ) ||
                         (y < ys && y >= yc) || (y > ys && y <= yc) )
                     {
                            if(++qs > 4)qs=1;
                            if(qs > 2)m = -1;
                            else m = 1;
                            flg=1;
                     }
                     cont(xc,yc);
                     xs = xc; 
                     ys = yc;
                     if(qs == qf && flg == 1)
                            switch(qs){
                            case 1:
                            case 4:
                                   if(ys >= y1)return;
                                   continue;
                            case 2:
                            case 3:
                                   if(ys <= y1)return;
                            }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void circle ( int  x,
int  y,
int  r 
) [static]

Definition at line 374 of file plotin.c.

{
       arc(x,y,x+r,y,x+r,y);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void cont ( int  x,
int  y 
) [static]

Here is the caller graph for this function:

void cont ( register int  x,
register int  y 
)

Definition at line 196 of file plotin.c.

{
    plseg(curmod, curx, cury, x, y);
    curx = x;
    cury = y;
}

Here is the call graph for this function:

void convert ( FILE *  infp) [static]

Definition at line 89 of file plotin.c.

{
    char  *fgets(), sbuf[BUFSIZ];
    int  command;
    int  a1, a2, a3, a4, a5, a6;

    while ((command = getc(infp)) != EOF)
       switch (command) {
           case 'm':
              a1 = getsi(infp, xmin);
              a2 = getsi(infp, ymin);
              move(a1, a2);
              break;
           case 'n':
              a1 = getsi(infp, xmin);
              a2 = getsi(infp, ymin);
              cont(a1, a2);
              break;
           case 'p':
              a1 = getsi(infp, xmin);
              a2 = getsi(infp, ymin);
              point(a1, a2);
              break;
           case 'l':
              a1 = getsi(infp, xmin);
              a2 = getsi(infp, ymin);
              a3 = getsi(infp, xmin);
              a4 = getsi(infp, ymin);
              line(a1, a2, a3, a4);
              break;
           case 't':
              fgets(sbuf, sizeof(sbuf), infp);
              sbuf[strlen(sbuf)-1] = '\0';
              label(sbuf);
              break;
           case 'a':
              a1 = getsi(infp, xmin);
              a2 = getsi(infp, ymin);
              a3 = getsi(infp, xmin);
              a4 = getsi(infp, ymin);
              a5 = getsi(infp, xmin);
              a6 = getsi(infp, ymin);
              arc(a1, a2, a3, a4, a5, a6);
              break;
           case 'c':
              a1 = getsi(infp, xmin);
              a2 = getsi(infp, ymin);
              a3 = getsi(infp, 0);
              circle(a1, a2, a3);
              break;
           case 'e':
              erase();
              break;
           case 'f':
              fgets(sbuf, sizeof(sbuf), infp);
              linemod(sbuf);
              break;
           case 's':
              a1 = geti(infp);
              a2 = geti(infp);
              a3 = geti(infp);
              a4 = geti(infp);
              space(a1, a2, a3, a4);
              break;
           default:
              error(USER, "unknown command in convert");
              break;
       }
}

Here is the call graph for this function:

void erase ( void  ) [static]

Definition at line 386 of file plotin.c.

{
    pglob(PEOP, 0200, NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int geti ( FILE *  fp) [static]

Here is the caller graph for this function:

int geti ( register FILE *  fp)

Definition at line 165 of file plotin.c.

{
    register int  i;

    i = getc(fp);
    i |= getc(fp) << 8;
    if (i & 0100000)
       i |= ~0177777;              /* manual sign extend */
    if (feof(fp))
       error(USER, "unexpected end of file in geti");
    
    return(i);
}

Here is the call graph for this function:

void label ( register char *  s) [static]

Definition at line 234 of file plotin.c.

{
    pprim(PMSTR, 0, curx, cury, curx, cury, s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void line ( int  x0,
int  y0,
int  x1,
int  y1 
) [static]

Definition at line 221 of file plotin.c.

{
    move(x0, y0);
    cont(x1, y1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void linemod ( char  s[]) [static]

Definition at line 393 of file plotin.c.

{
    switch (s[2]) {
       case 'l':            /* solid */
           curmod = 0;
           break;
       case 't':            /* dotted */
           curmod = 1;
           break;
       case 'n':            /* long dashed */
           curmod = 2;
           break;
       case 'o':            /* short dashed (dot dashed) */
           curmod = 3;
           break;
       default:
           error(WARNING, "unknown line mode in linemod");
           break;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 49 of file plotin.c.

{
 FILE  *fp;

 progname = *argv++;
 argc--;

 while (argc && **argv == '-')  {
    switch (*(*argv+1))  {
       default:
         error(WARNING, "unknown option");
         break;
       }
    argv++;
    argc--;
    }

 if (argc)
    while (argc)  {
         fp = efopen(*argv, "r");
         convert(fp);
         fclose(fp);
         argv++;
         argc--;
         }
 else
    convert(stdin);

 pglob(PEOF, 0200, NULL);

 return(0);
}

Here is the call graph for this function:

static void move ( int  x,
int  y 
) [static]

Here is the caller graph for this function:

void move ( register int  x,
register int  y 
)

Definition at line 184 of file plotin.c.

{
    curx = x;
    cury = y;
}
static void point ( int  x,
int  y 
) [static]

Here is the caller graph for this function:

void point ( register int  x,
register int  y 
)

Definition at line 208 of file plotin.c.

{
    plseg(0, x, y, x, y);
    curx = x;
    cury = y;
}

Here is the call graph for this function:

int quadr ( int  x,
int  y,
int  xp,
int  yp 
) [static]

Definition at line 355 of file plotin.c.

{
       if(x < xp)
              if(y <= yp)return(1);
              else return(4);
       else if(x > xp)
              if(y < yp)return(2);
              else return(3);
       else if(y < yp)return(2);
       else return(4);
}

Here is the caller graph for this function:

void space ( int  xmn,
int  ymn,
int  xmx,
int  ymx 
) [static]

Definition at line 418 of file plotin.c.

{
    if (xmn >= xmx || ymn >= ymx)
       error(USER, "illegal space specification in space");
    
    xmin = xmn;
    ymin = ymn;
    size = min(xmx-xmn, ymx-ymn);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void step ( int  d) [static]

Definition at line 246 of file plotin.c.

{
       del = d;
}

Here is the caller graph for this function:


Variable Documentation

short curmod = 0 [static]

Definition at line 29 of file plotin.c.

int curx = -1 [static]

Definition at line 26 of file plotin.c.

int cury = -1 [static]

Definition at line 27 of file plotin.c.

int del = 100 [static]

Definition at line 243 of file plotin.c.

char* progname

Definition at line 21 of file plotin.c.

const char RCSid[] = "$Id: plotin.c,v 1.2 2003/11/15 02:13:37 schorsch Exp $" [static]

Definition at line 2 of file plotin.c.

int size = XYSIZE [static]

Definition at line 24 of file plotin.c.

int xmin = 0 [static]

Definition at line 23 of file plotin.c.

int ymin = 0 [static]

Definition at line 23 of file plotin.c.