--- ray/src/common/bsdf.c 2010/09/07 23:10:50 2.7 +++ ray/src/common/bsdf.c 2011/01/03 19:27:00 2.9 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf.c,v 2.7 2010/09/07 23:10:50 greg Exp $"; +static const char RCSid[] = "$Id: bsdf.c,v 2.9 2011/01/03 19:27:00 greg Exp $"; #endif /* * Routines for handling BSDF data @@ -61,8 +61,16 @@ static ANGLE_BASIS abase_list[MAXABASES] = { static int nabases = 3; /* current number of defined bases */ -#define FEQ(a,b) ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7) +#define FEQ(a,b) ((a)-(b) <= 1e-6 && (b)-(a) <= 1e-6) +static int +fequal(double a, double b) +{ + if (b != .0) + a = a/b - 1.; + return((a <= 1e-6) & (a >= -1e-6)); +} + // returns the name of the given tag #ifdef ezxml_name #undef ezxml_name @@ -227,7 +235,7 @@ load_angle_basis( /* load custom BSDF angle basis */ if (!i) abase_list[nabases].lat[i].tmin = -abase_list[nabases].lat[i+1].tmin; - else if (!FEQ(atof(ezxml_txt(ezxml_child(ezxml_child(wbb, + else if (!fequal(atof(ezxml_txt(ezxml_child(ezxml_child(wbb, "ThetaBounds"), "LowerTheta"))), abase_list[nabases].lat[i].tmin)) error(WARNING, "theta values disagree in custom basis"); @@ -249,6 +257,7 @@ to_meters( /* return factor to convert given unit to if (!strcasecmp(unit, "Foot")) return(.3048); if (!strcasecmp(unit, "Inch")) return(.0254); if (!strcasecmp(unit, "Centimeter")) return(.01); + if (!strcasecmp(unit, "Millimeter")) return(.001); sprintf(errmsg, "unknown dimensional unit '%s'", unit); error(USER, errmsg); } @@ -445,7 +454,7 @@ check_bsdf_data( /* check that BSDF data is sane */ BSDF_value(dp,i,o) = .0f; } } - if (hemi_total > 1.02) { + if (hemi_total > 1.01) { sprintf(errmsg, "incoming BSDF direction %d passes %.1f%% of light", i, 100.*hemi_total); @@ -462,7 +471,7 @@ check_bsdf_data( /* check that BSDF data is sane */ for (i = dp->ninc; i--; ) hemi_total += BSDF_value(dp,i,o) * omega_iarr[i]; - if (hemi_total > 1.02) { + if (hemi_total > 1.01) { sprintf(errmsg, "outgoing BSDF direction %d collects %.1f%% of light", o, 100.*hemi_total); @@ -471,8 +480,8 @@ check_bsdf_data( /* check that BSDF data is sane */ full_total += hemi_total*omega_oarr[o]; } full_total /= PI; - if (full_total > 1.02) { - sprintf(errmsg, "BSDF transfers %.1f%% of light", + if (full_total > 1.00001) { + sprintf(errmsg, "BSDF transfers %.4f%% of light", 100.*full_total); error(WARNING, errmsg); }