import CatalogSkybox from "./CatalogSkybox.js";

//  测试CatalogSkybox相关函数的正向和反向转换
//  这个文件单独运行，使用node方式运行！
//  20240812    blitheli

//  theta从-Pi到Pi，phi从-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("如果没有输出其它信息，那么表明测试成功了！！");