--- ray/src/gen/mksource.c 2011/08/10 22:28:45 2.6 +++ ray/src/gen/mksource.c 2023/02/06 22:40:21 2.10 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: mksource.c,v 2.6 2011/08/10 22:28:45 greg Exp $"; +static const char RCSid[] = "$Id: mksource.c,v 2.10 2023/02/06 22:40:21 greg Exp $"; #endif /* * Generate distant sources corresponding to the given environment map @@ -246,7 +246,7 @@ get_threshold(const TRITREE *tree) long exphisto[256]; int i; /* compute sample histogram */ - memset((void *)exphisto, 0, sizeof(exphisto)); + memset(exphisto, 0, sizeof(exphisto)); for (i = 0; i < NTRUNKBR; i++) get_ehisto(&tree->kid[i], exphisto); /* use 98th percentile */ @@ -355,7 +355,7 @@ claimlight(COLOR intens, TRITREE *node, FVECT cent, do if (remaining) return; /* consolidate empties */ - free((void *)node->kid); node->kid = NULL; + free(node->kid); node->kid = NULL; copycolr(node->val, blkclr); node->sd = node->gdv[0]; /* doesn't really matter */ } @@ -387,7 +387,7 @@ getlost(LOSTLIGHT **llp, COLOR intens, FVECT cent, dou if (fdir2diff(thisp->sd,cent) <= maxr2) { LOSTLIGHT *mynext = thisp->next; addcolor(intens, thisp->intens); - free((void *)thisp); + free(thisp); lastp->next = mynext; } else lastp = thisp; @@ -398,9 +398,11 @@ getlost(LOSTLIGHT **llp, COLOR intens, FVECT cent, dou void mksources(TRITREE *samptree, double thresh, double maxang) { +#define MAXITER 100 const int ethresh = (int)(log(thresh)/log(2.) + (COLXS+.5)); const double maxomega = 2.*PI*(1. - cos(PI/180./2.*maxang)); const double minintens = .05*thresh*maxomega; + int niter = MAXITER; int nsrcs = 0; LOSTLIGHT *lostlightlist = NULL; int emax; @@ -426,7 +428,7 @@ mksources(TRITREE *samptree, double thresh, double max */ if (thresh <= FTINY) return; - for ( ; ; ) { + while (niter--) { emax = ethresh; /* find brightest unclaimed */ startleaf = NULL; for (i = 0; i < NTRUNKBR; i++) { @@ -457,7 +459,7 @@ mksources(TRITREE *samptree, double thresh, double max thisethresh); if (normalize(vsum) == .0) break; - movedist = acos(DOT(vsum,curcent)); + movedist = Acos(DOT(vsum,curcent)); if (movedist > growstep) { VSUB(vsum, vsum, curcent); movedist = growstep/VLEN(vsum); @@ -489,7 +491,9 @@ mksources(TRITREE *samptree, double thresh, double max printf("0\n0\n4 %f %f %f %f\n", curcent[0], curcent[1], curcent[2], 2.*180./PI*currad); + niter = MAXITER; } +#undef MAXITER } int @@ -554,7 +558,7 @@ userr: } void -eputs(char *s) +eputs(const char *s) { static int midline = 0; @@ -572,7 +576,7 @@ eputs(char *s) } void -wputs(char *s) +wputs(const char *s) { /* no warnings */ }