[brlcad-commits] SF.net SVN: brlcad:[54851] brlcad/trunk
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <br...@us...> - 2013-03-23 04:01:35
|
Revision: 54851 http://brlcad.svn.sourceforge.net/brlcad/?rev=54851&view=rev Author: brlcad Date: 2013-03-23 04:01:26 +0000 (Sat, 23 Mar 2013) Log Message: ----------- restore the increased M_SQRT3 precision change that carl had made to the polynomial root solver, which broke the solids regression test. walking the math through the debugger showed that a slightly different root was being returned causing a ray to intersect the massively distorted eto in the solids regression at enough of a delta to cause different light computations. this resulted in a single pixel off-by-many, which we also update in the reference image so that it reflects the new more accurate answer. while we're at it, increase the precision of 1/3 and 1/27th by computing them during static init. Modified Paths: -------------- brlcad/trunk/regress/solidspix.asc brlcad/trunk/src/libbn/poly.c Modified: brlcad/trunk/regress/solidspix.asc =================================================================== --- brlcad/trunk/regress/solidspix.asc 2013-03-22 23:05:24 UTC (rev 54850) +++ brlcad/trunk/regress/solidspix.asc 2013-03-23 04:01:26 UTC (rev 54851) @@ -96067,7 +96067,7 @@ 1D1D2F 212136 25253C -191928 +292943 2C2C49 30304F 333354 Modified: brlcad/trunk/src/libbn/poly.c =================================================================== --- brlcad/trunk/src/libbn/poly.c 2013-03-22 23:05:24 UTC (rev 54850) +++ brlcad/trunk/src/libbn/poly.c 2013-03-23 04:01:26 UTC (rev 54851) @@ -37,14 +37,11 @@ #include "bn.h" -#define Max(a, b) ((a) > (b) ? (a) : (b)) +#define CUBEROOT(a) (((a) > 0.0) ? pow(a, THIRD) : -pow(-(a), THIRD)) -#define PI_DIV_3 (M_PI/3.0) -#define SQRT3 1.732050808 -#define THIRD 0.333333333333333333333333333 -#define INV_TWENTYSEVEN 0.037037037037037037037037037 -#define CUBEROOT(a) (((a) >= 0.0) ? pow(a, THIRD) : -pow(-(a), THIRD)) +static const fastf_t THIRD = 1.0 / 3.0; +static const fastf_t TWENTYSEVENTH = 1.0 / 27.0; static const struct bn_poly bn_Zero_poly = { BN_POLY_MAGIC, 0, {0.0} }; static int bn_expecting_fpe = 0; @@ -301,11 +298,11 @@ c1_3rd = c1 * THIRD; a = eqn->cf[2] - c1*c1_3rd; if (abs(a) > SQRT_MAX_FASTF) return 0; /* FAIL */ - b = (2.0*c1*c1*c1 - 9.0*c1*eqn->cf[2] + 27.0*eqn->cf[3])*INV_TWENTYSEVEN; + b = (2.0*c1*c1*c1 - 9.0*c1*eqn->cf[2] + 27.0*eqn->cf[3])*TWENTYSEVENTH; if (abs(b) > SQRT_MAX_FASTF) return 0; /* FAIL */ if ((delta = a*a) > SQRT_MAX_FASTF) return 0; /* FAIL */ - delta = b*b*0.25 + delta*a*INV_TWENTYSEVEN; + delta = b*b*0.25 + delta*a*TWENTYSEVENTH; if (delta > 0.0) { fastf_t r_delta, A, B; @@ -321,7 +318,7 @@ roots[2].re = roots[1].re = -0.5 * (roots[0].re = A + B); roots[0].im = 0.0; - roots[2].im = -(roots[1].im = (A - B)*SQRT3*0.5); + roots[2].im = -(roots[1].im = (A - B)*M_SQRT3*0.5); } else if (ZERO(delta)) { fastf_t b_2; b_2 = -0.5 * b; @@ -336,22 +333,22 @@ if (a >= 0.0) { fact = 0.0; cs_phi = 1.0; /* cos(phi); */ - sn_phi_s3 = 0.0; /* sin(phi) * SQRT3; */ + sn_phi_s3 = 0.0; /* sin(phi) * M_SQRT3; */ } else { register fastf_t f; a *= -THIRD; fact = sqrt(a); if ((f = b * (-0.5) / (a*fact)) >= 1.0) { cs_phi = 1.0; /* cos(phi); */ - sn_phi_s3 = 0.0; /* sin(phi) * SQRT3; */ + sn_phi_s3 = 0.0; /* sin(phi) * M_SQRT3; */ } else if (f <= -1.0) { - phi = PI_DIV_3; + phi = M_PI_3; cs_phi = cos(phi); - sn_phi_s3 = sin(phi) * SQRT3; + sn_phi_s3 = sin(phi) * M_SQRT3; } else { phi = acos(f) * THIRD; cs_phi = cos(phi); - sn_phi_s3 = sin(phi) * SQRT3; + sn_phi_s3 = sin(phi) * M_SQRT3; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |