ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/raytrace.c
Revision: 2.33
Committed: Tue Sep 15 09:52:39 1998 UTC (25 years, 7 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 2.32: +17 -5 lines
Log Message:
eliminated unecessary modifier loop checking (I hope!)

File Contents

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