00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <assert.h>
00019 #include <pathutil.h>
00020 #include <stdlib.h>
00021
00022 #ifdef DMALLOC
00023 #include "dmalloc.h"
00024 #endif
00025
00026 #define ALLOC(size,ptr,type) (ptr? (type*)realloc(ptr,(size)*sizeof(type)):(type*)malloc((size)*sizeof(type)))
00027
00028 Ppoly_t copypoly(Ppoly_t argpoly)
00029 {
00030 Ppoly_t rv;
00031 int i;
00032
00033 rv.pn = argpoly.pn;
00034 rv.ps = malloc(sizeof(Ppoint_t) * argpoly.pn);
00035 for (i = 0; i < argpoly.pn; i++)
00036 rv.ps[i] = argpoly.ps[i];
00037 return rv;
00038 }
00039
00040 void freepoly(Ppoly_t argpoly)
00041 {
00042 free(argpoly.ps);
00043 }
00044
00045 int Ppolybarriers(Ppoly_t ** polys, int npolys, Pedge_t ** barriers,
00046 int *n_barriers)
00047 {
00048 Ppoly_t pp;
00049 int i, j, k, n, b;
00050 Pedge_t *bar;
00051
00052 n = 0;
00053 for (i = 0; i < npolys; i++)
00054 n = n + polys[i]->pn;
00055
00056 bar = malloc(n * sizeof(Pedge_t));
00057
00058 b = 0;
00059 for (i = 0; i < npolys; i++) {
00060 pp = *polys[i];
00061 for (j = 0; j < pp.pn; j++) {
00062 k = j + 1;
00063 if (k >= pp.pn)
00064 k = 0;
00065 bar[b].a = pp.ps[j];
00066 bar[b].b = pp.ps[k];
00067 b++;
00068 }
00069 }
00070 assert(b == n);
00071 *barriers = bar;
00072 *n_barriers = n;
00073 return 1;
00074 }
00075
00076
00077
00078 void
00079 make_polyline(Ppolyline_t line, Ppolyline_t* sline)
00080 {
00081 static int isz = 0;
00082 static Ppoint_t* ispline = 0;
00083 int i, j;
00084 int npts = 4 + 3*(line.pn-2);
00085
00086 if (npts > isz) {
00087 ispline = ALLOC(npts, ispline, Ppoint_t);
00088 isz = npts;
00089 }
00090
00091 j = i = 0;
00092 ispline[j+1] = ispline[j] = line.ps[i];
00093 j += 2;
00094 i++;
00095 for (; i < line.pn-1; i++) {
00096 ispline[j+2] = ispline[j+1] = ispline[j] = line.ps[i];
00097 j += 3;
00098 }
00099 ispline[j+1] = ispline[j] = line.ps[i];
00100
00101 sline->pn = npts;
00102 sline->ps = ispline;
00103 }
00104