test-skybox/CatalogSkybox.test.js
2024-08-13 18:56:27 +08:00

29 lines
1007 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import CatalogSkybox from "./CatalogSkybox.js";
// 测试CatalogSkybox相关函数的正向和反向转换
// 这个文件单独运行使用node方式运行
// 20240812 blitheli
// theta从-Pi到Piphi从-Pi/2到Pi/2
// theta取100个点phi取50个点
for (let ii = 0; ii < 100; ii++) {
let theta = -Math.PI + ii * Math.PI / 50.0;
for (let jj = 0; jj < 50; jj++) {
let phi = -Math.PI / 2.0 + jj * Math.PI / 50.0;
let { x, y, z } = CatalogSkybox.sphere2CubeXyz(theta, phi);
let { i, j, faceId } = CatalogSkybox.cubeXyzToImgUV(x, y, z);
// 反向转换
let { x1, y1, z1 } = CatalogSkybox.imgUvToCubeXyz(i, j, faceId);
let { thetap, phip } = CatalogSkybox.cubeXyz2Sphere(x1, y1, z1);
if (Math.abs(theta - thetap) > 0.0001 || Math.abs(phi - phip) > 0.0001) {
console.log("error", theta, phi, thetap, phip);
}
}
}
console.log("如果没有输出其它信息,那么表明测试成功了!!");