| 488 |
|
return SDEargument; |
| 489 |
|
/* get cumulative distribution */ |
| 490 |
|
VCOPY(inVec, ioVec); |
| 491 |
+ |
sv->cieY = 0; |
| 492 |
|
cd = (*sdc->func->getCDist)(inVec, sdc); |
| 493 |
< |
if (cd == NULL) |
| 494 |
< |
return SDEmemory; |
| 495 |
< |
if (cd->cTotal <= 1e-6) { /* anything to sample? */ |
| 493 |
> |
if (cd != NULL) |
| 494 |
> |
sv->cieY = cd->cTotal; |
| 495 |
> |
if (sv->cieY <= 1e-6) { /* nothing to sample? */ |
| 496 |
|
sv->spec = c_dfcolor; |
| 496 |
– |
sv->cieY = .0; |
| 497 |
|
memset(ioVec, 0, 3*sizeof(double)); |
| 498 |
|
return SDEnone; |
| 499 |
|
} |
| 500 |
– |
sv->cieY = cd->cTotal; |
| 500 |
|
/* compute sample direction */ |
| 501 |
|
ec = (*sdc->func->sampCDist)(ioVec, randX, cd); |
| 502 |
|
if (ec) |
| 558 |
|
SDmultiSamp(outVec, 2, randX); |
| 559 |
|
SDsquare2disk(outVec, outVec[0], outVec[1]); |
| 560 |
|
outVec[2] = 1. - outVec[0]*outVec[0] - outVec[1]*outVec[1]; |
| 561 |
< |
if (outVec[2] > 0) /* a bit of paranoia */ |
| 563 |
< |
outVec[2] = sqrt(outVec[2]); |
| 561 |
> |
outVec[2] = sqrt(outVec[2]*(outVec[2]>0)); |
| 562 |
|
if (!outFront) /* going out back? */ |
| 563 |
|
outVec[2] = -outVec[2]; |
| 564 |
|
} |
| 617 |
|
projSA[0] = M_PI; |
| 618 |
|
if (qflags == SDqueryMin+SDqueryMax) |
| 619 |
|
projSA[1] = M_PI; |
| 620 |
< |
} |
| 620 |
> |
} else if (qflags == SDqueryMin+SDqueryMax && projSA[0] > projSA[1]) |
| 621 |
> |
projSA[0] = projSA[1]; |
| 622 |
|
return SDEnone; |
| 623 |
|
} |
| 624 |
|
|
| 755 |
|
return SDEmemory; |
| 756 |
|
while (j-- > 0) { /* non-diffuse transmission */ |
| 757 |
|
cdarr[i+j] = (*tdf->comp[j].func->getCDist)(inVec, &tdf->comp[j]); |
| 758 |
< |
if (cdarr[i+j] == NULL) { |
| 759 |
< |
free(cdarr); |
| 761 |
< |
return SDEmemory; |
| 762 |
< |
} |
| 758 |
> |
if (cdarr[i+j] == NULL) |
| 759 |
> |
cdarr[i+j] = &SDemptyCD; |
| 760 |
|
sv->cieY += cdarr[i+j]->cTotal; |
| 761 |
|
} |
| 762 |
|
while (i-- > 0) { /* non-diffuse reflection */ |
| 763 |
|
cdarr[i] = (*rdf->comp[i].func->getCDist)(inVec, &rdf->comp[i]); |
| 764 |
< |
if (cdarr[i] == NULL) { |
| 765 |
< |
free(cdarr); |
| 769 |
< |
return SDEmemory; |
| 770 |
< |
} |
| 764 |
> |
if (cdarr[i] == NULL) |
| 765 |
> |
cdarr[i] = &SDemptyCD; |
| 766 |
|
sv->cieY += cdarr[i]->cTotal; |
| 767 |
|
} |
| 768 |
|
if (sv->cieY <= 1e-6) { /* anything to sample? */ |
| 788 |
|
randX -= sd->tLamb.cieY; |
| 789 |
|
} |
| 790 |
|
/* else one of cumulative dist. */ |
| 791 |
< |
for (i = 0; i < n && randX < cdarr[i]->cTotal; i++) |
| 791 |
> |
for (i = 0; i < n && randX > cdarr[i]->cTotal; i++) |
| 792 |
|
randX -= cdarr[i]->cTotal; |
| 793 |
|
if (i >= n) |
| 794 |
|
return SDEinternal; |