[GRASS-SVN] r56236 - grass/trunk/lib/vector/diglib

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 13 03:35:03 PDT 2013


Author: mmetz
Date: 2013-05-13 03:35:02 -0700 (Mon, 13 May 2013)
New Revision: 56236

Modified:
   grass/trunk/lib/vector/diglib/linecros.c
Log:
diglib: fix find intersection

Modified: grass/trunk/lib/vector/diglib/linecros.c
===================================================================
--- grass/trunk/lib/vector/diglib/linecros.c	2013-05-13 10:29:46 UTC (rev 56235)
+++ grass/trunk/lib/vector/diglib/linecros.c	2013-05-13 10:35:02 UTC (rev 56236)
@@ -137,6 +137,26 @@
     register double d, r1, r2;
     double t;
 
+    if (ax1 > ax2 || (ax1 == ax2 && ay1 > ay2)) {
+	t = ax1;
+	ax1 = ax2;
+	ax2 = t;
+
+	t = ay1;
+	ay1 = ay2;
+	ay2 = t;
+    }
+
+    if (bx1 > bx2 || (bx1 == bx2 && by1 > by2)) {
+	t = bx1;
+	bx1 = bx2;
+	bx2 = t;
+
+	t = by1;
+	by1 = by2;
+	by2 = t;
+    }
+
     d = D;
 
     if (d) {
@@ -160,16 +180,6 @@
 
     /* Collinear vertical */
     if (ax1 == ax2) {
-	if (ay1 > ay2) {
-	    t = ay1;
-	    ay1 = ay2;
-	    ay2 = t;
-	}
-	if (by1 > by2) {
-	    t = by1;
-	    by1 = by2;
-	    by2 = t;
-	}
 	if (ay1 > by2)
 	    return 0;
 	if (ay2 < by1)
@@ -200,26 +210,6 @@
 	return -1;
     }
     else {
-	if (ax1 > ax2) {
-	    /* need to swap both coords */
-	    t = ax1;
-	    ax1 = ax2;
-	    ax2 = t;
-
-	    t = ay1;
-	    ay1 = ay2;
-	    ay2 = t;
-	}
-	if (bx1 > bx2) {
-	    /* need to swap both coords */
-	    t = bx1;
-	    bx1 = bx2;
-	    bx2 = t;
-
-	    t = by1;
-	    by1 = by2;
-	    by2 = t;
-	}
 	if (ax1 > bx2)
 	    return 0;
 	if (ax2 < bx1)



More information about the grass-commit mailing list