ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/raytrace.c
Revision: 2.48
Committed: Fri Apr 15 04:44:51 2005 UTC (19 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.47: +2 -4 lines
Log Message:
Eliminated revf member from RAY struct, as it was never really needed

File Contents

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