ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/raytrace.c
Revision: 2.46
Committed: Thu Mar 10 22:37:00 2005 UTC (19 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.45: +4 -1 lines
Log Message:
Made illum work properly with distant source objects

File Contents

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