Index: raster/r.distance/distance.c
===================================================================
RCS file: /grassrepository/grass6/raster/r.distance/distance.c,v
retrieving revision 2.1
diff -u -r2.1 distance.c
--- raster/r.distance/distance.c	15 Sep 2006 09:44:25 -0000	2.1
+++ raster/r.distance/distance.c	14 Oct 2006 20:44:25 -0000
@@ -24,7 +24,7 @@
 /* this code assumes that list1 and list2 have at least one cell in each */
 
 void 
-find_minimum_distance (struct CatEdgeList *list1, struct CatEdgeList *list2, double *east1, double *north1, double *east2, double *north2, double *distance, struct Cell_head *region)
+find_minimum_distance (struct CatEdgeList *list1, struct CatEdgeList *list2, double *east1, double *north1, double *east2, double *north2, double *distance, struct Cell_head *region, int overlap,  char *name1, char *name2)
 {
     int i1,i2;
     double dist;
@@ -32,7 +32,13 @@
     extern double G_distance();
     extern double G_row_to_northing();
     extern double G_col_to_easting();
+    int zerro_row, zerro_col;
 
+    int nulldistance = 0;
+
+
+    if (overlap) 
+        nulldistance = null_distance(name1, name2, &zerro_row, &zerro_col);
 
     for (i1 = 0 ; i1 < list1->ncells; i1++)
     {
@@ -41,9 +47,16 @@
 
 	for (i2 = 0 ; i2 < list2->ncells; i2++)
 	{
-	    e2 = G_col_to_easting  (list2->col[i2]+0.5, region);
-	    n2 = G_row_to_northing (list2->row[i2]+0.5, region);
-	    dist = G_distance (e1, n1, e2, n2);
+            if (!nulldistance) {
+                e2 = G_col_to_easting  (list2->col[i2]+0.5, region);
+                n2 = G_row_to_northing (list2->row[i2]+0.5, region);
+                dist = G_distance (e1, n1, e2, n2);
+            }
+            else {
+                e2 = G_col_to_easting  (zerro_col+0.5, region);
+                n2 = G_row_to_northing (zerro_row+0.5, region);
+                dist = 0.;
+            }
 
 	    if ((i1 == 0 && i2 == 0) || (dist < *distance) )
 	    {
@@ -53,6 +66,98 @@
 		*east2    = e2;
 		*north2   = n2;
 	    }
+            if (nulldistance)
+                break;
 	}
+        if (nulldistance)
+            break;
+    }
+}
+
+int null_distance(char *name1, char *name2, int *zerro_row, int *zerro_col)
+{
+    RASTER_MAP_TYPE maptype1, maptype2;
+    char *mapset;
+    int mapd1, mapd2;
+    void *inrast1, *inrast2;
+    int nrows, ncols, row, col;
+    void *cell1, *cell2;
+
+   /* NOTE: no need to controll, if the map exists. it should be checked in edge.c */
+    mapset = G_find_cell2(name1, "");
+    maptype1 = G_raster_map_type(name1, mapset);
+    mapd1 = G_open_cell_old(name1, mapset);
+    inrast1 = G_allocate_raster_buf(maptype1);
+
+    mapset = G_find_cell2(name2, "");
+    maptype2 = G_raster_map_type(name2, mapset);
+    mapd2 = G_open_cell_old(name2, mapset);
+    inrast2 = G_allocate_raster_buf(maptype2);
+    
+    G_message (_("Reading maps  <%s,%s> while finding 0 distance ..."), name1, name2);
+
+    ncols = G_window_cols();
+    nrows = G_window_rows();
+
+    for (row = 0; row < nrows; row++) {
+
+        G_percent(row, nrows, 2);
+
+	if (G_get_raster_row(mapd1, inrast1, row, maptype1) < 0)
+	    G_fatal_error("Could not read from <%s>", name1);
+	if (G_get_raster_row(mapd2, inrast2, row, maptype2) < 0)
+	    G_fatal_error("Could not read from <%s>", name2);
+
+	for (col = 0; col < ncols; col++) {
+
+            /* first raster */
+	    switch (maptype1) {
+                case CELL_TYPE:
+                    cell1 = ((CELL **) inrast1)[col];
+                    break;
+                case FCELL_TYPE:
+                    cell1 = ((FCELL **) inrast1)[col];
+                    break;
+                case DCELL_TYPE:
+                    cell1 = ((DCELL **) inrast1)[col];
+                    break;
+                }
+            /* second raster */
+	    switch (maptype2) {
+                case CELL_TYPE:
+                    cell2 = ((CELL **) inrast2)[col];
+                    break;
+                case FCELL_TYPE:
+                    cell2 = ((FCELL **) inrast2)[col];
+                    break;
+                case DCELL_TYPE:
+                    cell2 = ((DCELL **) inrast2)[col];
+                    break;
+                }
+
+	    if (!G_is_null_value(&cell1, maptype1) && !G_is_null_value(&cell2, maptype2)) {
+
+                *zerro_row = row;
+                *zerro_col = col;
+                 
+                /* memory cleanup */
+                G_free(inrast1);
+                G_free(inrast2);
+
+                /* closing raster files */
+                G_close_cell(mapd1);
+                G_close_cell(mapd2);
+                return 1;
+            }
+        }
     }
+    /* memory cleanup */
+    G_free(inrast1);
+    G_free(inrast2);
+
+    /* closing raster files */
+    G_close_cell(mapd1);
+    G_close_cell(mapd2);
+
+    return 0;
 }
