@@ -254,29 +254,34 @@ int Torus::Intersect(const BasicRay& ray, DBL *Depth, RenderStatistics& stats) c
254
254
255
255
r2 = Sqr (MajorRadius + MinorRadius);
256
256
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 )
262
265
{
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
272
277
// 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
+ //
277
282
// Cost with improved versions of solvers:
278
283
// solve_quartic calls +1.30%
279
- // polysolve calls +0.25%
284
+ // polysolve calls +0.25% (since found some faster cases - interations <)
280
285
281
286
// Move P close to bounding sphere to have more precise root calculation.
282
287
// 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
969
974
u = P[X] + k * D[X];
970
975
v = P[Z] + k * D[Z];
971
976
972
- if (( k > gkDBL_epsilon) && (k < MAX_DISTANCE) )
977
+ if (k > gkDBL_epsilon)
973
978
{
974
979
r = u * u + v * v;
975
980
@@ -986,7 +991,7 @@ bool Torus::Test_Thick_Cylinder(const Vector3d& P, const Vector3d& D, DBL h1, DB
986
991
u = P[X] + k * D[X];
987
992
v = P[Z] + k * D[Z];
988
993
989
- if (( k > gkDBL_epsilon) && (k < MAX_DISTANCE) )
994
+ if (k > gkDBL_epsilon)
990
995
{
991
996
r = u * u + v * v;
992
997
@@ -1015,7 +1020,7 @@ bool Torus::Test_Thick_Cylinder(const Vector3d& P, const Vector3d& D, DBL h1, DB
1015
1020
1016
1021
k = (-b + d) / a;
1017
1022
1018
- if (( k > gkDBL_epsilon) && (k < MAX_DISTANCE) )
1023
+ if (k > gkDBL_epsilon)
1019
1024
{
1020
1025
h = P[Y] + k * D[Y];
1021
1026
@@ -1027,7 +1032,7 @@ bool Torus::Test_Thick_Cylinder(const Vector3d& P, const Vector3d& D, DBL h1, DB
1027
1032
1028
1033
k = (-b - d) / a;
1029
1034
1030
- if (( k > gkDBL_epsilon) && (k < MAX_DISTANCE) )
1035
+ if (k > gkDBL_epsilon)
1031
1036
{
1032
1037
h = P[Y] + k * D[Y];
1033
1038
@@ -1050,7 +1055,7 @@ bool Torus::Test_Thick_Cylinder(const Vector3d& P, const Vector3d& D, DBL h1, DB
1050
1055
1051
1056
k = (-b + d) / a;
1052
1057
1053
- if (( k > gkDBL_epsilon) && (k < MAX_DISTANCE) )
1058
+ if (k > gkDBL_epsilon)
1054
1059
{
1055
1060
h = P[Y] + k * D[Y];
1056
1061
@@ -1062,7 +1067,7 @@ bool Torus::Test_Thick_Cylinder(const Vector3d& P, const Vector3d& D, DBL h1, DB
1062
1067
1063
1068
k = (-b - d) / a;
1064
1069
1065
- if (( k > gkDBL_epsilon) && (k < MAX_DISTANCE) )
1070
+ if (k > gkDBL_epsilon)
1066
1071
{
1067
1072
h = P[Y] + k * D[Y];
1068
1073
0 commit comments