[GRASS-SVN] r32811 - in grass-addons/vector: v.buffer2 v.parallel2

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Aug 16 07:42:16 EDT 2008


Author: rmatev
Date: 2008-08-16 07:42:15 -0400 (Sat, 16 Aug 2008)
New Revision: 32811

Modified:
   grass-addons/vector/v.buffer2/main.c
   grass-addons/vector/v.buffer2/vlib_buffer.c
   grass-addons/vector/v.parallel2/vlib_buffer.c
Log:
Fixed Vect_area_buffer()

Modified: grass-addons/vector/v.buffer2/main.c
===================================================================
--- grass-addons/vector/v.buffer2/main.c	2008-08-16 09:46:03 UTC (rev 32810)
+++ grass-addons/vector/v.buffer2/main.c	2008-08-16 11:42:15 UTC (rev 32811)
@@ -192,6 +192,7 @@
         exit(EXIT_FAILURE);
     
     type = Vect_option_to_types ( type_opt );
+    G_message("type = %x", type);
     field = atoi( field_opt->answer );
     
     if ((dista_opt->answer && bufcol_opt->answer) || (!(dista_opt->answer || bufcol_opt->answer)))
@@ -309,7 +310,7 @@
             G_percent(line, nlines, 2);
 
             ltype = Vect_read_line(&In, Points, Cats, line);
-            if (!(ltype & type ))
+            if (!(ltype & type))
                 continue;
 
             if (!Vect_cat_get(Cats, field, &cat))
@@ -339,14 +340,23 @@
                 G_debug(2, _("The tolerance in map units: %g"), unit_tolerance);
             }
             
