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

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Aug 2 08:41:56 EDT 2011


Author: mmetz
Date: 2011-08-02 05:41:56 -0700 (Tue, 02 Aug 2011)
New Revision: 47355

Modified:
   grass/trunk/lib/vector/diglib/linecros.c
Log:
fix for special case when segments are parallel to y axis

Modified: grass/trunk/lib/vector/diglib/linecros.c
===================================================================
--- grass/trunk/lib/vector/diglib/linecros.c	2011-08-02 12:40:27 UTC (rev 47354)
+++ grass/trunk/lib/vector/diglib/linecros.c	2011-08-02 12:41:56 UTC (rev 47355)
@@ -76,26 +76,58 @@
 	return 0;
 
     /* segments are colinear. check for overlap */
-    if (ax1 > ax2) {
-	t = ax1;
-	ax1 = ax2;
-	ax2 = t;
+
+    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   */
     }
-    if (bx1 > bx2) {
-	t = bx1;
-	bx1 = bx2;
-	bx2 = t;
-    }
-    if (ax1 > bx2)
-	return 0;
-    if (ax2 < bx1)
-	return 0;
+    else {
+	/* segments are parallel to y axis, use y values */
+	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)
+	    return 0;
 
-    /* there is overlap */
+	/* there is overlap */
 
-    if (ax1 == bx2 || ax2 == bx1)
-	return 1;		/* endpoints only */
-    return -1;			/* true overlap   */
+	if (ay1 == by2 || ay2 == by1)
+	    return 1;		/* endpoints only */
+
+	return -1;			/* true overlap   */
+    }
+    
+    return 0; /* should not be reached */
 }
 
 
@@ -128,32 +160,109 @@
     }
 
     /* segments are colinear. check for overlap */
-    if (ax1 > ax2) {
-	t = ax1;
-	ax1 = ax2;
-	ax2 = t;
+
+    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;
+
+	    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)
+	    return 0;
+
+	/* there is overlap */
+
+	if (ax1 == bx2) {
+	    *x = ax1;
+	    *y = ay1;
+	    return 1;		/* endpoints only */
+	}
+	if (ax2 == bx1) {
+	    *x = ax2;
+	    *y = ay2;
+	    return 1;		/* endpoints only */
+	}
+	
+	/* overlap, no single intersection point */
+	if (ax1 > bx1 && ax1 < bx2) {
+	    *x = ax1;
+	    *y = ay1;
+	}
+	else {
+	    *x = ax2;
+	    *y = ay2;
+	}
+	return -1;
     }
-    if (bx1 > bx2) {
-	t = bx1;
-	bx1 = bx2;
-	bx2 = t;
-    }
-    if (ax1 > bx2)
-	return 0;
-    if (ax2 < bx1)
-	return 0;
+    else {
+	/* segments are parallel to y axis, use y values */
+	if (ay1 > ay2) {
+	    /* need to swap both coords */
+	    t = ay1;
+	    ay1 = ay2;
+	    ay2 = t;
 
-    /* there is overlap */
+	    t = ax1;
+	    ax1 = ax2;
+	    ax2 = t;
+	}
+	if (by1 > by2) {
+	    /* need to swap both coords */
+	    t = by1;
+	    by1 = by2;
+	    by2 = t;
 
-    if (ax1 == bx2) {
-	*x = ax1;
-	*y = ay1;
-	return 1;		/* endpoints only */
+	    t = by1;
+	    by1 = by2;
+	    by2 = t;
+	}
+	if (ay1 > by2)
+	    return 0;
+	if (ay2 < by1)
+	    return 0;
+
+	/* there is overlap */
+
+	if (ay1 == by2) {
+	    *x = ax1;
+	    *y = ay1;
+	    return 1;		/* endpoints only */
+	}
+	if (ay2 == by1) {
+	    *x = ax2;
+	    *y = ay2;
+	    return 1;		/* endpoints only */
+	}
+
+	/* overlap, no single intersection point */
+	if (ay1 > by1 && ay1 < by2) {
+	    *x = ax1;
+	    *y = ay1;
+	}
+	else {
+	    *x = ax2;
+	    *y = ay2;
+	}
+	return -1;
     }
-    if (ax2 == bx1) {
-	*x = ax2;
-	*y = ay2;
-	return 1;		/* endpoints only */
-    }
-    return -1;			/* overlap, no single intersection point */
+
+    return 0; /* should not be reached */
 }



More information about the grass-commit mailing list