Browse Source

diglib: add numerical stability to dig_x_intersect()

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@64195 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 10 years ago
parent
commit
fe9034ae98
1 changed files with 14 additions and 1 deletions
  1. 14 1
      lib/vector/diglib/inside.c

+ 14 - 1
lib/vector/diglib/inside.c

@@ -22,7 +22,20 @@ dig_x_intersect(double beg_x,
 		double end_x, double beg_y, double end_y, double Y)
 		double end_x, double beg_y, double end_y, double Y)
 {
 {
     double b;
     double b;
-    
+
+    /* assumes beg_y != end_y */
+
+    /* sort for numerical stability */
+    if (end_y < beg_y) {
+	b = end_x;
+	end_x = beg_x;
+	beg_x = b;
+
+	b = end_y;
+	end_y = beg_y;
+	beg_y = b;
+    }
+
     /* solve simple linear equation to get X = a + b * Y
     /* solve simple linear equation to get X = a + b * Y
      * with
      * with
      * b = (end_x - beg_x) / (end_y - beg_y)
      * b = (end_x - beg_x) / (end_y - beg_y)