Bläddra i källkod

diglib: optimize dig_x_intersect

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@52520 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 12 år sedan
förälder
incheckning
57e8999994
1 ändrade filer med 12 tillägg och 3 borttagningar
  1. 12 3
      lib/vector/diglib/inside.c

+ 12 - 3
lib/vector/diglib/inside.c

@@ -21,9 +21,18 @@ double
 dig_x_intersect(double beg_x,
 		double end_x, double beg_y, double end_y, double Y)
 {
-    double b, a;
+    double b;
+    
+    /* solve simple linear equation to get X = a + b * Y
+     * with
+     * b = (end_x - beg_x) / (end_y - beg_y)
+     * a = beg_x - b * beg_y
+     * 
+     * simplify a + b * Y: 
+     * a + b * Y = beg_x - b * beg_y + b * Y
+     * a + b * Y = beg_x + b * (Y - beg_y) */
 
     b = (end_x - beg_x) / (end_y - beg_y);
-    a = beg_x - b * beg_y;
-    return (a + b * Y);
+
+    return beg_x + b * (Y - beg_y);
 }