00001 #include <grass/gis.h> 00002 00021 int G_bresenham_line ( 00022 register int x0, register int y0 , 00023 int x1,int y1 , 00024 int (*point)()) 00025 { 00026 int dx, dy; 00027 int xinc, yinc; 00028 00029 register int res1; 00030 int res2; 00031 00032 xinc = 1; 00033 yinc = 1; 00034 if ((dx = x1-x0) < 0) 00035 { 00036 xinc = -1; 00037 dx = -dx; 00038 } 00039 if ((dy = y1-y0) < 0) 00040 { 00041 yinc = -1; 00042 dy = -dy; 00043 } 00044 res1 = 0; 00045 res2 = 0; 00046 00047 if (dx > dy) 00048 { 00049 while (x0 != x1) 00050 { 00051 point (x0, y0); 00052 if (res1 > res2) 00053 { 00054 res2 += dx - res1; 00055 res1 = 0; 00056 y0 += yinc; 00057 } 00058 res1 += dy; 00059 x0 += xinc; 00060 } 00061 } 00062 else if (dx < dy) 00063 { 00064 while (y0 != y1) 00065 { 00066 point (x0, y0); 00067 if (res1 > res2) 00068 { 00069 res2 += dy - res1; 00070 res1 = 0; 00071 x0 += xinc; 00072 } 00073 res1 += dx; 00074 y0 += yinc; 00075 } 00076 } 00077 else 00078 { 00079 while (x0 != x1) 00080 { 00081 point (x0, y0); 00082 y0 += yinc; 00083 x0 += xinc; 00084 } 00085 } 00086 00087 point (x1, y1); 00088 00089 return 0; 00090 }