export class KERNEL_ADJMATRIX_UPDATE {
    constructor() {

    }

    static getSrc(geometryLength) {
        return ["x", ["adjacencyMatrix", "adjacencyMatrixB", "adjacencyMatrixC", "adjacencyMatrixD"],
            // head
            "",

            // source
            `vec4 adjMat = adjacencyMatrix[x]; 
            vec4 adjMatB = adjacencyMatrixB[x];
            vec4 adjMatC = adjacencyMatrixC[x];
            vec4 adjMatD = adjacencyMatrixD[x];

            float linkTypeParent = adjMat.w;
            
            float linkLayerNum = adjMat.x;
            float linkWeight = adjMat.z;
            float multiplier = adjMatD.z;
            float weightAbsSum = adjMatB.x;
            float weightQuadSum = adjMat.y;
            
            
            float costA = adjMatB.y;
            float costB = adjMatC.x;
            float costC = adjMatC.y;
            float costD = adjMatC.z;
            float costE = adjMatC.w;
            float costF = adjMatD.x;
            float costG = adjMatD.y;
            
            if(linkTypeParent == 0.5) {
                float id = adjMatB.z;
                float idInv = adjMatB.w;
            
                vec2 xGeometryCurrentChild = get_global_id(id, bufferNodesWidth, `+geometryLength.toFixed(1)+`);
                vec2 xGeometryParent = get_global_id(idInv, bufferNodesWidth, `+geometryLength.toFixed(1)+`);

                costA = dataB[xGeometryCurrentChild].z;
                costB = dataF[xGeometryCurrentChild].x;
                costC = dataF[xGeometryCurrentChild].z;
                costD = dataG[xGeometryCurrentChild].x;
                costE = dataG[xGeometryCurrentChild].z;
                costF = dataH[xGeometryCurrentChild].x;
                costG = dataH[xGeometryCurrentChild].z;                
            }
            
            return [vec4(linkLayerNum, weightQuadSum, linkWeight, linkTypeParent), vec4(weightAbsSum, costA, adjMatB.z, adjMatB.w), vec4(costB, costC, costD, costE), vec4(costF, costG, 0.0, 0.0)];
            `];
    };
}
global.KERNEL_ADJMATRIX_UPDATE = KERNEL_ADJMATRIX_UPDATE;
module.exports.KERNEL_ADJMATRIX_UPDATE = KERNEL_ADJMATRIX_UPDATE;