1 line
108 KiB
Plaintext
1 line
108 KiB
Plaintext
|
{"version":3,"file":"IntersectionTests-596e31ec.js","sources":["../../../../Source/Core/QuadraticRealPolynomial.js","../../../../Source/Core/CubicRealPolynomial.js","../../../../Source/Core/QuarticRealPolynomial.js","../../../../Source/Core/Ray.js","../../../../Source/Core/IntersectionTests.js"],"sourcesContent":["import DeveloperError from \"./DeveloperError.js\";\nimport CesiumMath from \"./Math.js\";\n\n/**\n * Defines functions for 2nd order polynomial functions of one variable with only real coefficients.\n *\n * @namespace QuadraticRealPolynomial\n */\nconst QuadraticRealPolynomial = {};\n\n/**\n * Provides the discriminant of the quadratic equation from the supplied coefficients.\n *\n * @param {Number} a The coefficient of the 2nd order monomial.\n * @param {Number} b The coefficient of the 1st order monomial.\n * @param {Number} c The coefficient of the 0th order monomial.\n * @returns {Number} The value of the discriminant.\n */\nQuadraticRealPolynomial.computeDiscriminant = function (a, b, c) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof a !== \"number\") {\n throw new DeveloperError(\"a is a required number.\");\n }\n if (typeof b !== \"number\") {\n throw new DeveloperError(\"b is a required number.\");\n }\n if (typeof c !== \"number\") {\n throw new DeveloperError(\"c is a required number.\");\n }\n //>>includeEnd('debug');\n\n const discriminant = b * b - 4.0 * a * c;\n return discriminant;\n};\n\nfunction addWithCancellationCheck(left, right, tolerance) {\n const difference = left + right;\n if (\n CesiumMath.sign(left) !== CesiumMath.sign(right) &&\n Math.abs(difference / Math.max(Math.abs(left), Math.abs(right))) < tolerance\n ) {\n return 0.0;\n }\n\n return difference;\n}\n\n/**\n * Provides the real valued roots of the quadratic polynomial with the provided coefficients.\n *\n * @param {Number} a The coefficient of the 2nd order monomial.\n * @param {Number} b The coefficient of the 1st order monomial.\n * @param {Number} c The coefficient of the 0th order monomial.\n * @returns {Number[]} The real valued roots.\n */\nQuadraticRealPolynomial.computeRealRoots = function (a, b, c) {\n //>>includeStart('debug', pragmas.debug);\n if (typeof a !== \"number\") {\n throw new DeveloperError(\"a is a required number.\");\n }\n if (typeof b !== \"number\") {\n throw new DeveloperError(\"b is a required number.\");\n }\n if (typeof c !== \"number\") {\n throw new DeveloperError(\"c is a required number.\");\n }\n //>>includeEnd('debug');\n\n let ratio;\n if (a === 0.0) {\n if (b === 0.0) {\n // Constant function: c = 0.\n return [];\n }\n\n // Linear function: b * x + c = 0.\n return [-c / b];\n } else if (b === 0.0) {\n if (c === 0.0) {\n // 2nd order monomial: a * x^2 = 0.\n return [0.0, 0.0];\n }\n\n const cMagnitude = Math.abs(c);\n const aMagnitude = Math.abs(a);\n\n if (\n cMagnitude < aMagnitude &&\n cMagnitude / aMagnitude < CesiumMath.EPSILON14\n ) {\n // c ~= 0.0.\n // 2nd order monomial: a * x^2 = 0.\n return [0.0, 0.0];\n } else if (\n cMagnitude > aMagnitude &&\n aMagnitude / cMagnitude < CesiumMath.EPSILON14\n ) {\n // a ~= 0.0.\n // Constant function: c = 0.\n return [];\n }\n\n // a * x^2 + c = 0\n ratio = -c / a;\n\n if (ratio < 0.0) {\n // Both roots are complex.\n return [];\n }\n\n // Both roots are real.\n const root = Math.sqrt(ratio);\n return [-root, root];\n } else if (c === 0.0) {\n // a * x^2 + b * x = 0\n ratio = -b / a;\n if (ratio < 0.0) {\n return [ratio, 0.0];\n }\n\n return [0.0, ratio];\n }\n\n // a * x^2 + b * x + c = 0\n const b2 = b * b;\n const four_ac = 4.0 * a * c;\n const radicand = addWithCancellationCheck(b2, -four_ac, CesiumMath.EPSILON14);\n\n if (radicand < 0.0) {\n // Both roots are complex.\n return [];\n }\n\n const q =\n -0.5 *\n addWithCancellationCheck(\n b,\n CesiumMath.sign(b) * Math.sqrt(radicand),\n
|