]> granicus.if.org Git - postgis/commitdiff
Added check of values being passed to atan2() in _st_hillshade4ma()
authorBborie Park <bkpark at ucdavis.edu>
Wed, 1 Feb 2012 22:06:18 +0000 (22:06 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Wed, 1 Feb 2012 22:06:18 +0000 (22:06 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9007 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_pg/rtpostgis.sql.in.c

index 8e23a84a17eaf02e5fe0fd2b88eab98cfb3bc34c..4f83c15556aa9e3cd6dfdc952c5272db122ee026 100644 (file)
@@ -2008,7 +2008,7 @@ CREATE OR REPLACE FUNCTION _st_aspect4ma(matrix float[][], nodatamode text, vari
         pheight := args[2]::float;
         dz_dx := ((matrix[3][1] + 2.0 * matrix[3][2] + matrix[3][3]) - (matrix[1][1] + 2.0 * matrix[1][2] + matrix[1][3])) / (8.0 * pwidth);
         dz_dy := ((matrix[1][3] + 2.0 * matrix[2][3] + matrix[3][3]) - (matrix[1][1] + 2.0 * matrix[2][1] + matrix[3][1])) / (8.0 * pheight);
-        IF dz_dx = 0 AND dz_dy = 0 THEN
+        IF abs(dz_dx) = 0::float AND abs(dz_dy) = 0::float THEN
             RETURN -1;
         END IF;
 
@@ -2052,7 +2052,13 @@ CREATE OR REPLACE FUNCTION _st_hillshade4ma(matrix float[][], nodatamode text, v
         dz_dy := ((matrix[1][3] + 2.0 * matrix[2][3] + matrix[3][3]) - (matrix[1][1] + 2.0 * matrix[2][1] + matrix[3][1])) / (8.0 * pheight);
         elevation_scale := args[6]::float;
         slope := atan(sqrt(elevation_scale * pow(dz_dx, 2.0) + pow(dz_dy, 2.0)));
-        aspect := atan2(dz_dy, -dz_dx);
+                               -- handle special case of 0, 0
+                               IF abs(dz_dy) = 0::float AND abs(dz_dy) = 0::float THEN
+                                       -- set to pi as that is the expected PostgreSQL answer in Linux
+                                       aspect := pi();
+                               ELSE
+                                       aspect := atan2(dz_dy, -dz_dx);
+                               END IF;
         max_bright := args[5]::float;
 
         IF aspect < 0 THEN