ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/raytrace.c
Revision: 2.45
Committed: Tue Mar 30 16:13:01 2004 UTC (20 years, 1 month ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6, rad3R6P1
Changes since 2.44: +94 -74 lines
Log Message:
Continued ANSIfication. There are only bits and pieces left now.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 2.45 static const char RCSid[] = "$Id: raytrace.c,v 2.44 2003/12/31 01:50:02 greg Exp $";
3 greg 1.1 #endif
4     /*
5     * raytrace.c - routines for tracing and shading rays.
6     *
7 greg 2.34 * External symbols declared in ray.h
8     */
9    
10 greg 2.35 #include "copyright.h"
11 greg 1.1
12     #include "ray.h"
13 schorsch 2.45 #include "source.h"
14 greg 1.1 #include "otypes.h"
15 greg 1.15 #include "otspecial.h"
16    
17 greg 2.3 #define MAXCSET ((MAXSET+1)*2-1) /* maximum check set size */
18    
19 greg 2.6 unsigned long raynum = 0; /* next unique ray number */
20     unsigned long nrays = 0; /* number of calls to localhit */
21 greg 1.1
22 schorsch 2.40 static RREAL Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
23 greg 1.15 OBJREC Lamb = {
24     OVOID, MAT_PLASTIC, "Lambertian",
25 greg 2.2 {0, 5, NULL, Lambfa}, NULL,
26 greg 1.15 }; /* a Lambertian surface */
27    
28 greg 2.17 OBJREC Aftplane; /* aft clipping plane object */
29 greg 2.16
30 schorsch 2.45 #define RAYHIT (-1) /* return value for intercepted ray */
31 greg 2.5
32 schorsch 2.45 static int raymove(FVECT pos, OBJECT *cxs, int dirf, RAY *r, CUBE *cu);
33     static int checkhit(RAY *r, CUBE *cu, OBJECT *cxs);
34     static void checkset(OBJECT *os, OBJECT *cs);
35 greg 1.1
36    
37 schorsch 2.45 extern int
38     rayorigin( /* start new ray from old one */
39     register RAY *r,
40     register RAY *ro,
41     int rt,
42     double rw
43     )
44 greg 1.1 {
45 gwlarson 2.31 double re;
46    
47 greg 1.1 if ((r->parent = ro) == NULL) { /* primary ray */
48     r->rlvl = 0;
49     r->rweight = rw;
50     r->crtype = r->rtype = rt;
51     r->rsrc = -1;
52     r->clipset = NULL;
53 greg 1.21 r->revf = raytrace;
54 greg 2.23 copycolor(r->cext, cextinction);
55 greg 2.26 copycolor(r->albedo, salbedo);
56 greg 2.23 r->gecc = seccg;
57     r->slights = NULL;
58 greg 1.1 } else { /* spawned ray */
59     r->rlvl = ro->rlvl;
60     if (rt & RAYREFL) {
61     r->rlvl++;
62     r->rsrc = -1;
63     r->clipset = ro->clipset;
64 greg 2.22 r->rmax = 0.0;
65 greg 1.1 } else {
66     r->rsrc = ro->rsrc;
67     r->clipset = ro->newcset;
68 greg 2.22 r->rmax = ro->rmax <= FTINY ? 0.0 : ro->rmax - ro->rot;
69 greg 1.1 }
70 greg 1.21 r->revf = ro->revf;
71 greg 2.23 copycolor(r->cext, ro->cext);
72 greg 2.26 copycolor(r->albedo, ro->albedo);
73 greg 2.23 r->gecc = ro->gecc;
74     r->slights = ro->slights;
75 greg 1.1 r->crtype = ro->crtype | (r->rtype = rt);
76     VCOPY(r->rorg, ro->rop);
77 gwlarson 2.31 r->rweight = ro->rweight * rw;
78     /* estimate absorption */
79     re = colval(ro->cext,RED) < colval(ro->cext,GRN) ?
80     colval(ro->cext,RED) : colval(ro->cext,GRN);
81     if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU);
82     if (re > 0.)
83     r->rweight *= exp(-re*ro->rot);
84 greg 1.1 }
85 greg 1.22 rayclear(r);
86     return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
87     }
88    
89    
90 schorsch 2.45 extern void
91     rayclear( /* clear a ray for (re)evaluation */
92     register RAY *r
93     )
94 greg 1.22 {
95 greg 1.20 r->rno = raynum++;
96 greg 1.1 r->newcset = r->clipset;
97 greg 2.36 r->hitf = rayhit;
98 greg 2.28 r->robj = OVOID;
99 greg 2.17 r->ro = NULL;
100 greg 2.34 r->rox = NULL;
101 gregl 2.29 r->rt = r->rot = FHUGE;
102 greg 1.1 r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
103 greg 2.37 r->uv[0] = r->uv[1] = 0.0;
104 greg 1.1 setcolor(r->pcol, 1.0, 1.0, 1.0);
105     setcolor(r->rcol, 0.0, 0.0, 0.0);
106     }
107    
108    
109 schorsch 2.45 extern void
110     raytrace( /* trace a ray and compute its value */
111     RAY *r
112     )
113 greg 1.1 {
114 greg 1.15 if (localhit(r, &thescene))
115 greg 2.24 raycont(r); /* hit local surface, evaluate */
116 greg 2.16 else if (r->ro == &Aftplane) {
117 greg 2.23 r->ro = NULL; /* hit aft clipping plane */
118 greg 2.16 r->rot = FHUGE;
119     } else if (sourcehit(r))
120 greg 2.24 rayshade(r, r->ro->omod); /* distant source */
121 greg 1.1
122 greg 2.23 rayparticipate(r); /* for participating medium */
123    
124 greg 1.1 if (trace != NULL)
125     (*trace)(r); /* trace execution */
126     }
127    
128    
129 schorsch 2.45 extern void
130     raycont( /* check for clipped object and continue */
131     register RAY *r
132     )
133 greg 1.8 {
134 greg 2.7 if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) ||
135 greg 2.24 !rayshade(r, r->ro->omod))
136 greg 1.8 raytrans(r);
137     }
138    
139    
140 schorsch 2.45 extern void
141     raytrans( /* transmit ray as is */
142     register RAY *r
143     )
144 greg 1.1 {
145     RAY tr;
146    
147     if (rayorigin(&tr, r, TRANS, 1.0) == 0) {
148     VCOPY(tr.rdir, r->rdir);
149     rayvalue(&tr);
150     copycolor(r->rcol, tr.rcol);
151 greg 1.10 r->rt = r->rot + tr.rt;
152 greg 1.1 }
153     }
154    
155    
156 schorsch 2.45 extern int
157     rayshade( /* shade ray r with material mod */
158     register RAY *r,
159     int mod
160     )
161 greg 1.1 {
162 greg 2.9 int gotmat;
163 greg 1.1 register OBJREC *m;
164 greg 1.19 r->rt = r->rot; /* set effective ray length */
165 greg 2.9 for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) {
166 greg 1.1 m = objptr(mod);
167 greg 1.4 /****** unnecessary test since modifier() is always called
168 greg 1.1 if (!ismodifier(m->otype)) {
169     sprintf(errmsg, "illegal modifier \"%s\"", m->oname);
170     error(USER, errmsg);
171     }
172 greg 1.4 ******/
173 greg 1.16 /* hack for irradiance calculation */
174 greg 2.38 if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) &&
175 greg 2.43 m->otype != MAT_CLIP &&
176 greg 2.38 (ofun[m->otype].flags & (T_M|T_X))) {
177 greg 1.16 if (irr_ignore(m->otype)) {
178     raytrans(r);
179 greg 2.15 return(1);
180 greg 1.16 }
181 greg 1.18 if (!islight(m->otype))
182 greg 1.16 m = &Lamb;
183     }
184 greg 2.9 /* materials call raytexture */
185     gotmat = (*ofun[m->otype].funp)(m, r);
186 greg 1.1 }
187 greg 2.9 return(gotmat);
188 greg 2.23 }
189    
190    
191 schorsch 2.45 extern void
192     rayparticipate( /* compute ray medium participation */
193     register RAY *r
194     )
195 greg 2.23 {
196     COLOR ce, ca;
197     double re, ge, be;
198    
199     if (intens(r->cext) <= 1./FHUGE)
200     return; /* no medium */
201 greg 2.27 re = r->rot*colval(r->cext,RED);
202     ge = r->rot*colval(r->cext,GRN);
203     be = r->rot*colval(r->cext,BLU);
204 greg 2.26 if (r->crtype & SHADOW) { /* no scattering for sources */
205     re *= 1. - colval(r->albedo,RED);
206     ge *= 1. - colval(r->albedo,GRN);
207     be *= 1. - colval(r->albedo,BLU);
208     }
209     setcolor(ce, re<=0. ? 1. : re>92. ? 0. : exp(-re),
210     ge<=0. ? 1. : ge>92. ? 0. : exp(-ge),
211     be<=0. ? 1. : be>92. ? 0. : exp(-be));
212 greg 2.23 multcolor(r->rcol, ce); /* path absorption */
213 greg 2.26 if (r->crtype & SHADOW || intens(r->albedo) <= FTINY)
214 greg 2.23 return; /* no scattering */
215 greg 2.26 setcolor(ca,
216     colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)),
217     colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)),
218     colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU)));
219 greg 2.23 addcolor(r->rcol, ca); /* ambient in scattering */
220     srcscatter(r); /* source in scattering */
221 greg 1.1 }
222    
223    
224 schorsch 2.45 extern void
225     raytexture( /* get material modifiers */
226     RAY *r,
227     OBJECT mod
228     )
229 greg 1.1 {
230 gwlarson 2.33 register OBJREC *m;
231 greg 1.1 /* execute textures and patterns */
232     for ( ; mod != OVOID; mod = m->omod) {
233     m = objptr(mod);
234 greg 2.9 /****** unnecessary test since modifier() is always called
235     if (!ismodifier(m->otype)) {
236 greg 1.1 sprintf(errmsg, "illegal modifier \"%s\"", m->oname);
237     error(USER, errmsg);
238     }
239 greg 2.9 ******/
240 greg 2.20 if ((*ofun[m->otype].funp)(m, r)) {
241     sprintf(errmsg, "conflicting material \"%s\"",
242     m->oname);
243     objerror(r->ro, USER, errmsg);
244     }
245 greg 1.1 }
246     }
247    
248    
249 schorsch 2.45 extern int
250     raymixture( /* mix modifiers */
251     register RAY *r,
252     OBJECT fore,
253     OBJECT back,
254     double coef
255     )
256 greg 1.1 {
257 greg 2.9 RAY fr, br;
258     int foremat, backmat;
259 greg 1.1 register int i;
260 greg 2.24 /* bound coefficient */
261 greg 1.1 if (coef > 1.0)
262     coef = 1.0;
263     else if (coef < 0.0)
264     coef = 0.0;
265 greg 2.13 /* compute foreground and background */
266 greg 2.24 foremat = backmat = 0;
267 greg 2.9 /* foreground */
268 schorsch 2.41 fr = *r;
269 greg 2.24 if (coef > FTINY)
270 greg 2.9 foremat = rayshade(&fr, fore);
271     /* background */
272 schorsch 2.41 br = *r;
273 greg 2.24 if (coef < 1.0-FTINY)
274 greg 2.9 backmat = rayshade(&br, back);
275 greg 2.24 /* check for transparency */
276 schorsch 2.41 if (backmat ^ foremat) {
277 gwlarson 2.33 if (backmat && coef > FTINY)
278 greg 2.24 raytrans(&fr);
279 gwlarson 2.33 else if (foremat && coef < 1.0-FTINY)
280 greg 2.24 raytrans(&br);
281 schorsch 2.41 }
282 greg 2.12 /* mix perturbations */
283 greg 1.1 for (i = 0; i < 3; i++)
284 greg 2.12 r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i];
285     /* mix pattern colors */
286 greg 2.9 scalecolor(fr.pcol, coef);
287     scalecolor(br.pcol, 1.0-coef);
288 greg 2.12 copycolor(r->pcol, fr.pcol);
289     addcolor(r->pcol, br.pcol);
290 greg 2.24 /* return value tells if material */
291     if (!foremat & !backmat)
292     return(0);
293 greg 2.12 /* mix returned ray values */
294 greg 2.24 scalecolor(fr.rcol, coef);
295     scalecolor(br.rcol, 1.0-coef);
296     copycolor(r->rcol, fr.rcol);
297     addcolor(r->rcol, br.rcol);
298     r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt;
299     return(1);
300 greg 1.1 }
301    
302    
303 schorsch 2.45 extern double
304     raydist( /* compute (cumulative) ray distance */
305     register RAY *r,
306     register int flags
307     )
308 greg 2.21 {
309     double sum = 0.0;
310    
311     while (r != NULL && r->crtype&flags) {
312     sum += r->rot;
313     r = r->parent;
314     }
315     return(sum);
316     }
317    
318    
319 schorsch 2.45 extern double
320     raynormal( /* compute perturbed normal for ray */
321     FVECT norm,
322     register RAY *r
323     )
324 greg 1.1 {
325     double newdot;
326     register int i;
327    
328     /* The perturbation is added to the surface normal to obtain
329     * the new normal. If the new normal would affect the surface
330     * orientation wrt. the ray, a correction is made. The method is
331     * still fraught with problems since reflected rays and similar
332     * directions calculated from the surface normal may spawn rays behind
333     * the surface. The only solution is to curb textures at high
334 greg 1.9 * incidence (namely, keep DOT(rdir,pert) < Rdot).
335 greg 1.1 */
336    
337     for (i = 0; i < 3; i++)
338     norm[i] = r->ron[i] + r->pert[i];
339    
340     if (normalize(norm) == 0.0) {
341     objerror(r->ro, WARNING, "illegal normal perturbation");
342     VCOPY(norm, r->ron);
343     return(r->rod);
344     }
345     newdot = -DOT(norm, r->rdir);
346     if ((newdot > 0.0) != (r->rod > 0.0)) { /* fix orientation */
347     for (i = 0; i < 3; i++)
348     norm[i] += 2.0*newdot*r->rdir[i];
349     newdot = -newdot;
350     }
351     return(newdot);
352 greg 1.12 }
353    
354    
355 schorsch 2.45 extern void
356     newrayxf( /* get new tranformation matrix for ray */
357     RAY *r
358     )
359 greg 1.12 {
360     static struct xfn {
361     struct xfn *next;
362     FULLXF xf;
363     } xfseed = { &xfseed }, *xflast = &xfseed;
364     register struct xfn *xp;
365     register RAY *rp;
366    
367     /*
368     * Search for transform in circular list that
369     * has no associated ray in the tree.
370     */
371     xp = xflast;
372     for (rp = r->parent; rp != NULL; rp = rp->parent)
373     if (rp->rox == &xp->xf) { /* xp in use */
374     xp = xp->next; /* move to next */
375     if (xp == xflast) { /* need new one */
376 greg 2.34 xp = (struct xfn *)malloc(sizeof(struct xfn));
377 greg 1.12 if (xp == NULL)
378     error(SYSTEM,
379     "out of memory in newrayxf");
380     /* insert in list */
381     xp->next = xflast->next;
382     xflast->next = xp;
383     break; /* we're done */
384     }
385     rp = r; /* start check over */
386     }
387     /* got it */
388     r->rox = &xp->xf;
389     xflast = xp;
390 greg 1.1 }
391    
392    
393 schorsch 2.45 extern void
394     flipsurface( /* reverse surface orientation */
395     register RAY *r
396     )
397 greg 1.1 {
398     r->rod = -r->rod;
399     r->ron[0] = -r->ron[0];
400     r->ron[1] = -r->ron[1];
401     r->ron[2] = -r->ron[2];
402     r->pert[0] = -r->pert[0];
403     r->pert[1] = -r->pert[1];
404     r->pert[2] = -r->pert[2];
405     }
406    
407    
408 schorsch 2.45 extern void
409     rayhit( /* standard ray hit test */
410     OBJECT *oset,
411     RAY *r
412     )
413 greg 2.36 {
414     OBJREC *o;
415     int i;
416    
417     for (i = oset[0]; i > 0; i--) {
418     o = objptr(oset[i]);
419     if ((*ofun[o->otype].funp)(o, r))
420     r->robj = oset[i];
421     }
422     }
423    
424    
425 schorsch 2.45 extern int
426     localhit( /* check for hit in the octree */
427     register RAY *r,
428     register CUBE *scene
429     )
430 greg 1.1 {
431 greg 2.3 OBJECT cxset[MAXCSET+1]; /* set of checked objects */
432 greg 1.1 FVECT curpos; /* current cube position */
433 greg 1.11 int sflags; /* sign flags */
434 greg 1.1 double t, dt;
435     register int i;
436    
437 greg 1.21 nrays++; /* increment trace counter */
438 greg 1.11 sflags = 0;
439 greg 1.1 for (i = 0; i < 3; i++) {
440     curpos[i] = r->rorg[i];
441 greg 2.8 if (r->rdir[i] > 1e-7)
442 greg 1.11 sflags |= 1 << i;
443 greg 2.8 else if (r->rdir[i] < -1e-7)
444 greg 1.11 sflags |= 0x10 << i;
445 greg 1.1 }
446 greg 1.17 if (sflags == 0)
447     error(CONSISTENCY, "zero ray direction in localhit");
448 greg 2.17 /* start off assuming nothing hit */
449     if (r->rmax > FTINY) { /* except aft plane if one */
450     r->ro = &Aftplane;
451     r->rot = r->rmax;
452     for (i = 0; i < 3; i++)
453     r->rop[i] = r->rorg[i] + r->rot*r->rdir[i];
454     }
455     /* find global cube entrance point */
456 greg 1.1 t = 0.0;
457     if (!incube(scene, curpos)) {
458     /* find distance to entry */
459     for (i = 0; i < 3; i++) {
460     /* plane in our direction */
461 greg 1.11 if (sflags & 1<<i)
462 greg 1.1 dt = scene->cuorg[i];
463 greg 1.11 else if (sflags & 0x10<<i)
464 greg 1.1 dt = scene->cuorg[i] + scene->cusize;
465     else
466     continue;
467     /* distance to the plane */
468     dt = (dt - r->rorg[i])/r->rdir[i];
469     if (dt > t)
470     t = dt; /* farthest face is the one */
471     }
472     t += FTINY; /* fudge to get inside cube */
473 greg 2.17 if (t >= r->rot) /* clipped already */
474     return(0);
475 greg 1.1 /* advance position */
476     for (i = 0; i < 3; i++)
477     curpos[i] += r->rdir[i]*t;
478    
479     if (!incube(scene, curpos)) /* non-intersecting ray */
480     return(0);
481     }
482 greg 2.3 cxset[0] = 0;
483 greg 2.19 raymove(curpos, cxset, sflags, r, scene);
484 schorsch 2.42 return((r->ro != NULL) & (r->ro != &Aftplane));
485 greg 1.1 }
486    
487    
488     static int
489 schorsch 2.45 raymove( /* check for hit as we move */
490     FVECT pos, /* current position, modified herein */
491     OBJECT *cxs, /* checked objects, modified by checkhit */
492     int dirf, /* direction indicators to speed tests */
493     register RAY *r,
494     register CUBE *cu
495     )
496 greg 1.1 {
497     int ax;
498     double dt, t;
499    
500     if (istree(cu->cutree)) { /* recurse on subcubes */
501     CUBE cukid;
502 greg 1.11 register int br, sgn;
503 greg 1.1
504     cukid.cusize = cu->cusize * 0.5; /* find subcube */
505     VCOPY(cukid.cuorg, cu->cuorg);
506     br = 0;
507     if (pos[0] >= cukid.cuorg[0]+cukid.cusize) {
508     cukid.cuorg[0] += cukid.cusize;
509     br |= 1;
510     }
511     if (pos[1] >= cukid.cuorg[1]+cukid.cusize) {
512     cukid.cuorg[1] += cukid.cusize;
513     br |= 2;
514     }
515     if (pos[2] >= cukid.cuorg[2]+cukid.cusize) {
516     cukid.cuorg[2] += cukid.cusize;
517     br |= 4;
518     }
519     for ( ; ; ) {
520     cukid.cutree = octkid(cu->cutree, br);
521 greg 2.3 if ((ax = raymove(pos,cxs,dirf,r,&cukid)) == RAYHIT)
522 greg 1.1 return(RAYHIT);
523     sgn = 1 << ax;
524 greg 1.11 if (sgn & dirf) /* positive axis? */
525 greg 1.1 if (sgn & br)
526     return(ax); /* overflow */
527     else {
528     cukid.cuorg[ax] += cukid.cusize;
529     br |= sgn;
530     }
531 greg 1.11 else
532     if (sgn & br) {
533     cukid.cuorg[ax] -= cukid.cusize;
534     br &= ~sgn;
535     } else
536     return(ax); /* underflow */
537 greg 1.1 }
538     /*NOTREACHED*/
539     }
540 greg 2.18 if (isfull(cu->cutree)) {
541     if (checkhit(r, cu, cxs))
542     return(RAYHIT);
543     } else if (r->ro == &Aftplane && incube(cu, r->rop))
544 greg 1.1 return(RAYHIT);
545     /* advance to next cube */
546 greg 1.11 if (dirf&0x11) {
547     dt = dirf&1 ? cu->cuorg[0] + cu->cusize : cu->cuorg[0];
548 greg 1.1 t = (dt - pos[0])/r->rdir[0];
549     ax = 0;
550     } else
551     t = FHUGE;
552 greg 1.11 if (dirf&0x22) {
553     dt = dirf&2 ? cu->cuorg[1] + cu->cusize : cu->cuorg[1];
554 greg 1.1 dt = (dt - pos[1])/r->rdir[1];
555     if (dt < t) {
556     t = dt;
557     ax = 1;
558     }
559     }
560 greg 1.11 if (dirf&0x44) {
561     dt = dirf&4 ? cu->cuorg[2] + cu->cusize : cu->cuorg[2];
562 greg 1.1 dt = (dt - pos[2])/r->rdir[2];
563     if (dt < t) {
564     t = dt;
565     ax = 2;
566     }
567     }
568     pos[0] += r->rdir[0]*t;
569     pos[1] += r->rdir[1]*t;
570     pos[2] += r->rdir[2]*t;
571     return(ax);
572     }
573    
574    
575 greg 2.34 static int
576 schorsch 2.45 checkhit( /* check for hit in full cube */
577     register RAY *r,
578     CUBE *cu,
579     OBJECT *cxs
580     )
581 greg 1.1 {
582     OBJECT oset[MAXSET+1];
583    
584     objset(oset, cu->cutree);
585 greg 2.36 checkset(oset, cxs); /* avoid double-checking */
586    
587     (*r->hitf)(oset, r); /* test for hit in set */
588    
589     if (r->robj == OVOID)
590 greg 1.1 return(0); /* no scores yet */
591    
592     return(incube(cu, r->rop)); /* hit OK if in current cube */
593 greg 2.2 }
594    
595    
596 greg 2.34 static void
597 schorsch 2.45 checkset( /* modify checked set and set to check */
598     register OBJECT *os, /* os' = os - cs */
599     register OBJECT *cs /* cs' = cs + os */
600     )
601 greg 2.2 {
602     OBJECT cset[MAXCSET+MAXSET+1];
603 greg 2.3 register int i, j;
604     int k;
605 greg 2.2 /* copy os in place, cset <- cs */
606     cset[0] = 0;
607     k = 0;
608     for (i = j = 1; i <= os[0]; i++) {
609     while (j <= cs[0] && cs[j] < os[i])
610     cset[++cset[0]] = cs[j++];
611     if (j > cs[0] || os[i] != cs[j]) { /* object to check */
612     os[++k] = os[i];
613     cset[++cset[0]] = os[i];
614     }
615     }
616 greg 2.3 if (!(os[0] = k)) /* new "to check" set size */
617     return; /* special case */
618 greg 2.2 while (j <= cs[0]) /* get the rest of cs */
619     cset[++cset[0]] = cs[j++];
620 greg 2.3 if (cset[0] > MAXCSET) /* truncate "checked" set if nec. */
621 greg 2.2 cset[0] = MAXCSET;
622 greg 2.3 /* setcopy(cs, cset); */ /* copy cset back to cs */
623     os = cset;
624     for (i = os[0]; i-- >= 0; )
625     *cs++ = *os++;
626 greg 1.1 }