Browse Source

Fix off-by-half error

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@43943 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 14 năm trước cách đây
mục cha
commit
41a960fccc
4 tập tin đã thay đổi với 13 bổ sung11 xóa
  1. 4 4
      raster/r.proj/bilinear.c
  2. 4 4
      raster/r.proj/cubic.c
  3. 1 1
      raster/r.proj/cubic_f.c
  4. 4 2
      raster/r.proj/main.c

+ 4 - 4
raster/r.proj/bilinear.c

@@ -33,8 +33,8 @@ void p_bilinear(struct cache *ibuffer,	/* input buffer                  */
     FCELL *c00, *c01, *c10, *c11;
 
     /* cut indices to integer */
-    row0 = (int)floor(*row_idx);
-    col0 = (int)floor(*col_idx);
+    row0 = (int)floor(*row_idx - 0.5);
+    col0 = (int)floor(*col_idx - 0.5);
     row1 = row0 + 1;
     col1 = col0 + 1;
 
@@ -58,8 +58,8 @@ void p_bilinear(struct cache *ibuffer,	/* input buffer                  */
     }
 
     /* do the interpolation  */
-    t = *col_idx - col0;
-    u = *row_idx - row0;
+    t = *col_idx - 0.5 - col0;
+    u = *row_idx - 0.5 - row0;
     tu = t * u;
 
     result = Rast_interp_bilinear(t, u, *c00, *c01, *c10, *c11);

+ 4 - 4
raster/r.proj/cubic.c

@@ -35,8 +35,8 @@ void p_cubic(struct cache *ibuffer,	/* input buffer                  */
     FCELL *cellp[4][4];
 
     /* cut indices to integer */
-    row = (int)floor(*row_idx);
-    col = (int)floor(*col_idx);
+    row = (int)floor(*row_idx - 0.5);
+    col = (int)floor(*col_idx - 0.5);
 
     /* check for out of bounds of map - if out of bounds set NULL value     */
     if (row - 1 < 0 || row + 2 >= cellhd->rows ||
@@ -59,8 +59,8 @@ void p_cubic(struct cache *ibuffer,	/* input buffer                  */
 	}
 
     /* do the interpolation  */
-    t = *col_idx - col;
-    u = *row_idx - row;
+    t = *col_idx - 0.5 - col;
+    u = *row_idx - 0.5 - row;
 
     for (i = 0; i < 4; i++) {
 	FCELL **tmp = cellp[i];

+ 1 - 1
raster/r.proj/cubic_f.c

@@ -47,7 +47,7 @@ void p_cubic_f(struct cache *ibuffer,	/* input buffer                  */
     if (Rast_is_f_null_value(obufptr)) {
         p_bilinear(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
         /* fallback to nearest if bilinear is null */
-		if (Rast_is_f_null_value(obufptr))
+	if (Rast_is_f_null_value(obufptr))
             Rast_set_f_value(obufptr, *cellp, cell_type);
     }
 }

+ 4 - 2
raster/r.proj/main.c

@@ -236,11 +236,13 @@ int main(int argc, char **argv)
 	G_fatal_error(_("option <%s>: <%s> exists."), "output", mapname);
 
     setname = imapset->answer ? imapset->answer : G_store(G_mapset());
-
     if (strcmp(inlocation->answer, G_location()) == 0 &&
         (!indbase->answer || strcmp(indbase->answer, G_gisdbase()) == 0))
+#if 0
 	G_fatal_error(_("Input and output locations can not be the same"));
-
+#else
+	G_warning(_("Input and output locations are the same"));
+#endif
     G_get_window(&outcellhd);
 
     if(gprint_bounds->answer && !print_bounds->answer)