src/shline2s.c

00001 
00006 /*
00007  *  PROGRAM NAME:  sh
00008  *
00009  *  (c) COPYRIGHT INTERNATIONAL BUSINESS MACHINES
00010  *  CORPORATION 12/1/2001.  ALL RIGHTS RESERVED.
00011  *
00012  *  Please refer to the LICENSE file in the top directory
00013  *
00014  *      author: Mike Henderson mhender@watson.ibm.com
00015  */
00016 
00017 static char *id="@(#) $Id: shline2s.c,v 1.2 2006/08/17 19:28:17 mhender Exp $";
00018 
00019 #include <shInternal.h>
00020 #include <math.h>
00021 
00032 void shline2s(int *i0,int *j0,int *i1,int *j1,int *ixoff,int *iyoff)
00033  {
00034   float zz;
00035   float xc,yc;
00036   float dx,dy;
00037   int ipix,jpix;
00038 
00039 /*   draw a line segment */
00040 
00041   if((*i0)==(*i1)&&(*j0)==(*j1))
00042    {
00043     if((*i0)>0&&(*i0)<shIMax&&(*j0)>0&&(*j0)<shJMax)
00044      {
00045       zz=0.;
00046       shsetp(i0,j0,&sh_rl,&sh_gl,&sh_bl,&zz);
00047      }
00048     return;
00049    }
00050 
00051   xc=(*i0);
00052   yc=(*j0);
00053   dx=(*i1)-xc;
00054   dy=(*j1)-yc;
00055   zz=0.;
00056   while(fabs(dx)>.5||fabs(dy)>.5)
00057    {
00058     ipix=xc+.5+(*ixoff);
00059     jpix=yc+.5+(*iyoff);
00060     if(ipix>0&&ipix<shIMax&&jpix>0&&jpix<shJMax)shsetp(&ipix,&jpix,&sh_rl,&sh_gl,&sh_bl,&zz);
00061 
00062     dx=(*i1)-xc;
00063     dy=(*j1)-yc;
00064     if(abs(dx)>.5||abs(dy)>.5)
00065      {
00066       if(abs(dx)>abs(dy))
00067        {
00068         if(dx>0)
00069          {
00070           xc=xc+1;
00071           yc=yc+dy/dx;
00072          }else{
00073           xc=xc-1;
00074           yc=yc-dy/dx;
00075          }
00076        }else{
00077         if(dy>0)
00078          {
00079           yc=yc+1;
00080           xc=xc+dx/dy;
00081          }else{
00082           yc=yc-1;
00083           xc=xc-dx/dy;
00084          }
00085        }
00086      }
00087     dx=(*i1)-xc;
00088     dy=(*j1)-yc;
00089    }
00090 
00091   return;
00092  }

Generated on Thu Aug 17 15:29:43 2006 for sh by  doxygen 1.4.6