[go: up one dir, main page]

File: Node_pair_link.c

package info (click to toggle)
circlepack 5.1-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, sarge
  • size: 2,828 kB
  • ctags: 1,683
  • sloc: ansic: 43,152; makefile: 46
file content (249 lines) | stat: -rw-r--r-- 6,645 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#include "cp_types.h"
#include "cp_proto.h"

/* read string of node pairs into linked list, endptr=NULL or 
pts to inappropriate char, if such is encountered or odd number 
of nodes is listed. hits=0 ==> no expressions parsed. */

struct Edgelist *Node_pair_link(struct p_data *p,char *dpoint,
				char **endptr,int *hits,
				 struct Vertlist **Vlist,
				 struct Edgelist **Elist,
				struct Vertlist **Flist,
				 Region *region,struct Pathlist *pathlist,
				 int pathlength)
{
  int count,nextvert,stopvert,v1,v2,i,j,k,v,hts;
  char next[256],next2[256],*nextptr,*lastptr;
  struct K_data *pK_ptr;
  struct Edgelist *edgelist=NULL,*trace,*clobber;
  struct Vertlist *vertlist=NULL,*facelist=NULL,*vtrace;

  pK_ptr=p->packK_ptr;
  stripsp(dpoint);
  nextptr=lastptr=dpoint;
  *endptr=NULL;
  count=*hits=0;
  if (*nextptr == '\0' || !grab_next(&nextptr,next) ) return NULL;
  edgelist=(struct Edgelist *)malloc(sizeof(struct Edgelist));
  edgelist->next=NULL;
  trace=edgelist;
  clobber=trace;
  do
    {
      lastptr += notspace(lastptr);
      if (next[0]=='a') /* do all edges */
	{
	  for (i=1;i<p->nodecount;i++) 
	    for (j=0;j<=pK_ptr[i].num;j++)
	      if ((k=pK_ptr[i].flower[j])>i)
		{
		  trace->v=i;trace->w=k;
		  trace->next=(struct Edgelist *)
		    calloc((size_t)1,sizeof(struct Edgelist));
		  clobber=trace;
		  trace=trace->next;
		  count++;
		}
	}
      else if (next[0]=='b') /* all boundary edges */
	{
	  lastptr++;
	  for (j=1;j<=p->num_bdry_comp;j++)
	    {
	      v1=stopvert=p->bdry_starts[j];
	      nextvert=pK_ptr[v1].flower[0];
	      trace->v=v1;trace->w=nextvert;
	      trace->next=(struct Edgelist *)
		calloc((size_t)1,sizeof(struct Edgelist));
	      clobber=trace;
	      trace=trace->next;
	      count++;
	      do
		{
		  v1=nextvert;
		  nextvert=pK_ptr[v1].flower[0];
		  trace->v=v1;trace->w=nextvert;
		  trace->next=(struct Edgelist *)
		    calloc((size_t)1,sizeof(struct Edgelist));
		  clobber=trace;
		  trace=trace->next;
		  count++;
		}
	      while (nextvert!=stopvert);
	    }
	}
      else if (strncmp(next+1,"list",4)==0) /* use elist */
	{
	  struct Edgelist *elptr=NULL,*ceptr=NULL;
	  if (((*next=='E' && (ceptr=*(Elist) )) 
	       || (*next=='e' && (ceptr=p->elist)))
	      && *(next+5)=='[')
	    {
	      if (*(next+6)=='r') /* rotate list */
		{
		  elptr=ceptr;
		  while (elptr && elptr->next) elptr=elptr->next;
		  elptr->next=(struct Edgelist *)
		    calloc((size_t)1,sizeof(struct Edgelist));
		  elptr->next->v=ceptr->v;
		  elptr->next->w=ceptr->w;
		}
	      if (*(next+6)=='n' || *(next+6)=='r')
		{
		  consume_one_edge(&ceptr,&v1,&v2);
		  if (*next=='E') (*Elist)=ceptr;
		  else p->elist=ceptr;
		}
	      else if (sscanf(next+5,"[%d]",&j) && j>=0)
		{
		  elptr=ceptr;
		  while (j-- > 1 && elptr->next)
		    elptr=elptr->next;
		  if (j==0 && elptr)
		    {
		      v1=elptr->v;
		      v2=elptr->w;
		    }
		  else v1=0;
		}
	      else v1=0;
	      if (v1>0 && v1<=p->nodecount 
		  && v2>0 && v2<=p->nodecount ) 
		{
		  trace->v=v1;trace->w=v2;
		  trace->next=(struct Edgelist *)
		    calloc((size_t)1,sizeof(struct Edgelist));
		  clobber=trace;
		  trace=trace->next;
		  count++;
		}	
	      elptr=(struct Edgelist *)NULL;
	    }
	  else if (*next=='E') elptr=(*Elist); /* adjoint Elist */
	  else if (*next=='e') elptr=p->elist; /* adjoint pack elist */
	  while (elptr && (v1=elptr->v)>0 && v1<=p->nodecount
		 && (v2=elptr->w)>0 && v2<=p->nodecount)
	    {
	      trace->v=v1;trace->w=v2;
	      trace->next=(struct Edgelist *)
		calloc((size_t)1,sizeof(struct Edgelist));
	      clobber=trace;
	      trace=trace->next;
	      elptr=elptr->next;
	      count++;
	    }
	}
 /* oriented, closed lists of edges bounding given faces: Caution: 
    assumes rest of data string specifies verts; resets nextptr. */      
      else if (next[0]=='f')
	{
	  lastptr++;
	  if ((facelist=Face_link_parse(p,lastptr,endptr,&hts,Vlist,
					Elist,Flist,region,pathlist,
					pathlength)))
	    {
	      nextptr=*endptr;
	      vtrace=facelist;
	      while(vtrace)
		{
		  for (j=0;j<3;j++)
		    {
		      v1=p->faces[vtrace->v].vert[j];
		      v2=p->faces[vtrace->v].vert[(j+1)%3];
		      trace->v=v1;trace->w=v2;
		      trace->next=(struct Edgelist *)
			calloc((size_t)1,sizeof(struct Edgelist));
		      clobber=trace;
		      trace=trace->next;
		      count++;
		    }
		  vtrace=vtrace->next;
		}
	      vert_free(&facelist);
	    }
	}

/* attempt to make edgelist from raw vert list (ie., not listed
   in pairs); little attempt to avoid duplication. Caution: assumes 
   rest of data string specifies verts;	resets nextptr. */      
      else if (next[0]=='e') 
	{
	  lastptr++;
	  if ((vertlist=Node_link_parse(p,lastptr,endptr,&hts,
					Vlist,Elist,Flist,
					region,pathlist,pathlength)))
	    {
	      nextptr=*endptr;
	      vtrace=vertlist;
	      while(vtrace && vtrace->next)
		{
		  v1=vtrace->v;
		  v2=vtrace->next->v;
		  if ((v1!=v2) && nghb(p,v1,v2)>=0)
		    {
		      trace->v=v1;trace->w=v2;
		      trace->next=(struct Edgelist *)
			calloc((size_t)1,sizeof(struct Edgelist));
		      clobber=trace;
		      trace=trace->next;
		      count++;
		    }
		  vtrace=vtrace->next;
		}
	      vert_free(&vertlist);
	    }
	}
      else if (next[0]=='m') /* all with both ends marked */
	{
	  lastptr++;
	  for (j=1;j<p->nodecount;j++)
	    if (pK_ptr[j].mark) 
	      for (k=0;k<=pK_ptr[j].num;k++)
		if (pK_ptr[(v=pK_ptr[j].flower[k])].mark
		    && v>j)
		  {
		    trace->v=j;trace->w=v;
		    trace->next=(struct Edgelist *)
		      calloc((size_t)1,sizeof(struct Edgelist));
		    clobber=trace;
		    trace=trace->next;
		    count++;
		  }
	}
      else if (sscanf(next,"%d",&v1)  
	       && v1>0 && v1<=p->nodecount
	       && grab_next(&nextptr,next2)
	       && sscanf(next2,"%d",&v2) 
	       && v2>0 && v2<=p->nodecount)
	/* removed restriction that they're nghbs: && nghb(p,v1,v2)!=-1) */
	/* just regular edge pair */
	{
	  trace->v=v1;trace->w=v2;
	  trace->next=(struct Edgelist *)
	    calloc((size_t)1,sizeof(struct Edgelist));
	  clobber=trace;
	  trace=trace->next;
	  count++;
	}
      else goto E_GETOUT;   /* inappropriate entry */

      stripsp(nextptr);
      lastptr=nextptr;
    }
  while (*nextptr!='-' && grab_next(&nextptr,next) );
  *endptr=nextptr;
 E_GETOUT: /* clean up and leave */
  *hits=count;
  if (trace!=clobber) 
    {
      clobber->next=NULL; /* clobber should be last valid data */
      free(trace);trace=NULL;
    }
  if (!count) /* no data; should have trace=clobber=vertlist */
    {
      free(trace);
      return NULL;
    } 
  return edgelist;
} /* Node_pair_link */