[GRASS-SVN] r34309 - grass/trunk/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 15 15:42:52 EST 2008


Author: neteler
Date: 2008-11-15 15:42:52 -0500 (Sat, 15 Nov 2008)
New Revision: 34309

Modified:
   grass/trunk/lib/vector/Vlib/intersect.c
Log:
marisn: Add Vect_line_get_intersection() function (merge from develbranch_6, r34306)

Modified: grass/trunk/lib/vector/Vlib/intersect.c
===================================================================
--- grass/trunk/lib/vector/Vlib/intersect.c	2008-11-15 20:41:51 UTC (rev 34308)
+++ grass/trunk/lib/vector/Vlib/intersect.c	2008-11-15 20:42:52 UTC (rev 34309)
@@ -1065,7 +1065,7 @@
     return 1;
 }
 
-static struct line_pnts *APnts, *BPnts;
+static struct line_pnts *APnts, *BPnts, *IPnts;
 
 static int cross_found;		/* set by find_cross() */
 
@@ -1087,6 +1087,23 @@
 				    BPnts->y[j + 1], BPnts->z[j + 1], &x1,
 				    &y1, &z1, &x2, &y2, &z2, 0);
 
+    switch (ret) {
+    case 0:
+    case 5:
+	break;
+    case 1:
+	if (0 > Vect_copy_xyz_to_pnts(IPnts, &x1, &y1, &z1, 1))
+	    G_warning(_("Error while adding point to array. Out of memory"));
+	break;
+    case 2:
+    case 3:
+    case 4:
+	if (0 > Vect_copy_xyz_to_pnts(IPnts, &x1, &y1, &z1, 1))
+	    G_warning(_("Error while adding point to array. Out of memory"));
+	if (0 > Vect_copy_xyz_to_pnts(IPnts, &x2, &y2, &z2, 1))
+	    G_warning(_("Error while adding point to array. Out of memory"));
+	break;
+    }
     /* add ALL (including end points and duplicates), clean later */
     if (ret > 0) {
 	cross_found = 1;
@@ -1126,11 +1143,21 @@
     if (APoints->n_points == 1 && BPoints->n_points == 1) {
 	if (APoints->x[0] == BPoints->x[0] && APoints->y[0] == BPoints->y[0]) {
 	    if (!with_z) {
+		if (0 >
+		    Vect_copy_xyz_to_pnts(IPnts, &APoints->x[0],
+					  &APoints->y[0], NULL, 1))
+		    G_warning(_("Error while adding point to array. Out of memory"));
 		return 1;
 	    }
 	    else {
-		if (APoints->z[0] == BPoints->z[0])
+		if (APoints->z[0] == BPoints->z[0]) {
+		    if (0 >
+			Vect_copy_xyz_to_pnts(IPnts, &APoints->x[0],
+					      &APoints->y[0], &APoints->z[0],
+					      1))
+			G_warning(_("Error while adding point to array. Out of memory"));
 		    return 1;
+		}
 		else
 		    return 0;
 	    }
@@ -1146,6 +1173,10 @@
 			   NULL, NULL);
 
 	if (dist <= rethresh) {
+	    if (0 >
+		Vect_copy_xyz_to_pnts(IPnts, &APoints->x[0], &APoints->y[0],
+				      &APoints->z[0], 1))
+		G_warning(_("Error while adding point to array. Out of memory"));
 	    return 1;
 	}
 	else {
@@ -1158,8 +1189,13 @@
 			   BPoints->z[0], with_z, NULL, NULL, NULL, &dist,
 			   NULL, NULL);
 
-	if (dist <= rethresh)
+	if (dist <= rethresh) {
+	    if (0 >
+		Vect_copy_xyz_to_pnts(IPnts, &BPoints->x[0], &BPoints->y[0],
+				      &BPoints->z[0], 1))
+		G_warning(_("Error while adding point to array. Out of memory"));
 	    return 1;
+	}
 	else
 	    return 0;
     }
@@ -1246,3 +1282,29 @@
 
     return cross_found;
 }
+
+/*!
+ * \brief Get 2 lines intersection points.
+ * 
+ * A wrapper around Vect_line_check_intersection() function.
+ *
+ * \param[in] APoints first input line 
+ * \param[in] BPoints second input line 
+ * \param[out] IPoints output with intersection points
+ * \param[in] with_z 3D, not supported (only if one or both are points)!
+ *
+ * \return 0 no intersection 
+ * \return 1 intersection found
+ */
+int
+Vect_line_get_intersections(struct line_pnts *APoints,
+			    struct line_pnts *BPoints,
+			    struct line_pnts *IPoints, int with_z)
+{
+    int ret;
+
+    IPnts = IPoints;
+    ret = Vect_line_check_intersection(APoints, BPoints, with_z);
+
+    return ret;
+}



More information about the grass-commit mailing list