GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
bres_line.c
Go to the documentation of this file.
1 /*
2  * \file bres_line.c
3  *
4  * \brief GIS Library - Bresenham line routines.
5  *
6  * (C) 2001-2008 by the GRASS Development Team
7  *
8  * This program is free software under the GNU General Public License
9  * (>=v2). Read the file COPYING that comes with GRASS for details.
10  *
11  * \author GRASS GIS Development Team
12  *
13  * \date 1999-2008
14  */
15 
16 #include <grass/gis.h>
17 
18 
38 int G_bresenham_line(int x0, int y0, int x1, int y1, int (*point) (int, int))
39 {
40  int dx, dy;
41  int xinc, yinc;
42 
43  register int res1;
44  int res2;
45 
46  xinc = 1;
47  yinc = 1;
48  if ((dx = x1 - x0) < 0) {
49  xinc = -1;
50  dx = -dx;
51  }
52 
53  if ((dy = y1 - y0) < 0) {
54  yinc = -1;
55  dy = -dy;
56  }
57  res1 = 0;
58  res2 = 0;
59 
60  if (dx > dy) {
61  while (x0 != x1) {
62  point(x0, y0);
63  if (res1 > res2) {
64  res2 += dx - res1;
65  res1 = 0;
66  y0 += yinc;
67  }
68  res1 += dy;
69  x0 += xinc;
70  }
71  }
72  else if (dx < dy) {
73  while (y0 != y1) {
74  point(x0, y0);
75  if (res1 > res2) {
76  res2 += dy - res1;
77  res1 = 0;
78  x0 += xinc;
79  }
80  res1 += dx;
81  y0 += yinc;
82  }
83  }
84  else {
85  while (x0 != x1) {
86  point(x0, y0);
87  y0 += yinc;
88  x0 += xinc;
89  }
90  }
91 
92  point(x1, y1);
93 
94  return 0;
95 }
struct triple * point
Definition: dataquad.c:294
int G_bresenham_line(int x0, int y0, int x1, int y1, int(*point)(int, int))
Bresenham line algorithm.
Definition: bres_line.c:38