src/util/WWMath.js
function (farDistance, farResolution, depthBits) {
                if (farDistance < 0) {
                    throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "WWMath", "perspectiveNearDistanceForFarDistance",
                        "The specified distance is negative."));
                }

                if (farResolution < 0) {
                    throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "WWMath", "perspectiveNearDistanceForFarDistance",
                        "The specified resolution is negative."));
                }

                if (depthBits < 1) {
                    throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "WWMath", "perspectiveNearDistanceForFarDistance",
                        "The specified depth bits is negative."));
                }

                var maxDepthValue = (1 << depthBits) - 1;

                return farDistance / (maxDepthValue / (1 - farResolution / farDistance) - maxDepthValue + 1);
            }
function (farDistance, farResolution, depthBits) {
                if (farDistance < 0) {
                    throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "WWMath", "perspectiveNearDistanceForFarDistance",
                        "The specified distance is negative."));
                }

                if (farResolution < 0) {
                    throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "WWMath", "perspectiveNearDistanceForFarDistance",
                        "The specified resolution is negative."));
                }

                if (depthBits < 1) {
                    throw new ArgumentError(Logger.logMessage(Logger.LEVEL_SEVERE, "WWMath", "perspectiveNearDistanceForFarDistance",
                        "The specified depth bits is negative."));
                }

                var maxDepthValue = (1 << depthBits) - 1;

                return farDistance / (maxDepthValue / (1 - farResolution / farDistance) - maxDepthValue + 1);
            }
function ( farDistance , farResolution , depthBits ) { if ( farDistance < 0 ) { throw new ArgumentError ( Logger . logMessage ( Logger . LEVEL_SEVERE , "WWMath" , "perspectiveNearDistanceForFarDistance" , "The specified distance is negative." ) ) ; } if ( farResolution < 0 ) { throw new ArgumentError ( Logger . logMessage ( Logger . LEVEL_SEVERE , "WWMath" , "perspectiveNearDistanceForFarDistance" , "The specified resolution is negative." ) ) ; } if ( depthBits < 1 ) { throw new ArgumentError ( Logger . logMessage ( Logger . LEVEL_SEVERE , "WWMath" , "perspectiveNearDistanceForFarDistance" , "The specified depth bits is negative." ) ) ; } var maxDepthValue = ( 1 << depthBits ) - 1 ; return farDistance / ( maxDepthValue / ( 1 - farResolution / farDistance ) - maxDepthValue + 1 ) ; }
Computes the near clip distance that corresponds to a specified far clip distance and resolution at the far clip
plane.

This computes a near clip distance appropriate for use in [perspectiveFrustumRect]{@link WWMath#perspectiveFrustumRectangle}
and [setToPerspectiveProjection]{@link Matrix#setToPerspectiveProjection}. This returns zero if either the distance or the
resolution are zero.

@param {Number} farDistance The far clip distance, in meters.
@param {Number} farResolution The depth resolution at the far clip plane, in meters.
@param {Number} depthBits The number of bit-planes in the depth buffer.
@returns {Number} The near clip distance, in meters.
@throws {ArgumentError} If either the distance or resolution is negative, or if the depth bits is less
than one.
Computes the near clip distance that corresponds to a specified far clip distance and resolution at the far clip plane .