Bläddra i källkod

Vlib: Vect_line_buffe2(), Vect_area_buffer2(), Vect_point_buffer2() and
Vect_line_parallel() moved from v.buffer2 and v.parallel2 to
vector library (buffer2.c)

(merge from devbr6, https://trac.osgeo.org/grass/changeset/34601)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@34602 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 16 år sedan
förälder
incheckning
11cd111cbd

+ 15 - 0
include/Vect.h

@@ -35,7 +35,22 @@ int Vect_line_distance(struct line_pnts *, double, double, double, int,
 int Vect_line_box(struct line_pnts *, BOUND_BOX *);
 void Vect_line_parallel(struct line_pnts *, double, double, int,
 			struct line_pnts *);
+void Vect_line_parallel2(struct line_pnts *, double, double,
+			 double, int, int, double,
+			 struct line_pnts *);
 void Vect_line_buffer(struct line_pnts *, double, double, struct line_pnts *);
+void Vect_line_buffer2(struct line_pnts *, double, double,
+		       double, int, int, double,
+		       struct line_pnts **,
+		       struct line_pnts ***, int *);
+void Vect_area_buffer2(struct Map_info *, int, double, double,
+		       double, int, int, double,
+		       struct line_pnts **,
+		       struct line_pnts ***, int *);
+void Vect_point_buffer2(double, double, double, double,
+			double, int, double,
+			struct line_pnts **);
+
 
 /* Categories */
 struct line_cats *Vect_new_cats_struct(void);

+ 1 - 1
lib/vector/Vlib/buffer.c

@@ -1,7 +1,7 @@
 /*!
    \file buffer.c
 
-   \brief Vector library - nearest, adjust_line, parallel_line
+   \brief Vector library - nearest, adjust, parallel lines
 
    Higher level functions for reading/writing/manipulating vectors.
 

+ 79 - 44
vector/v.buffer2/vlib_buffer.c

@@ -1,9 +1,23 @@
-/* Functions: ...
- **
- ** Author: Radim Blazek, Rosen Matev; July 2008
- **
- **
+/*!
+   \file buffer2.c
+
+   \brief Vector library - nearest, adjust, parallel lines
+
+   Higher level functions for reading/writing/manipulating vectors.
+
+   (C) 2001-2008 by the GRASS Development Team
+
+   This program is free software under the 
+   GNU General Public License (>=v2). 
+   Read the file COPYING that comes with GRASS
+   for details.
+
+   \author Original author Radim Blazek (see buffer.c)
+   \author Rewritten by Rosen Matev (Google Summer of Code 2008)
+
+   \date 2008
  */
+
 #include <stdlib.h>
 #include <grass/Vect.h>
 #include <grass/gis.h>
@@ -167,9 +181,9 @@ static double angular_tolerance(double tol, double da, double db)
  * when (da == db) we have plain distances (old case)
  * round - 1 for round corners, 0 for sharp corners. (tol is used only if round == 1)
  */
-void parallel_line(struct line_pnts *Points, double da, double db,
-		   double dalpha, int side, int round, int caps, int looped,
-		   double tol, struct line_pnts *nPoints)
+static void parallel_line(struct line_pnts *Points, double da, double db,
+			  double dalpha, int side, int round, int caps, int looped,
+			  double tol, struct line_pnts *nPoints)
 {
     int i, j, res, np;
 
@@ -328,9 +342,9 @@ void parallel_line(struct line_pnts *Points, double da, double db,
 }
 
 /* input line must be looped */
-void convolution_line(struct line_pnts *Points, double da, double db,
-		      double dalpha, int side, int round, int caps,
-		      double tol, struct line_pnts *nPoints)
+static void convolution_line(struct line_pnts *Points, double da, double db,
+			     double dalpha, int side, int round, int caps,
+			     double tol, struct line_pnts *nPoints)
 {
     int i, j, res, np;
 
@@ -638,8 +652,8 @@ static void extract_contour(struct planar_graph *pg, struct pg_edge *first,
  * 
  * TODO: Implement side != 0 feature;
  */
-void extract_outer_contour(struct planar_graph *pg, int side,
-			   struct line_pnts *nPoints)
+static void extract_outer_contour(struct planar_graph *pg, int side,
+				  struct line_pnts *nPoints)
 {
     int i;
 
@@ -694,8 +708,8 @@ void extract_outer_contour(struct planar_graph *pg, int side,
  *
  * returns: 0 when there are no more inner contours; otherwise, 1
  */
-int extract_inner_contour(struct planar_graph *pg, int *winding,
-			  struct line_pnts *nPoints)
+static int extract_inner_contour(struct planar_graph *pg, int *winding,
+				 struct line_pnts *nPoints)
 {
     int i, w;
 
@@ -731,8 +745,8 @@ int extract_inner_contour(struct planar_graph *pg, int *winding,
  ** returns:  1 in buffer
  **           0 not in buffer
  */
-int point_in_buf(struct line_pnts *Points, double px, double py, double da,
-		 double db, double dalpha)
+static int point_in_buf(struct line_pnts *Points, double px, double py, double da,
+			double db, double dalpha)
 {
     int i, np;
 
@@ -807,7 +821,7 @@ int point_in_buf(struct line_pnts *Points, double px, double py, double da,
 
 /* returns 0 for ccw, non-zero for cw
  */
-int get_polygon_orientation(const double *x, const double *y, int n)
+static int get_polygon_orientation(const double *x, const double *y, int n)
 {
     double x1, y1, x2, y2;
 
@@ -830,9 +844,9 @@ int get_polygon_orientation(const double *x, const double *y, int n)
 }
 
 /* internal */
-void add_line_to_array(struct line_pnts *Points,
-		       struct line_pnts ***arrPoints, int *count,
-		       int *allocated, int more)
+static void add_line_to_array(struct line_pnts *Points,
+			      struct line_pnts ***arrPoints, int *count,
+			      int *allocated, int more)
 {
     if (*allocated == *count) {
 	*allocated += more;
@@ -844,7 +858,7 @@ void add_line_to_array(struct line_pnts *Points,
     return;
 }
 
-void destroy_lines_array(struct line_pnts **arr, int count)
+static void destroy_lines_array(struct line_pnts **arr, int count)
 {
     int i;
 
@@ -856,11 +870,11 @@ void destroy_lines_array(struct line_pnts **arr, int count)
 /* area_outer and area_isles[i] must be closed non self-intersecting lines
    side: 0 - auto, 1 - right, -1 left
  */
-void buffer_lines(struct line_pnts *area_outer, struct line_pnts **area_isles,
-		  int isles_count, int side, double da, double db,
-		  double dalpha, int round, int caps, double tol,
-		  struct line_pnts **oPoints, struct line_pnts ***iPoints,
-		  int *inner_count)
+static void buffer_lines(struct line_pnts *area_outer, struct line_pnts **area_isles,
+			 int isles_count, int side, double da, double db,
+			 double dalpha, int round, int caps, double tol,
+			 struct line_pnts **oPoints, struct line_pnts ***iPoints,
+			 int *inner_count)
 {
     struct planar_graph *pg2;
 
@@ -966,18 +980,20 @@ void buffer_lines(struct line_pnts *area_outer, struct line_pnts **area_isles,
 
 
 /*!
-   \fn void Vect_line_buffer(struct line_pnts *Points, double da, double db, double dalpha, int round, int caps, double tol, struct line_pnts **oPoints, struct line_pnts ***iPoints, int *inner_count) {
-   \brief Creates buffer around the line Points.
-   \param InPoints input line
+   \brief Creates buffer around line.
+
+   See also Vect_line_buffer().
+
+   \param InPoints input line geometry
    \param da distance along major axis
-   \param da distance along minor axis
+   \param db distance along minor axis
    \param dalpha angle between 0x and major axis
    \param round make corners round
    \param caps add caps at line ends
    \param tol maximum distance between theoretical arc and output segments
-   \param oPoints output polygon outer border (ccw order)
-   \param inner_count number of holes
-   \param iPoints array of output polygon's holes (cw order)
+   \param[out] oPoints output polygon outer border (ccw order)
+   \param[out] inner_count number of holes
+   \param[out] iPoints array of output polygon's holes (cw order)
  */
 void Vect_line_buffer2(struct line_pnts *Points, double da, double db,
 		       double dalpha, int round, int caps, double tol,
@@ -1029,6 +1045,21 @@ void Vect_line_buffer2(struct line_pnts *Points, double da, double db,
     return;
 }
 
+/*!
+   \brief Creates buffer around area.
+
+   \param Map vector map
+   \param area area id
+   \param da distance along major axis
+   \param db distance along minor axis
+   \param dalpha angle between 0x and major axis
+   \param round make corners round
+   \param caps add caps at line ends
+   \param tol maximum distance between theoretical arc and output segments
+   \param[out] oPoints output polygon outer border (ccw order)
+   \param[out] inner_count number of holes
+   \param[out] iPoints array of output polygon's holes (cw order)
+ */
 void Vect_area_buffer2(struct Map_info *Map, int area, double da, double db,
 		       double dalpha, int round, int caps, double tol,
 		       struct line_pnts **oPoints,
@@ -1087,8 +1118,8 @@ void Vect_area_buffer2(struct Map_info *Map, int area, double da, double db,
 }
 
 /*!
-   \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).
+   \brief Creates buffer around the point (px, py).
+
    \param px input point x-coordinate
    \param py input point y-coordinate
    \param da distance along major axis
@@ -1096,7 +1127,7 @@ void Vect_area_buffer2(struct Map_info *Map, int area, double da, double db,
    \param dalpha angle between 0x and major axis
    \param round make corners round
    \param tol maximum distance between theoretical arc and output segments
-   \param nPoints output polygon outer border (ccw order)
+   \param[out] 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,
@@ -1141,14 +1172,17 @@ void Vect_point_buffer2(double px, double py, double da, double db,
 
 
 /*
-   \fn void Vect_line_parallel2 ( struct line_pnts *InPoints, double distance, double tolerance, int rm_end,
-   struct line_pnts *OutPoints )
    \brief Create parrallel line
-   \param InPoints input line
-   \param distance
-   \param tolerance maximum distance between theoretical arc and polygon segments
-   \param rm_end remove end points falling into distance
-   \param OutPoints output line
+
+   See also Vect_line_parallel().
+   
+   \param InPoints input line geometry
+   \param da distance along major axis
+   \param da distance along minor axis
+   \param dalpha angle between 0x and major axis
+   \param round make corners round
+   \param tol maximum distance between theoretical arc and output segments
+   \param[out] OutPoints output line
  */
 void Vect_line_parallel2(struct line_pnts *InPoints, double da, double db,
 			 double dalpha, int side, int round, double tol,
@@ -1164,5 +1198,6 @@ void Vect_line_parallel2(struct line_pnts *InPoints, double da, double db,
     /*    if (!loops)
        clean_parallel(OutPoints, InPoints, distance, rm_end);
      */
+    
     return;
 }

vector/v.buffer2/dgraph.c → lib/vector/Vlib/dgraph.c


+ 2 - 2
vector/v.parallel2/dgraph.h

@@ -1,5 +1,5 @@
-#ifndef DGRAPH_H
-#define DGRAPH_H
+#ifndef GRASS_DGRAPH_H
+#define GRASS_DGRAPH_H
 
 /* pg comes from "planar graph" */
 /* every edge is directed. Nevertheless, we can visit it on both sides */

vector/v.buffer2/e_intersect.c → lib/vector/Vlib/e_intersect.c


+ 2 - 2
vector/v.parallel2/e_intersect.h

@@ -1,5 +1,5 @@
-#ifndef E_INTERSECT_H
-#define E_INTERSECT_H
+#ifndef GRASS_E_INTERSECT_H
+#define GRASS_E_INTERSECT_H
 
 #define FZERO(X, TOL) (fabs(X)<TOL)
 #define FEQUAL(X, Y, TOL) (fabs(X-Y)<TOL)

+ 0 - 38
vector/v.buffer2/dgraph.h

@@ -1,38 +0,0 @@
-#ifndef DGRAPH_H
-#define DGRAPH_H
-
-/* pg comes from "planar graph" */
-/* every edge is directed. Nevertheless, we can visit it on both sides */
-struct pg_edge {
-    int v1; /* first vertex */
-    int v2; /* second vertex */
-    char visited_left;
-    char visited_right;
-    char winding_left; /* winding numbers */
-    char winding_right;
-};
-
-struct pg_vertex {
-    double x; /* coordinates */
-    double y;
-    int ecount; /* number of neighbours */
-    int eallocated; /* size of the array bellow */
-    struct pg_edge **edges; /* array of pointers */
-    double *angles; /* precalculated angles with Ox */
-};
-
-struct planar_graph {
-    int vcount; /* number of vertices */
-    struct pg_vertex *v;
-    int ecount;
-    int eallocated;
-    struct pg_edge *e;
-};
-
-struct planar_graph* pg_create_struct(int n, int e);
-void pg_destroy_struct(struct planar_graph *pg);
-int pg_existsedge(struct planar_graph *pg, int v1, int v2);
-void pg_addedge(struct planar_graph *pg, int v1, int v2);
-struct planar_graph* pg_create(struct line_pnts *Points);
-
-#endif

+ 0 - 21
vector/v.buffer2/e_intersect.h

@@ -1,21 +0,0 @@
-#ifndef E_INTERSECT_H
-#define E_INTERSECT_H
-
-#define FZERO(X, TOL) (fabs(X)<TOL)
-#define FEQUAL(X, Y, TOL) (fabs(X-Y)<TOL)
-
-/*int segment_intersection_2d_e(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, double by2,
-    double *x1, double *y1, double *x2, double *y2);
-int segment_intersection_2d_test(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, double by2,
-    double *x1, double *y1, double *x2, double *y2);*/
-
-int segment_intersection_2d_tol(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, double by2,
-    double *x1, double *y1, double *x2, double *y2, double tol);
-
-int segment_intersection_2d(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, double by2,
-    double *x1, double *y1, double *x2, double *y2);
-
-    
-int almost_equal(double a, double b, int bits);
-
-#endif

+ 0 - 521
vector/v.parallel2/dgraph.c

@@ -1,521 +0,0 @@
-#include <stdlib.h>
-#include <grass/Vect.h>
-#include <grass/gis.h>
-#include "dgraph.h"
-#include "e_intersect.h"
-
-#define LENGTH(DX, DY) (sqrt((DX*DX)+(DY*DY)))
-#ifndef MIN
-#define MIN(X,Y) ((X<Y)?X:Y)
-#endif
-#ifndef MAX
-#define MAX(X,Y) ((X>Y)?X:Y)
-#endif
-#define PI M_PI
-
-struct intersection_point
-{
-    double x;
-    double y;
-    int group;			/* IPs with very similar dist will be in the same group */
-};
-
-struct seg_intersection
-{
-    int with;			/* second segment */
-    int ip;			/* index of the IP */
-    double dist;		/* distance from first point of first segment to intersection point (IP) */
-};
-
-struct seg_intersection_list
-{
-    int count;
-    int allocated;
-    struct seg_intersection *a;
-};
-
-struct seg_intersections
-{
-    int ipcount;
-    int ipallocated;
-    struct intersection_point *ip;
-    int ilcount;
-    struct seg_intersection_list *il;
-    int group_count;
-};
-
-struct seg_intersections *create_si_struct(int segments_count)
-{
-    struct seg_intersections *si;
-
-    int i;
-
-    si = G_malloc(sizeof(struct seg_intersections));
-    si->ipcount = 0;
-    si->ipallocated = segments_count + 16;
-    si->ip = G_malloc((si->ipallocated) * sizeof(struct intersection_point));
-    si->ilcount = segments_count;
-    si->il = G_malloc(segments_count * sizeof(struct seg_intersection_list));
-    for (i = 0; i < segments_count; i++) {
-	si->il[i].count = 0;
-	si->il[i].allocated = 0;
-	si->il[i].a = NULL;
-    }
-
-    return si;
-}
-
-void destroy_si_struct(struct seg_intersections *si)
-{
-    int i;
-
-    for (i = 0; i < si->ilcount; i++)
-	G_free(si->il[i].a);
-    G_free(si->il);
-    G_free(si->ip);
-    G_free(si);
-
-    return;
-}
-
-/* internal use */
-void add_ipoint1(struct seg_intersection_list *il, int with, double dist,
-		 int ip)
-{
-    struct seg_intersection *s;
-
-    if (il->count == il->allocated) {
-	il->allocated += 4;
-	il->a =
-	    G_realloc(il->a,
-		      (il->allocated) * sizeof(struct seg_intersection));
-    }
-    s = &(il->a[il->count]);
-    s->with = with;
-    s->ip = ip;
-    s->dist = dist;
-    il->count++;
-
-    return;
-}
-
-/* adds intersection point to the structure */
-void add_ipoint(struct line_pnts *Points, int first_seg, int second_seg,
-		double x, double y, struct seg_intersections *si)
-{
-    struct intersection_point *t;
-
-    int ip;
-
-    G_debug(4, "add_ipoint()");
-
-    if (si->ipcount == si->ipallocated) {
-	si->ipallocated += 16;
-	si->ip =
-	    G_realloc(si->ip,
-		      (si->ipallocated) * sizeof(struct intersection_point));
-    }
-    ip = si->ipcount;
-    t = &(si->ip[ip]);
-    t->x = x;
-    t->y = y;
-    t->group = -1;
-    si->ipcount++;
-
-    add_ipoint1(&(si->il[first_seg]), second_seg,
-		LENGTH((Points->x[first_seg] - x),
-		       (Points->y[first_seg] - y)), ip);
-    if (second_seg >= 0)
-	add_ipoint1(&(si->il[second_seg]), first_seg,
-		    LENGTH((Points->x[second_seg] - x),
-			   (Points->y[second_seg] - y)), ip);
-}
-
-void sort_intersection_list(struct seg_intersection_list *il)
-{
-    int n, i, j, min;
-
-    struct seg_intersection t;
-
-    G_debug(4, "sort_intersection_list()");
-
-    n = il->count;
-    G_debug(4, "    n=%d", n);
-    for (i = 0; i < n - 1; i++) {
-	min = i;
-	for (j = i + 1; j < n; j++) {
-	    if (il->a[j].dist < il->a[min].dist) {
-		min = j;
-	    }
-	}
-	if (min != i) {
-	    t = il->a[i];
-	    il->a[i] = il->a[min];
-	    il->a[min] = t;
-	}
-    }
-
-    return;
-}
-
-static int compare(const void *a, const void *b)
-{
-    struct intersection_point *aa, *bb;
-
-    aa = *((struct intersection_point **)a);
-    bb = *((struct intersection_point **)b);
-
-    if (aa->x < bb->x)
-	return -1;
-    else if (aa->x > bb->x)
-	return 1;
-    else
-	return (aa->y < bb->y) ? -1 : ((aa->y > bb->y) ? 1 : 0);
-}
-
-/* O(Points->n_points) time */
-double get_epsilon(struct line_pnts *Points)
-{
-    int i, np;
-
-    double min, t;
-
-    double *x, *y;
-
-    np = Points->n_points;
-    x = Points->x;
-    y = Points->y;
-
-    min = MAX(fabs(x[1] - x[0]), fabs(y[1] - y[0]));
-    for (i = 1; i <= np - 2; i++) {
-	t = MAX(fabs(x[i + 1] - x[i]), fabs(y[i + 1] - y[i]));
-	if ((t > 0) && (t < min)) {
-	    min = t;
-	}
-    }
-
-    /* ??? is 0.001 ok ??? */
-    return min * 0.000001;
-}
-
-/* currently O(n*n); future implementation O(nlogn) */
-struct seg_intersections *find_all_intersections(struct line_pnts *Points)
-{
-    int i, j, np;
-
-    int group, t;
-
-    int looped;
-
-    double EPSILON = 0.00000001;
-
-    double *x, *y;
-
-    double x1, y1, x2, y2;
-
-    int res;
-
-    /*int res2
-       double x1_, y1_, x2_, y2_, z1_, z2_; */
-    struct seg_intersections *si;
-
-    struct seg_intersection_list *il;
-
-    struct intersection_point **sorted;
-
-    G_debug(3, "find_all_intersections()");
-
-    np = Points->n_points;
-    x = Points->x;
-    y = Points->y;
-
-    si = create_si_struct(np - 1);
-
-    looped = ((x[0] == x[np - 1]) && (y[0] == y[np - 1]));
-    G_debug(3, "    looped=%d", looped);
-
-    G_debug(3, "    finding intersections...");
-    for (i = 0; i < np - 1; i++) {
-	for (j = i + 1; j < np - 1; j++) {
-	    G_debug(4, "        checking %d-%d %d-%d", i, i + 1, j, j + 1);
-	    /*res = segment_intersection_2d_e(x[i], y[i], x[i+1], y[i+1], x[j], y[j], x[j+1], y[j+1], &x1, &y1, &x2, &y2); */
-	    res =
-		segment_intersection_2d(x[i], y[i], x[i + 1], y[i + 1], x[j],
-					y[j], x[j + 1], y[j + 1], &x1, &y1,
-					&x2, &y2);
-	    /*            res2 = segment_intersection_2d_e(x[i], y[i], x[i+1], y[i+1], x[j], y[j], x[j+1], y[j+1], &x1_, &y1_, &x2_, &y2_);
-	       if ((res != res2) || ((res != 0) && (x1!=x1_ || y1!=y1_)) ) {
-	       G_debug(0, "exact=%d orig=%d", res, res2);
-	       segment_intersection_2d_test(x[i], y[i], x[i+1], y[i+1], x[j], y[j], x[j+1], y[j+1], &x1, &y1, &x2, &y2);
-	       }
-	     */
-	    G_debug(4, "        intersection type = %d", res);
-	    if (res == 1) {
-		add_ipoint(Points, i, j, x1, y1, si);
-	    }
-	    else if ((res >= 2) && (res <= 5)) {
-		add_ipoint(Points, i, j, x1, y1, si);
-		add_ipoint(Points, i, j, x2, y2, si);
-	    }
-	}
-    }
-    if (!looped) {
-	/* these are not really intersection points */
-	add_ipoint(Points, 0, -1, Points->x[0], Points->y[0], si);
-	add_ipoint(Points, np - 2, -1, Points->x[np - 1], Points->y[np - 1],
-		   si);
-    }
-    G_debug(3, "    finding intersections...done");
-
-    G_debug(3, "    postprocessing...");
-    if (si->ipallocated > si->ipcount) {
-	si->ipallocated = si->ipcount;
-	si->ip =
-	    G_realloc(si->ip,
-		      (si->ipcount) * sizeof(struct intersection_point));
-    }
-    for (i = 0; i < si->ilcount; i++) {
-	il = &(si->il[i]);
-	if (il->allocated > il->count) {
-	    il->allocated = il->count;
-	    il->a =
-		G_realloc(il->a,
-			  (il->count) * sizeof(struct seg_intersection));
-	}
-
-	if (il->count > 0) {
-	    sort_intersection_list(il);
-	    /* is it ok to use qsort here ? */
-	}
-    }
-
-    /* si->ip will not be reallocated any more so we can use pointers */
-    sorted = G_malloc((si->ipcount) * sizeof(struct intersection_point *));
-    for (i = 0; i < si->ipcount; i++)
-	sorted[i] = &(si->ip[i]);
-
-    qsort(sorted, si->ipcount, sizeof(struct intersection_point *), compare);
-
-    /* assign groups */
-    group = 0;			/* next available group number */
-    for (i = 0; i < si->ipcount; i++) {
-
-	t = group;
-	for (j = i - 1; j >= 0; j--) {
-	    if (!FEQUAL(sorted[j]->x, sorted[i]->x, EPSILON))
-		/*            if (!almost_equal(sorted[j]->x, sorted[i]->x, 16)) */
-		break;
-	    if (FEQUAL(sorted[j]->y, sorted[i]->y, EPSILON)) {
-		/*            if (almost_equal(sorted[j]->y, sorted[i]->y, 16)) { */
-		t = sorted[j]->group;
-		break;
-	    }
-	}
-	G_debug(4, "        group=%d, ip=%d", t,
-		(int)(sorted[i] - &(si->ip[0])));
-	sorted[i]->group = t;
-	if (t == group)
-	    group++;
-    }
-    si->group_count = group;
-
-    G_debug(3, "    postprocessing...done");
-
-    /* output contents of si */
-    for (i = 0; i < si->ilcount; i++) {
-	G_debug(4, "%d-%d :", i, i + 1);
-	for (j = 0; j < si->il[i].count; j++) {
-	    G_debug(4, "     %d-%d, group=%d", si->il[i].a[j].with,
-		    si->il[i].a[j].with + 1, si->ip[si->il[i].a[j].ip].group);
-	    G_debug(4, "            dist=%.18f", si->il[i].a[j].dist);
-	    G_debug(4, "            x=%.18f, y=%.18f",
-		    si->ip[si->il[i].a[j].ip].x, si->ip[si->il[i].a[j].ip].y);
-	}
-    }
-
-    return si;
-}
-
-/* create's graph with n vertices and allocates memory for e edges */
-/* trying to add more than e edges, produces fatal error */
-struct planar_graph *pg_create_struct(int n, int e)
-{
-    struct planar_graph *pg;
-
-    pg = G_malloc(sizeof(struct planar_graph));
-    pg->vcount = n;
-    pg->v = G_malloc(n * sizeof(struct pg_vertex));
-    memset(pg->v, 0, n * sizeof(struct pg_vertex));
-    pg->ecount = 0;
-    pg->eallocated = MAX(e, 0);
-    pg->e = NULL;
-    pg->e = G_malloc(e * sizeof(struct pg_edge));
-
-    return pg;
-}
-
-void pg_destroy_struct(struct planar_graph *pg)
-{
-    int i;
-
-    for (i = 0; i < pg->vcount; i++) {
-	G_free(pg->v[i].edges);
-	G_free(pg->v[i].angles);
-    }
-    G_free(pg->v);
-    G_free(pg->e);
-    G_free(pg);
-}
-
-/* v1 and v2 must be valid */
-int pg_existsedge(struct planar_graph *pg, int v1, int v2)
-{
-    struct pg_vertex *v;
-
-    struct pg_edge *e;
-
-    int i, ecount;
-
-    if (pg->v[v1].ecount <= pg->v[v2].ecount)
-	v = &(pg->v[v1]);
-    else
-	v = &(pg->v[v2]);
-
-    ecount = v->ecount;
-    for (i = 0; i < ecount; i++) {
-	e = v->edges[i];
-	if (((e->v1 == v1) && (e->v2 == v2)) ||
-	    ((e->v1 == v2) && (e->v2 == v1)))
-	    return 1;
-    }
-
-    return 0;
-}
-
-/* for internal use */
-void pg_addedge1(struct pg_vertex *v, struct pg_edge *e)
-{
-    if (v->ecount == v->eallocated) {
-	v->eallocated += 4;
-	v->edges =
-	    G_realloc(v->edges, (v->eallocated) * sizeof(struct pg_edge *));
-    }
-    v->edges[v->ecount] = e;
-    v->ecount++;
-}
-
-void pg_addedge(struct planar_graph *pg, int v1, int v2)
-{
-    struct pg_edge *e;
-
-    G_debug(4, "pg_addedge(), v1=%d, v2=%d", v1, v2);
-
-    if ((v1 == v2) || (v1 < 0) || (v1 >= pg->vcount) || (v2 < 0) ||
-	(v2 >= pg->vcount)) {
-	G_fatal_error("    pg_addedge(), v1 and/or v2 is invalid");
-	return;
-    }
-
-    if (pg_existsedge(pg, v1, v2))
-	return;
-
-    if (pg->ecount == pg->eallocated) {
-	G_fatal_error
-	    ("Trying to add more edges to the planar_graph than the initial allocation size allows");
-    }
-    e = &(pg->e[pg->ecount]);
-    e->v1 = v1;
-    e->v2 = v2;
-    e->winding_left = 0;	/* winding is undefined if the corresponding side is not visited */
-    e->winding_right = 0;
-    e->visited_left = 0;
-    e->visited_right = 0;
-    pg->ecount++;
-    pg_addedge1(&(pg->v[v1]), e);
-    pg_addedge1(&(pg->v[v2]), e);
-
-    return;
-}
-
-struct planar_graph *pg_create(struct line_pnts *Points)
-{
-    struct seg_intersections *si;
-
-    struct planar_graph *pg;
-
-    struct intersection_point *ip;
-
-    struct pg_vertex *vert;
-
-    struct pg_edge *edge;
-
-    int i, j, t, v;
-
-    G_debug(3, "pg_create()");
-
-    si = find_all_intersections(Points);
-    pg = pg_create_struct(si->group_count, 2 * (si->ipcount));
-
-    /* set vertices info */
-    for (i = 0; i < si->ipcount; i++) {
-	ip = &(si->ip[i]);
-	t = ip->group;
-	pg->v[t].x = ip->x;
-	pg->v[t].y = ip->y;
-    }
-
-    /* add all edges */
-    for (i = 0; i < si->ilcount; i++) {
-	v = si->ip[si->il[i].a[0].ip].group;
-	for (j = 1; j < si->il[i].count; j++) {
-	    t = si->ip[si->il[i].a[j].ip].group;
-	    if (t != v) {
-		pg_addedge(pg, v, t);	/* edge direction is v ---> t */
-		v = t;
-	    }
-	}
-    }
-
-    /* precalculate angles with 0x */
-    for (i = 0; i < pg->vcount; i++) {
-	vert = &(pg->v[i]);
-	vert->angles = G_malloc((vert->ecount) * sizeof(double));
-	for (j = 0; j < vert->ecount; j++) {
-	    edge = vert->edges[j];
-	    t = (edge->v1 != i) ? (edge->v1) : (edge->v2);
-	    vert->angles[j] =
-		atan2(pg->v[t].y - vert->y, pg->v[t].x - vert->x);
-	}
-    }
-
-    destroy_si_struct(si);
-    /*
-       I'm not sure if shrinking of the allocated memory always preserves it's physical place.
-       That's why I don't want to do this:
-       if (pg->ecount < pg->eallocated) {
-       pg->eallocated = pg->ecount;
-       pg->e = G_realloc(pg->e, (pg->ecount)*sizeof(struct pg_edge));
-       }
-     */
-
-    /* very time consuming */
-    /*
-       for (i = 0; i < pg->vcount; i++) {
-       if (pg->v[i].ecount < pg->v[i].eallocated) {
-       pg->v[i].eallocated = pg->v[i].ecount;
-       pg->v[i].edges = G_realloc(pg->v[i].edges, (pg->v[i].ecount)*sizeof(struct pg_edges));
-       }
-       }
-     */
-
-    /* output pg */
-    for (i = 0; i < pg->vcount; i++) {
-	G_debug(4, "    vertex %d (%g, %g)", i, pg->v[i].x, pg->v[i].y);
-	for (j = 0; j < pg->v[i].ecount; j++) {
-	    G_debug(4, "        edge %d-%d", pg->v[i].edges[j]->v1,
-		    pg->v[i].edges[j]->v2);
-	}
-    }
-
-    return pg;
-}

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 1077
vector/v.parallel2/e_intersect.c


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 1167
vector/v.parallel2/vlib_buffer.c