]> granicus.if.org Git - postgis/commitdiff
Additional regression tests for rt_raster_get_nearest_pixel()
authorBborie Park <bkpark at ucdavis.edu>
Wed, 19 Sep 2012 18:48:37 +0000 (18:48 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Wed, 19 Sep 2012 18:48:37 +0000 (18:48 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10306 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/test/core/testapi.c

index 236eaaaf84db9ddb878e67370ea703970f6a0581..d07e3c7db665280de27f42355f9310767426d57e 100644 (file)
@@ -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;
                                        }
 
index d46c31f2168e17735ddffb86000ee85846a9c589..2865d9f883c26a4d9953d4d629d7b89fb79bca41 100644 (file)
@@ -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);
 }