607 |
|
SDgetTreCDist(const FVECT inVec, SDComponent *sdc) |
608 |
|
{ |
609 |
|
const SDTre *sdt; |
610 |
< |
double inCoord[2]; |
610 |
> |
double inCoord[2], quantum; |
611 |
|
int i; |
612 |
|
SDTreCDst *cd, *cdlast; |
613 |
|
/* check arguments */ |
614 |
|
if ((inVec == NULL) | (sdc == NULL) || |
615 |
|
(sdt = (SDTre *)sdc->dist) == NULL) |
616 |
|
return NULL; |
617 |
< |
if (sdt->st->ndim == 3) /* isotropic BSDF? */ |
617 |
> |
if (sdt->st->ndim == 3) { /* isotropic BSDF? */ |
618 |
|
inCoord[0] = .5 - .5*sqrt(inVec[0]*inVec[0] + inVec[1]*inVec[1]); |
619 |
< |
else if (sdt->st->ndim == 4) |
619 |
> |
} else if (sdt->st->ndim == 4) { |
620 |
|
SDdisk2square(inCoord, -inVec[0], -inVec[1]); |
621 |
< |
else |
621 |
> |
} else |
622 |
|
return NULL; /* should be internal error */ |
623 |
+ |
/* quantize to avoid f.p. errors */ |
624 |
+ |
quantum = SDsmallestLeaf(sdt->st); |
625 |
+ |
for (i = sdt->st->ndim - 2; i--; ) |
626 |
+ |
inCoord[i] = floor(inCoord[i]/quantum)*quantum + .5*quantum; |
627 |
|
cdlast = NULL; /* check for direction in cache list */ |
628 |
|
for (cd = (SDTreCDst *)sdc->cdList; cd != NULL; |
629 |
|
cdlast = cd, cd = cd->next) { |