Created
August 24, 2025 21:53
-
-
Save lardratboy/c8697c6bb9607019a48c954543167f43 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tiledProjection(points, quantizationBits) { | |
| const q = quantizationBits; | |
| const qRange = Math.pow(2, q); | |
| const sqrtQRange = Math.floor(Math.sqrt(qRange)); | |
| const maxTiledCoord = Math.max(sqrtQRange * qRange + qRange - 1, 1); | |
| // Create new projected points array | |
| const projectedPoints = new Float32Array(points.length); | |
| for (let i = 0; i < points.length; i += 3) { | |
| const x = points[i]; | |
| const y = points[i + 1]; | |
| const z = points[i + 2]; | |
| // Convert normalized coordinates [-1,1] to discrete grid [0, qRange-1] | |
| const discreteX = Math.max(0, Math.min(qRange - 1, Math.floor((x + 1) / 2 * qRange))); | |
| const discreteY = Math.max(0, Math.min(qRange - 1, Math.floor((y + 1) / 2 * qRange))); | |
| const discreteZ = Math.max(0, Math.min(qRange - 1, Math.floor((z + 1) / 2 * qRange))); | |
| // Apply tiling formula: (col, row) = (z % sqrt(2^q), floor(z / sqrt(2^q))) | |
| const col = discreteZ % sqrtQRange; | |
| const row = Math.floor(discreteZ / sqrtQRange); | |
| // Calculate tiled coordinates: col * 2^q + x, row * 2^q + y | |
| const tiledX = col * qRange + discreteX; | |
| const tiledY = row * qRange + discreteY; | |
| // Normalize back for display (scale to fit in reasonable viewing area) | |
| projectedPoints[i] = (tiledX / maxTiledCoord) * 2 - 1; | |
| projectedPoints[i + 1] = (tiledY / maxTiledCoord) * 2 - 1; | |
| projectedPoints[i + 2] = 0; // Flatten to z=0 plane | |
| } | |
| return projectedPoints; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment