GitHub PullRequestReviewCommentEvent at 2014-02-03 22:39:57
Repository: cesium
Actor: kring
Payload: {"comment":{"url":"https://api.github.com/repos/AnalyticalGraphicsInc/cesium/pulls/comments/9403097","id":9403097,"diff_hunk":"@@ -0,0 +1,416 @@\n+/*global define*/\n+define([\n+        '../Core/BoundingSphere',\n+        '../Core/Cartesian3',\n+        '../Core/Cartographic',\n+        '../Core/Ellipsoid',\n+        '../Core/EllipsoidalOccluder',\n+        '../Core/Extent',\n+        '../Core/HeightmapTessellator',\n+        '../Core/Intersections2D',\n+        '../Core/Math',\n+        './createTaskProcessorWorker'\n+    ], function(\n+        BoundingSphere,\n+        Cartesian3,\n+        Cartographic,\n+        Ellipsoid,\n+        EllipsoidalOccluder,\n+        Extent,\n+        HeightmapTessellator,\n+        Intersections2D,\n+        CesiumMath,\n+        createTaskProcessorWorker) {\n+    \"use strict\";\n+\n+    var maxShort = 32767;\n+\n+    var clipScratch = [];\n+    var clipScratch2 = [];\n+    var verticesScratch = [];\n+    var cartographicScratch = new Cartographic();\n+    var cartesian3Scratch = new Cartesian3();\n+    var uScratch = [];\n+    var vScratch = [];\n+    var heightScratch = [];\n+    var indicesScratch = [];\n+    var horizonOcclusionPointScratch = new Cartesian3();\n+    var boundingSphereScratch = new BoundingSphere();\n+\n+    function upsampleQuantizedTerrainMesh(parameters, transferableObjects) {\n+        var isEastChild = parameters.isEastChild;\n+        var isNorthChild = parameters.isNorthChild;\n+\n+        var minU = isEastChild ? 0.5 : 0.0;\n+        var maxU = isEastChild ? 1.0 : 0.5;\n+        var minV = isNorthChild ? 0.5 : 0.0;\n+        var maxV = isNorthChild ? 1.0 : 0.5;\n+\n+        var uBuffer = uScratch;\n+        var vBuffer = vScratch;\n+        var heightBuffer = heightScratch;\n+\n+        uBuffer.length = 0;\n+        vBuffer.length = 0;\n+        heightBuffer.length = 0;\n+\n+        var indices = indicesScratch;\n+        indices.length = 0;\n+\n+        var vertexMap = {};\n+\n+        var parentVertices = parameters.vertices;\n+        var parentIndices = parameters.indices;\n+\n+        var quantizedVertexCount = parentVertices.length / 3;\n+        var parentUBuffer = parentVertices.subarray(0, quantizedVertexCount);\n+        var parentVBuffer = parentVertices.subarray(quantizedVertexCount, 2 * quantizedVertexCount);\n+        var parentHeightBuffer = parentVertices.subarray(quantizedVertexCount * 2, 3 * quantizedVertexCount);\n+\n+        var vertexCount = 0;\n+\n+        var i, u, v;\n+        for (i = 0; i < quantizedVertexCount; ++i) {\n+            u = parentUBuffer[i] / maxShort;\n+            v = parentVBuffer[i] / maxShort;\n+            if ((isEastChild && u >= 0.5 || !isEastChild && u <= 0.5) &&\n+                (isNorthChild && v >= 0.5 || !isNorthChild && v <= 0.5)) {\n+\n+                vertexMap[i] = vertexCount;\n+                uBuffer.push(u);\n+                vBuffer.push(v);\n+                heightBuffer.push(parentHeightBuffer[i]);\n+                ++vertexCount;\n+            }\n+        }\n+\n+        var triangleVertices = [];\n+        triangleVertices.push(new Vertex());\n+        triangleVertices.push(new Vertex());\n+        triangleVertices.push(new Vertex());\n+\n+        var clippedTriangleVertices = [];\n+        clippedTriangleVertices.push(new Vertex());\n+        clippedTriangleVertices.push(new Vertex());\n+        clippedTriangleVertices.push(new Vertex());\n+\n+        var clippedIndex;\n+        var clipped2;\n+\n+        for (i = 0; i < parentIndices.length; i += 3) {\n+            var i0 = parentIndices[i];\n+            var i1 = parentIndices[i + 1];\n+            var i2 = parentIndices[i + 2];\n+\n+            var u0 = parentUBuffer[i0] / maxShort;\n+            var u1 = parentUBuffer[i1] / maxShort;\n+            var u2 = parentUBuffer[i2] / maxShort;\n+\n+            triangleVertices[0].initializeIndexed(parentUBuffer, parentVBuffer, parentHeightBuffer, i0);\n+            triangleVertices[1].initializeIndexed(parentUBuffer, parentVBuffer, parentHeightBuffer, i1);\n+            triangleVertices[2].initializeIndexed(parentUBuffer, parentVBuffer, parentHeightBuffer, i2);\n+\n+            // Clip triangle on the east-west boundary.\n+            var clipped = Intersections2D.clipTriangleAtAxisAlignedThreshold(0.5, isEastChild, u0, u1, u2, clipScratch);\n+\n+            // Get the first clipped triangle, if any.\n+            clippedIndex = 0;\n+\n+            if (clippedIndex >= clipped.length) {\n+                continue;\n+            }\n+            clippedIndex = clippedTriangleVertices[0].initializeFromClipResult(clipped, clippedIndex, triangleVertices);\n+\n+            if (clippedIndex >= clipped.length) {\n+                continue;\n+            }\n+            clippedIndex = clippedTriangleVertices[1].initializeFromClipResult(clipped, clippedIndex, triangleVertices);\n+\n+            if (clippedIndex >= clipped.length) {\n+                continue;\n+            }\n+            clippedIndex = clippedTriangleVertices[2].initializeFromClipResult(clipped, clippedIndex, triangleVertices);\n+\n+            // Clip the triangle against the North-south boundary.\n+            clipped2 = Intersections2D.clipTriangleAtAxisAlignedThreshold(0.5, isNorthChild, clippedTriangleVertices[0].getV(), clippedTriangleVertices[1].getV(), clippedTriangleVertices[2].getV(), clipScratch2);\n+            addClippedPolygon(uBuffer, vBuffer, heightBuffer, indices, vertexMap, clipped2, clippedTriangleVertices);\n+\n+            // If there's another vertex in the original clipped result,\n+            // it forms a second triangle.  Clip it as well.\n+            if (clippedIndex < clipped.length) {\n+                clippedTriangleVertices[2].clone(clippedTriangleVertices[1]);\n+                clippedTriangleVertices[2].initializeFromClipResult(clipped, clippedIndex, triangleVertices);\n+\n+                clipped2 = Intersections2D.clipTriangleAtAxisAlignedThreshold(0.5, isNorthChild, clippedTriangleVertices[0].getV(), clippedTriangleVertices[1].getV(), clippedTriangleVertices[2].getV(), clipScratch2);\n+                addClippedPolygon(uBuffer, vBuffer, heightBuffer, indices, vertexMap, clipped2, clippedTriangleVertices);\n+            }\n+        }\n+\n+        var uOffset = isEastChild ? -1.0 : 0.0;\n+        var vOffset = isNorthChild ? -1.0 : 0.0;\n+\n+        var parentMinimumHeight = parameters.minimumHeight;\n+        var parentMaximumHeight = parameters.maximumHeight;\n+\n+        var westIndices = [];\n+        var southIndices = [];\n+        var eastIndices = [];\n+        var northIndices = [];\n+\n+        var minimumHeight = Number.MAX_VALUE;\n+        var maximumHeight = -minimumHeight;\n+\n+        var cartesianVertices = verticesScratch;\n+        cartesianVertices.length = 0;\n+\n+        var ellipsoid = Ellipsoid.clone(parameters.ellipsoid);\n+        var extent = parameters.childExtent;\n+\n+        for (i = 0; i < uBuffer.length; ++i) {\n+            u = uBuffer[i];\n+            if (u <= minU) {\n+                westIndices.push(i);\n+                u = 0.0;\n+            } else if (u >= maxU) {\n+                eastIndices.push(i);\n+                u = 1.0;\n+            } else {\n+                u = u * 2.0 + uOffset;\n+            }\n+\n+            uBuffer[i] = u;\n+\n+            v = vBuffer[i];\n+            if (v <= minV) {\n+                southIndices.push(i);\n+                v = 0.0;\n+            } else if (v >= maxV) {\n+                northIndices.push(i);\n+                v = 1.0;\n+            } else {\n+                v = v * 2.0 + vOffset;\n+            }\n+\n+            vBuffer[i] = v;\n+\n+            var height = CesiumMath.lerp(parentMinimumHeight, parentMaximumHeight, heightBuffer[i] / maxShort);\n+            if (height < minimumHeight) {\n+                minimumHeight = height;\n+            }\n+            if (height > maximumHeight) {\n+                maximumHeight = height;\n+            }\n+\n+            heightBuffer[i] = height;\n+\n+            cartographicScratch.longitude = CesiumMath.lerp(extent.west, extent.east, u);\n+            cartographicScratch.latitude = CesiumMath.lerp(extent.south, extent.north, v);\n+            cartographicScratch.height = height;\n+\n+            ellipsoid.cartographicToCartesian(cartographicScratch, cartesian3Scratch);\n+\n+            cartesianVertices.push(cartesian3Scratch.x);\n+            cartesianVertices.push(cartesian3Scratch.y);\n+            cartesianVertices.push(cartesian3Scratch.z);\n+        }\n+\n+        var boundingSphere = BoundingSphere.fromVertices(cartesianVertices, Cartesian3.ZERO, 3, boundingSphereScratch);\n+\n+        var occluder = new EllipsoidalOccluder(ellipsoid);\n+        var horizonOcclusionPoint = occluder.computeHorizonCullingPointFromVertices(boundingSphere.center, cartesianVertices, 3, boundingSphere.center, horizonOcclusionPointScratch);\n+\n+        var heightRange = maximumHeight - minimumHeight;\n+\n+        var vertices = new Uint16Array(uBuffer.length + vBuffer.length + heightBuffer.length);\n+\n+        for (i = 0; i < uBuffer.length; ++i) {\n+            vertices[i] = uBuffer[i] * maxShort;\n+        }\n+\n+        var start = uBuffer.length;\n+\n+        for (i = 0; i < vBuffer.length; ++i) {\n+            vertices[start + i] = vBuffer[i] * maxShort;\n+        }\n+\n+        start += vBuffer.length;\n+\n+        for (i = 0; i < heightBuffer.length; ++i) {\n+            vertices[start + i] = maxShort * (heightBuffer[i] - minimumHeight) / heightRange;\n+        }\n+\n+        var indicesTypedArray = new Uint16Array(indices);\n+\n+        transferableObjects.push(vertices.buffer);\n+        transferableObjects.push(indicesTypedArray.buffer);\n+\n+        return {\n+            vertices : vertices.buffer,\n+            indices : indicesTypedArray.buffer,\n+            minimumHeight : minimumHeight,\n+            maximumHeight : maximumHeight,\n+            westIndices : westIndices,\n+            southIndices : southIndices,\n+            eastIndices : eastIndices,\n+            northIndices : northIndices,\n+            boundingSphere : boundingSphere,\n+            horizonOcclusionPoint : horizonOcclusionPoint\n+        };\n+    }\n+\n+    function Vertex() {","path":"Source/Workers/upsampleQuantizedTerrainMesh.js","position":261,"original_position":261,"commit_id":"f2bc88c70962fc42330566e8bc7121c814f89a9d","original_commit_id":"f81495355f7778b8e652f2d03401702c311090c9","user":{"login":"kring","id":924374,"avatar_url":"https://gravatar.com/avatar/67333af82be41c2da955c327af956535?d=https%3A%2F%2Fidenticons.github.com%2Ff2f877d7e680b118d8fbf7391cf039c5.png&r=x","gravatar_id":"67333af82be41c2da955c327af956535","url":"https://api.github.com/users/kring","html_url":"https://github.com/kring","followers_url":"https://api.github.com/users/kring/followers","following_url":"https://api.github.com/users/kring/following{/other_user}","gists_url":"https://api.github.com/users/kring/gists{/gist_id}","starred_url":"https://api.github.com/users/kring/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kring/subscriptions","organizations_url":"https://api.github.com/users/kring/orgs","repos_url":"https://api.github.com/users/kring/repos","events_url":"https://api.github.com/users/kring/events{/privacy}","received_events_url":"https://api.github.com/users/kring/received_events","type":"User","site_admin":false},"body":"We do it lots of other places, certainly in all the code I've written.  Here's one example: https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/CentralBodySurface.js#L327\r\n\r\nI get the argument about variable assignment, but I don't think that ever matters at module scope in a properly written module.  Meanwhile, it drives me crazy every time I open `JulianDate` or `ShaderProgram` and have to scroll past a ton of nonsense before I find the thing I actual opened the file looking for.  So you're going to need a stronger argument than (the false statement) \"we don't do it anywhere else\" if you want me to change it, sorry.","created_at":"2014-02-03T22:39:57Z","updated_at":"2014-02-03T22:39:57Z","html_url":"https://github.com/AnalyticalGraphicsInc/cesium/pull/1420#discussion_r9403097","pull_request_url":"https://api.github.com/repos/AnalyticalGraphicsInc/cesium/pulls/1420","_links":{"self":{"href":"https://api.github.com/repos/AnalyticalGraphicsInc/cesium/pulls/comments/9403097"},"html":{"href":"https://github.com/AnalyticalGraphicsInc/cesium/pull/1420#discussion_r9403097"},"pull_request":{"href":"https://api.github.com/repos/AnalyticalGraphicsInc/cesium/pulls/1420"}}}}