1 line
8.2 KiB
Plaintext
1 line
8.2 KiB
Plaintext
|
{"version":3,"file":"CoplanarPolygonGeometryLibrary-b973f66f.js","sources":["../../../../Source/Core/CoplanarPolygonGeometryLibrary.js"],"sourcesContent":["import Cartesian2 from \"./Cartesian2.js\";\nimport Cartesian3 from \"./Cartesian3.js\";\nimport Check from \"./Check.js\";\nimport Matrix3 from \"./Matrix3.js\";\nimport OrientedBoundingBox from \"./OrientedBoundingBox.js\";\n\n/**\n * @private\n */\nconst CoplanarPolygonGeometryLibrary = {};\n\nconst scratchIntersectionPoint = new Cartesian3();\nconst scratchXAxis = new Cartesian3();\nconst scratchYAxis = new Cartesian3();\nconst scratchZAxis = new Cartesian3();\nconst obbScratch = new OrientedBoundingBox();\n\nCoplanarPolygonGeometryLibrary.validOutline = function (positions) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"positions\", positions);\n //>>includeEnd('debug');\n\n const orientedBoundingBox = OrientedBoundingBox.fromPoints(\n positions,\n obbScratch\n );\n const halfAxes = orientedBoundingBox.halfAxes;\n const xAxis = Matrix3.getColumn(halfAxes, 0, scratchXAxis);\n const yAxis = Matrix3.getColumn(halfAxes, 1, scratchYAxis);\n const zAxis = Matrix3.getColumn(halfAxes, 2, scratchZAxis);\n\n const xMag = Cartesian3.magnitude(xAxis);\n const yMag = Cartesian3.magnitude(yAxis);\n const zMag = Cartesian3.magnitude(zAxis);\n\n // If all the points are on a line return undefined because we can't draw a polygon\n return !(\n (xMag === 0 && (yMag === 0 || zMag === 0)) ||\n (yMag === 0 && zMag === 0)\n );\n};\n\n// call after removeDuplicates\nCoplanarPolygonGeometryLibrary.computeProjectTo2DArguments = function (\n positions,\n centerResult,\n planeAxis1Result,\n planeAxis2Result\n) {\n //>>includeStart('debug', pragmas.debug);\n Check.defined(\"positions\", positions);\n Check.defined(\"centerResult\", centerResult);\n Check.defined(\"planeAxis1Result\", planeAxis1Result);\n Check.defined(\"planeAxis2Result\", planeAxis2Result);\n //>>includeEnd('debug');\n\n const orientedBoundingBox = OrientedBoundingBox.fromPoints(\n positions,\n obbScratch\n );\n const halfAxes = orientedBoundingBox.halfAxes;\n const xAxis = Matrix3.getColumn(halfAxes, 0, scratchXAxis);\n const yAxis = Matrix3.getColumn(halfAxes, 1, scratchYAxis);\n const zAxis = Matrix3.getColumn(halfAxes, 2, scratchZAxis);\n\n const xMag = Cartesian3.magnitude(xAxis);\n const yMag = Cartesian3.magnitude(yAxis);\n const zMag = Cartesian3.magnitude(zAxis);\n const min = Math.min(xMag, yMag, zMag);\n\n // If all the points are on a line return undefined because we can't draw a polygon\n if (\n (xMag === 0 && (yMag === 0 || zMag === 0)) ||\n (yMag === 0 && zMag === 0)\n ) {\n return false;\n }\n\n let planeAxis1;\n let planeAxis2;\n\n if (min === yMag || min === zMag) {\n planeAxis1 = xAxis;\n }\n if (min === xMag) {\n planeAxis1 = yAxis;\n } else if (min === zMag) {\n planeAxis2 = yAxis;\n }\n if (min === xMag || min === yMag) {\n planeAxis2 = zAxis;\n }\n\n Cartesian3.normalize(planeAxis1, planeAxis1Result);\n Cartesian3.normalize(planeAxis2, planeAxis2Result);\n Cartesian3.clone(orientedBoundingBox.center, centerResult);\n return true;\n};\n\nfunction projectTo2D(position, center, axis1, axis2, result) {\n const v = Cartesian3.subtract(position, center, scratchIntersectionPoint);\n const x = Cartesian3.dot(axis1, v);\n const y = Cartesian3.dot(axis2, v);\n\n return Cartesian2.fromElements(x, y, result);\n}\n\nCoplanarPolygonGeometryLibrary.createProjectPointsTo2DFunction = function (\n center,\n axis1,\n axis2\n) {\n return function (positions) {\n const positionResults = new Array(positions.length);\n for (let i = 0; i < positions.length; i++) {\n positionResults[i] = projectTo2D(positions[i], center, axis1, axis2);\n }\n\n return positionResults;\n };\n};\n\nCoplanarPolygonGeometryLibrary.createProjectPointTo2DFunction = function (\n center,\n axis1,\n axis2\n) {\n return function (position, result) {\n return projectTo2D(position, center, axis1, axis2, result);\n
|