-            Vect_line_buffer2(Points, da, db, dalpha, !(straight_flag->answer), !(nocaps_flag->answer), unit_tolerance, &(arr_bc[buffers_count].oPoints), &(arr_bc[buffers_count].iPoints), &(arr_bc[buffers_count].inner_count));
-            buffers_count++;
+            if (ltype & GV_POINTS) {
+                Vect_point_buffer2(Points->x[0], Points->y[0], da, db, dalpha, !(straight_flag->answer), unit_tolerance, &(arr_bc[buffers_count].oPoints));
+                arr_bc[buffers_count].iPoints = NULL;
+                arr_bc[buffers_count].inner_count = 0;
+                buffers_count++;
+                    
+            }
+            else {
+                Vect_line_buffer2(Points, da, db, dalpha, !(straight_flag->answer), !(nocaps_flag->answer), unit_tolerance, &(arr_bc[buffers_count].oPoints), &(arr_bc[buffers_count].iPoints), &(arr_bc[buffers_count].inner_count));
+                buffers_count++;
+            }
         }
     }
 
     /* Areas */
     if (type & GV_AREA) {
-        int centroid, nisles, isle;
+        int centroid;
         
         G_message ( _("Areas buffers... "));
         for (area = 1; area <= nareas; area++) {
@@ -402,14 +412,14 @@
     G_message (_("Building parts of topology...") );
     Vect_build_partial(&Out, GV_BUILD_BASE, stderr);
 
-/*    G_message(_("Snapping boundaries...") );
-    Vect_snap_lines ( &Out, GV_BOUNDARY, 1e-7, NULL, stderr );*/
+    G_message(_("Snapping boundaries...") );
+    Vect_snap_lines ( &Out, GV_BOUNDARY, 1e-7, NULL, stderr );
 
     G_message(_( "Breaking boundaries...") );
     Vect_break_lines ( &Out, GV_BOUNDARY, NULL, stderr );
 
-/*    G_message(_( "Removing duplicates...") );
-    Vect_remove_duplicates ( &Out, GV_BOUNDARY, NULL, stderr );*/
+    G_message(_( "Removing duplicates...") );
+    Vect_remove_duplicates ( &Out, GV_BOUNDARY, NULL, stderr );
 
     /* Dangles and bridges don't seem to be necessary if snapping is small enough. */
     /*

Modified: grass-addons/vector/v.buffer2/vlib_buffer.c
===================================================================
--- grass-addons/vector/v.buffer2/vlib_buffer.c	2008-08-16 09:46:03 UTC (rev 32810)
+++ grass-addons/vector/v.buffer2/vlib_buffer.c	2008-08-16 11:42:15 UTC (rev 32811)
@@ -24,19 +24,21 @@
 #define NON_LOOPED_LINE 0
 
 /* norm_vector() calculates normalized vector form two points */
-static void norm_vector(double x1, double y1, double x2, double y2, double *x, double *y )
-{
+static void norm_vector(double x1, double y1, double x2, double y2, double *x, double *y) {
     double dx, dy, l;
     dx  = x2 - x1;
     dy  = y2 - y1;
-    l = LENGTH(dx, dy);
-    if (l == 0) {
+    if ((dx == 0) && (dy == 0)) {
         /* assume that dx == dy == 0, which should give (NaN,NaN) */
         /* without this, very small dx or dy could result in Infinity */
-        dx = dy = 0;
+        *x = 0;
+        *y = 0;
+        return;
     }
+    l = LENGTH(dx, dy);
     *x = dx/l;
     *y = dy/l;
+    return;
 }
 
 static void rotate_vector(double x, double y, double cosa, double sina, double *nx, double *ny) {
@@ -197,6 +199,9 @@
         
         
         norm_vector(x[i], y[i], x[i+1], y[i+1], &tx, &ty);
+        if ((tx == 0) && (ty == 0))
+            continue;
+        
         elliptic_tangent(side*tx, side*ty, da, db, dalpha, &vx, &vy);
         
         nx = x[i] + vx;
@@ -307,7 +312,8 @@
     double angle0, angle1;
     int inner_corner, turns360;
     
-    G_debug(4, "convolution_line()");
+    G_debug(3, "convolution_line()");
+    G_debug(3, "    side = %d", side);
 
     np = Points->n_points;
     x = Points->x;
@@ -355,6 +361,8 @@
         angle0 = angle1;
         
         norm_vector(x[i], y[i], x[i+1], y[i+1], &tx, &ty);
+        if ((tx == 0) && (ty == 0))
+            continue;
         elliptic_tangent(side*tx, side*ty, da, db, dalpha, &vx, &vy);
         angle1 = atan2(ty, tx);
         nx = x[i] + vx;
@@ -732,7 +740,7 @@
 
         area += (y2+y1)*(x2-x1);
     }
-    return signbit(area);
+    return !signbit(area);
 }
 
 /* internal */
@@ -954,7 +962,7 @@
 }
 
 /*!
-  \fn void Vect_point_buffer(double px, double py, double da, double db, double dalpha, int round, double tol, struct line_pnts *nPoints) {
+  \fn void Vect_point_buffer(double px, double py, double da, double db, double dalpha, int round, double tol, struct line_pnts **oPoints) {
   \brief Creates buffer around the point (px,py).
   \param px input point x-coordinate
   \param py input point y-coordinate
@@ -965,12 +973,12 @@
   \param tol maximum distance between theoretical arc and output segments
   \param nPoints output polygon outer border (ccw order)
 */
-void Vect_point_buffer2(double px, double py, double da, double db, double dalpha, int round, double tol, struct line_pnts *nPoints) {
+void Vect_point_buffer2(double px, double py, double da, double db, double dalpha, int round, double tol, struct line_pnts **oPoints) {
     double tx, ty;
     double angular_tol, angular_step, phi1;
     int j, nsegments;
     
-    Vect_reset_line(nPoints);
+    *oPoints = Vect_new_line_struct();
     
     dalpha *= PI/180; /* convert dalpha from degrees to radians */
 
@@ -983,7 +991,7 @@
         phi1 = 0;
         for (j = 0; j < nsegments; j++) {
             elliptic_transform(cos(phi1), sin(phi1), da, db, dalpha, &tx, &ty);
-            Vect_append_point(nPoints, px + tx, py + ty, 0);
+            Vect_append_point(*oPoints, px + tx, py + ty, 0);
             phi1 += angular_step;
         }
     }
@@ -992,7 +1000,7 @@
     }
     
     /* close the output line */
-    Vect_append_point(nPoints, nPoints->x[0], nPoints->y[0], nPoints->z[0]);    
+    Vect_append_point(*oPoints, (*oPoints)->x[0], (*oPoints)->y[0], (*oPoints)->z[0]);    
 }
 
 

Modified: grass-addons/vector/v.parallel2/vlib_buffer.c
===================================================================
--- grass-addons/vector/v.parallel2/vlib_buffer.c	2008-08-16 09:46:03 UTC (rev 32810)
+++ grass-addons/vector/v.parallel2/vlib_buffer.c	2008-08-16 11:42:15 UTC (rev 32811)
@@ -24,19 +24,21 @@
 #define NON_LOOPED_LINE 0
 
 /* norm_vector() calculates normalized vector form two points */
-static void norm_vector(double x1, double y1, double x2, double y2, double *x, double *y )
-{
+static void norm_vector(double x1, double y1, double x2, double y2, double *x, double *y) {
     double dx, dy, l;
     dx  = x2 - x1;
     dy  = y2 - y1;
-    l = LENGTH(dx, dy);
-    if (l == 0) {
+    if ((dx == 0) && (dy == 0)) {
         /* assume that dx == dy == 0, which should give (NaN,NaN) */
         /* without this, very small dx or dy could result in Infinity */
-        dx = dy = 0;
+        *x = 0;
+        *y = 0;
+        return;
     }
+    l = LENGTH(dx, dy);
     *x = dx/l;
     *y = dy/l;
+    return;
 }
 
 static void rotate_vector(double x, double y, double cosa, double sina, double *nx, double *ny) {
@@ -197,6 +199,9 @@
         
         
         norm_vector(x[i], y[i], x[i+1], y[i+1], &tx, &ty);
+        if ((tx == 0) && (ty == 0))
+            continue;
+        
         elliptic_tangent(side*tx, side*ty, da, db, dalpha, &vx, &vy);
         
         nx = x[i] + vx;
@@ -307,7 +312,8 @@
     double angle0, angle1;
     int inner_corner, turns360;
     
-    G_debug(4, "convolution_line()");
+    G_debug(3, "convolution_line()");
+    G_debug(3, "    side = %d", side);
 
     np = Points->n_points;
     x = Points->x;
@@ -355,6 +361,8 @@
         angle0 = angle1;
         
         norm_vector(x[i], y[i], x[i+1], y[i+1], &tx, &ty);
+        if ((tx == 0) && (ty == 0))
+            continue;
         elliptic_tangent(side*tx, side*ty, da, db, dalpha, &vx, &vy);
         angle1 = atan2(ty, tx);
         nx = x[i] + vx;
@@ -732,7 +740,7 @@
 
         area += (y2+y1)*(x2-x1);
     }
-    return signbit(area);
+    return !signbit(area);
 }
 
 /* internal */
@@ -954,7 +962,7 @@
 }
 
 /*!
-  \fn void Vect_point_buffer(double px, double py, double da, double db, double dalpha, int round, double tol, struct line_pnts *nPoints) {
+  \fn void Vect_point_buffer(double px, double py, double da, double db, double dalpha, int round, double tol, struct line_pnts **oPoints) {
   \brief Creates buffer around the point (px,py).
   \param px input point x-coordinate
   \param py input point y-coordinate
@@ -965,12 +973,12 @@
   \param tol maximum distance between theoretical arc and output segments
   \param nPoints output polygon outer border (ccw order)
 */
-void Vect_point_buffer2(double px, double py, double da, double db, double dalpha, int round, double tol, struct line_pnts *nPoints) {
+void Vect_point_buffer2(double px, double py, double da, double db, double dalpha, int round, double tol, struct line_pnts **oPoints) {
     double tx, ty;
     double angular_tol, angular_step, phi1;
     int j, nsegments;
     
-    Vect_reset_line(nPoints);
+    *oPoints = Vect_new_line_struct();
     
     dalpha *= PI/180; /* convert dalpha from degrees to radians */
 
@@ -983,7 +991,7 @@
         phi1 = 0;
         for (j = 0; j < nsegments; j++) {
             elliptic_transform(cos(phi1), sin(phi1), da, db, dalpha, &tx, &ty);
-            Vect_append_point(nPoints, px + tx, py + ty, 0);
+            Vect_append_point(*oPoints, px + tx, py + ty, 0);
             phi1 += angular_step;
         }
     }
@@ -992,7 +1000,7 @@
     }
     
     /* close the output line */
-    Vect_append_point(nPoints, nPoints->x[0], nPoints->y[0], nPoints->z[0]);    
+    Vect_append_point(*oPoints, (*oPoints)->x[0], (*oPoints)->y[0], (*oPoints)->z[0]);    
 }
 
 



More information about the grass-commit mailing list