Index: raster/r.distance/edges.c
===================================================================
RCS file: /grassrepository/grass6/raster/r.distance/edges.c,v
retrieving revision 2.2
diff -u -r2.2 edges.c
--- raster/r.distance/edges.c	2 Oct 2006 17:58:15 -0000	2.2
+++ raster/r.distance/edges.c	14 Oct 2006 20:44:26 -0000
@@ -37,7 +37,7 @@
     int fd;
     CELL *buf0, *buf1, *buf2, *tmp;
 
-    G_message ("Reading map %s ...", map->fullname);
+    G_message (_("Reading map %s ..."), map->fullname);
 
     ncols = G_window_cols();
     nrows = G_window_rows();
Index: raster/r.distance/parse.c
===================================================================
RCS file: /grassrepository/grass6/raster/r.distance/parse.c,v
retrieving revision 2.6
diff -u -r2.6 parse.c
--- raster/r.distance/parse.c	14 Oct 2006 19:00:38 -0000	2.6
+++ raster/r.distance/parse.c	14 Oct 2006 20:44:26 -0000
@@ -25,7 +25,7 @@
 parse (int argc, char *argv[], struct Parms *parms)
 {
     struct Option *maps, *fs;
-    struct Flag *labels;
+    struct Flag *labels, *overlap;
     char *name, *mapset;
 
     /* please, remove before GRASS 7 released */
@@ -53,6 +53,10 @@
     labels -> key = 'l';
     labels->description = _("Include category labels in the output");
 
+    overlap = G_define_flag();
+    overlap -> key = 'o';
+    overlap->description = _("Report zero distance if rasters are overlapping");
+
     /* please, remove before GRASS 7 released */
     q_flag = G_define_flag() ;
     q_flag->key         = 'q' ;  
@@ -84,4 +88,5 @@
 
     parms->labels = labels->answer ? 1 : 0;
     parms->fs = fs->answer;
+    parms->overlap = overlap->answer ? 1:0;
 }
Index: raster/r.distance/report.c
===================================================================
RCS file: /grassrepository/grass6/raster/r.distance/report.c,v
retrieving revision 2.2
diff -u -r2.2 report.c
--- raster/r.distance/report.c	2 Oct 2006 17:58:15 -0000	2.2
+++ raster/r.distance/report.c	14 Oct 2006 20:44:26 -0000
@@ -38,7 +38,7 @@
     map2 = &parms->map2;
     fs   = parms->fs;
 
-    G_message ("Processing...");
+    G_message (_("Processing..."));
 
     for (i1 = 0; i1 < map1->edges.ncats; i1++)
     {
@@ -47,7 +47,7 @@
 	{
 	    list2 = &map2->edges.catlist[i2];
 	    find_minimum_distance (list1, list2,
-		&east1, &north1, &east2, &north2, &distance, &region);
+		&east1, &north1, &east2, &north2, &distance, &region, parms->overlap, map1->name, map2->name);
 
 	/* print cat numbers */
 	    fprintf (stdout,"%ld%s%ld", (long)list1->cat, fs, (long)list2->cat) ;
