Skip to content

Commit a822285

Browse files
committed
Fixing torus Test_Thick_Cylinder bug. Ceasing use of it.
See late April 2019 comments to github pull request POV-Ray#358.
1 parent d840b26 commit a822285

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

source/core/shape/torus.cpp

+30-25
Original file line numberDiff line numberDiff line change
@@ -254,29 +254,34 @@ int Torus::Intersect(const BasicRay& ray, DBL *Depth, RenderStatistics& stats) c
254254

255255
r2 = Sqr(MajorRadius + MinorRadius);
256256

257-
#ifdef TORUS_EXTRA_STATS
258-
stats[Torus_Bound_Tests]++;
259-
#endif
260-
261-
if (Test_Thick_Cylinder(P, D, y1, y2, r1, r2))
257+
//#ifdef TORUS_EXTRA_STATS
258+
// stats[Torus_Bound_Tests]++;
259+
//#endif
260+
261+
// @todo Look to completely remove Test_Thick_Cylinder unless compelling reason
262+
// found to keep it. If keep it also look to turn off on -mb use.
263+
// if (Test_Thick_Cylinder(P, D, y1, y2, r1, r2))
264+
if ( true )
262265
{
263-
#ifdef TORUS_EXTRA_STATS
264-
stats[Torus_Bound_Tests_Succeeded]++;
265-
#endif
266-
267-
// @todo Look to remove the optimization below. It's true the rays origin
268-
// being nearer eventual surface intersection normalizes the polynomial
269-
// values returned on evaluation. However, after recent solver improvements
270-
// values are less often used to determine intersections directly. Further,
271-
// the optimization below was never a general one in that it handled only
266+
//#ifdef TORUS_EXTRA_STATS
267+
// stats[Torus_Bound_Tests_Succeeded]++;
268+
//#endif
269+
270+
// @todo Look for more general way to apply the ray origin distance normalization.
271+
//
272+
// The optimization below found to condition polynomials where P is
273+
// far from the torus such that they are much easier to solver. Coefficients
274+
// and evaluated values not necessarily normalized because the defined torus
275+
// is not normalized during parsing and set up for user minor/major radii.
276+
// The optimization below also not a general one in that it handles only
272277
// the P far away cases and not secondary rays where the torus itself might
273-
// create "long" rays to itself. It also didn't handle cases where the distances
274-
// might be dimensionally really small in the solver space. Probably the
275-
// optimization isn't any longer needed, but if so, look to normalize using
276-
// the coefficient values so to normalize the returned values more generally.
278+
// create "long" rays to itself. Aside: The original choice of +MinorRadius
279+
// to be sure origin outside also 'fortunate' in that it tends produces nice
280+
// coefficients for usual major/minor radii.
281+
//
277282
// Cost with improved versions of solvers:
278283
// solve_quartic calls +1.30%
279-
// polysolve calls +0.25%
284+
// polysolve calls +0.25% (since found some faster cases - interations <)
280285

281286
// Move P close to bounding sphere to have more precise root calculation.
282287
// Bounding sphere radius is R + r, we add r once more to ensure
@@ -969,7 +974,7 @@ bool Torus::Test_Thick_Cylinder(const Vector3d& P, const Vector3d& D, DBL h1, DB
969974
u = P[X] + k * D[X];
970975
v = P[Z] + k * D[Z];
971976

972-
if ((k > gkDBL_epsilon) && (k < MAX_DISTANCE))
977+
if (k > gkDBL_epsilon)
973978
{
974979
r = u * u + v * v;
975980

@@ -986,7 +991,7 @@ bool Torus::Test_Thick_Cylinder(const Vector3d& P, const Vector3d& D, DBL h1, DB
986991
u = P[X] + k * D[X];
987992
v = P[Z] + k * D[Z];
988993

989-
if ((k > gkDBL_epsilon) && (k < MAX_DISTANCE))
994+
if (k > gkDBL_epsilon)
990995
{
991996
r = u * u + v * v;
992997

@@ -1015,7 +1020,7 @@ bool Torus::Test_Thick_Cylinder(const Vector3d& P, const Vector3d& D, DBL h1, DB
10151020

10161021
k = (-b + d) / a;
10171022

1018-
if ((k > gkDBL_epsilon) && (k < MAX_DISTANCE))
1023+
if (k > gkDBL_epsilon)
10191024
{
10201025
h = P[Y] + k * D[Y];
10211026

@@ -1027,7 +1032,7 @@ bool Torus::Test_Thick_Cylinder(const Vector3d& P, const Vector3d& D, DBL h1, DB
10271032

10281033
k = (-b - d) / a;
10291034

1030-
if ((k > gkDBL_epsilon) && (k < MAX_DISTANCE))
1035+
if (k > gkDBL_epsilon)
10311036
{
10321037
h = P[Y] + k * D[Y];
10331038

@@ -1050,7 +1055,7 @@ bool Torus::Test_Thick_Cylinder(const Vector3d& P, const Vector3d& D, DBL h1, DB
10501055

10511056
k = (-b + d) / a;
10521057

1053-
if ((k > gkDBL_epsilon) && (k < MAX_DISTANCE))
1058+
if (k > gkDBL_epsilon)
10541059
{
10551060
h = P[Y] + k * D[Y];
10561061

@@ -1062,7 +1067,7 @@ bool Torus::Test_Thick_Cylinder(const Vector3d& P, const Vector3d& D, DBL h1, DB
10621067

10631068
k = (-b - d) / a;
10641069

1065-
if ((k > gkDBL_epsilon) && (k < MAX_DISTANCE))
1070+
if (k > gkDBL_epsilon)
10661071
{
10671072
h = P[Y] + k * D[Y];
10681073

0 commit comments

Comments
 (0)