+ qboolean adjusted = qfalse;
+
+ // A change from the original SnapNormal() is that we snap each
+ // component that's close to 0. So for example if a normal is
+ // (0.707, 0.707, 0.0000001), it will get snapped to lie perfectly in the
+ // XY plane (its Z component will be set to 0 and its length will be
+ // normalized). The original SnapNormal() didn't snap such vectors - it
+ // only snapped vectors that were near a perfect axis.
+
+ for (i = 0; i < 3; i++)
+ {
+ if (normal[i] != 0.0 && -normalEpsilon < normal[i] && normal[i] < normalEpsilon)
+ {
+ normal[i] = 0.0;
+ adjusted = qtrue;
+ }
+ }
+
+ if (adjusted)
+ {
+ VectorNormalize(normal, normal);
+ return qtrue;
+ }
+ return qfalse;
+#else
+ int i;
+
+ // I would suggest that you uncomment the following code and look at the
+ // results:
+
+ /*
+ Sys_Printf("normalEpsilon is %f\n", normalEpsilon);
+ for (i = 0;; i++)
+ {
+ normal[0] = 1.0;
+ normal[1] = 0.0;
+ normal[2] = i * 0.000001;
+ VectorNormalize(normal, normal);
+ if (1.0 - normal[0] >= normalEpsilon) {
+ Sys_Printf("(%f %f %f)\n", normal[0], normal[1], normal[2]);
+ Error("SnapNormal: test completed");
+ }
+ }
+ */
+
+ // When the normalEpsilon is 0.00001, the loop will break out when normal is
+ // (0.999990 0.000000 0.004469). In other words, this is the vector closest
+ // to axial that will NOT be snapped. Anything closer will be snaped. Now,
+ // 0.004469 is close to 1/225. The length of a circular quarter-arc of radius
+ // 1 is PI/2, or about 1.57. And 0.004469/1.57 is about 0.0028, or about
+ // 1/350. Expressed a different way, 1/350 is also about 0.26/90.
+ // This means is that a normal with an angle that is within 1/4 of a degree
+ // from axial will be "snapped". My belief is that the person who wrote the
+ // code below did not intend it this way. I think the person intended that
+ // the epsilon be measured against the vector components close to 0, not 1.0.
+ // I think the logic should be: if 2 of the normal components are within
+ // epsilon of 0, then the vector can be snapped to be perfectly axial.
+ // We may consider adjusting the epsilon to a larger value when we make this
+ // code fix.