From 0a946a4627b08dad247914d325b9f73fa6142288 Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Wed, 19 Sep 2012 18:48:37 +0000 Subject: [PATCH] Additional regression tests for rt_raster_get_nearest_pixel() git-svn-id: http://svn.osgeo.org/postgis/trunk@10306 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_core/rt_api.c | 7 +++++-- raster/test/core/testapi.c | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 236eaaaf8..d07e3c7db 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -2379,7 +2379,7 @@ int rt_band_get_nearest_pixel( uint32_t i = 0; uint32_t j = 0; uint32_t k = 0; - uint32_t _max = 0; + int _max = 0; int _x = 0; int _y = 0; int *_min = NULL; @@ -2484,6 +2484,8 @@ int rt_band_get_nearest_pixel( max_extent[1] = y - distance[1]; /* min Y */ max_extent[2] = x + distance[0]; /* max X */ max_extent[3] = y + distance[1]; /* max Y */ + RASTER_DEBUGF(4, "Maximum Extent: (%d, %d, %d, %d)", + max_extent[0], max_extent[1], max_extent[2], max_extent[3]); _d[0] = 0; _d[1] = 0; @@ -2538,13 +2540,14 @@ int rt_band_get_nearest_pixel( _x = extent[2]; } - RASTER_DEBUGF(4, "_min, _max: %d, %d", _min, _max); + RASTER_DEBUGF(4, "_min, _max: %d, %d", *_min, _max); for (k = 0; k < _max; k++) { /* check that _x and _y are not outside max extent */ if ( _x < max_extent[0] || _x > max_extent[2] || _y < max_extent[1] || _y > max_extent[3] ) { + (*_min)++; continue; } diff --git a/raster/test/core/testapi.c b/raster/test/core/testapi.c index d46c31f21..2865d9f88 100644 --- a/raster/test/core/testapi.c +++ b/raster/test/core/testapi.c @@ -7028,6 +7028,30 @@ static void testNearestPixel() { if (rtn) rtdealloc(npixels); + /* 2,7 distance 3,1 */ + rtn = rt_band_get_nearest_pixel( + band, + 2, 7, + 3, 1, + 1, + &npixels + ); + CHECK((rtn == 13)); + if (rtn) + rtdealloc(npixels); + + /* 10,10 distance 1,3 */ + rtn = rt_band_get_nearest_pixel( + band, + 10,10, + 1, 3, + 1, + &npixels + ); + CHECK((rtn == 3)); + if (rtn) + rtdealloc(npixels); + deepRelease(rast); } -- 2.40.0