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

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


Author: mmetz
Date: 2013-05-13 03:29:46 -0700 (Mon, 13 May 2013)
New Revision: 56235

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

Modified: grass/trunk/lib/vector/diglib/linecros.c
===================================================================
--- grass/trunk/lib/vector/diglib/linecros.c	2013-05-13 10:24:30 UTC (rev 56234)
+++ grass/trunk/lib/vector/diglib/linecros.c	2013-05-13 10:29:46 UTC (rev 56235)
@@ -77,33 +77,8 @@
 
     /* segments are colinear. check for overlap */
 
-    if (ax1 != ax2) {
-	/* segments are not parallel to y axis, can use x values */
-    
-	if (ax1 > ax2) {
-	    t = ax1;
-	    ax1 = ax2;
-	    ax2 = t;
-	}
-	if (bx1 > bx2) {
-	    t = bx1;
-	    bx1 = bx2;
-	    bx2 = t;
-	}
-	if (ax1 > bx2)
-	    return 0;
-	if (ax2 < bx1)
-	    return 0;
-
-	/* there is overlap */
-
-	if (ax1 == bx2 || ax2 == bx1)
-	    return 1;		/* endpoints only */
-
-	return -1;			/* true overlap   */
-    }
-    else {
-	/* segments are parallel to y axis, use y values */
+    /* Collinear vertical */
+    if (ax1 == ax2) {
 	if (ay1 > ay2) {
 	    t = ay1;
 	    ay1 = ay2;
@@ -126,7 +101,29 @@
 
 	return -1;			/* true overlap   */
     }
-    
+    else {
+	if (ax1 > ax2) {
+	    t = ax1;
+	    ax1 = ax2;
+	    ax2 = t;
+	}
+	if (bx1 > bx2) {
+	    t = bx1;
+	    bx1 = bx2;
+	    bx2 = t;
+	}
+	if (ax1 > bx2)
+	    return 0;
+	if (ax2 < bx1)
+	    return 0;
+
+	/* there is overlap */
+
+	if (ax1 == bx2 || ax2 == bx1)
+	    return 1;		/* endpoints only */
+
+	return -1;			/* true overlap   */
+    }    
     return 0; /* should not be reached */
 }
 
@@ -161,48 +158,38 @@
 
     /* segments are colinear. check for overlap */
 
-    if (ax1 != ax2) {
-	/* segments are not parallel to y axis, can use x values */
-	if (ax1 > ax2) {
-	    /* need to swap both coords */
-	    t = ax1;
-	    ax1 = ax2;
-	    ax2 = t;
-
+    /* Collinear vertical */
+    if (ax1 == ax2) {
+	if (ay1 > ay2) {
 	    t = ay1;
 	    ay1 = ay2;
 	    ay2 = t;
 	}
-	if (bx1 > bx2) {
-	    /* need to swap both coords */
-	    t = bx1;
-	    bx1 = bx2;
-	    bx2 = t;
-
+	if (by1 > by2) {
 	    t = by1;
 	    by1 = by2;
 	    by2 = t;
 	}
-	if (ax1 > bx2)
+	if (ay1 > by2)
 	    return 0;
-	if (ax2 < bx1)
+	if (ay2 < by1)
 	    return 0;
 
 	/* there is overlap */
 
-	if (ax1 == bx2) {
+	if (ay1 == by2) {
 	    *x = ax1;
 	    *y = ay1;
 	    return 1;		/* endpoints only */
 	}
-	if (ax2 == bx1) {
+	if (ay2 == by1) {
 	    *x = ax2;
 	    *y = ay2;
 	    return 1;		/* endpoints only */
 	}
-	
+
 	/* overlap, no single intersection point */
-	if (ax1 > bx1 && ax1 < bx2) {
+	if (ay1 > by1 && ay1 < by2) {
 	    *x = ax1;
 	    *y = ay1;
 	}
@@ -213,47 +200,46 @@
 	return -1;
     }
     else {
-	/* segments are parallel to y axis, use y values */
-	if (ay1 > ay2) {
+	if (ax1 > ax2) {
 	    /* need to swap both coords */
-	    t = ay1;
-	    ay1 = ay2;
-	    ay2 = t;
-
 	    t = ax1;
 	    ax1 = ax2;
 	    ax2 = t;
+
+	    t = ay1;
+	    ay1 = ay2;
+	    ay2 = t;
 	}
-	if (by1 > by2) {
+	if (bx1 > bx2) {
 	    /* need to swap both coords */
-	    t = by1;
-	    by1 = by2;
-	    by2 = t;
+	    t = bx1;
+	    bx1 = bx2;
+	    bx2 = t;
 
 	    t = by1;
 	    by1 = by2;
 	    by2 = t;
 	}
-	if (ay1 > by2)
+	if (ax1 > bx2)
 	    return 0;
-	if (ay2 < by1)
+	if (ax2 < bx1)
 	    return 0;
 
 	/* there is overlap */
 
-	if (ay1 == by2) {
+	if (ax1 == bx2) {
 	    *x = ax1;
 	    *y = ay1;
 	    return 1;		/* endpoints only */
 	}
-	if (ay2 == by1) {
+	if (ax2 == bx1) {
 	    *x = ax2;
 	    *y = ay2;
 	    return 1;		/* endpoints only */
 	}
-
+	
 	/* overlap, no single intersection point */
-	if (ay1 > by1 && ay1 < by2) {
+	if (ax1 > bx1 && ax1 < bx2) {
 	    *x = ax1;
 	    *y = ay1;
 	}



More information about the grass-commit mailing list