<commit_before>/* <NAME> Copyright @2014
 * Asynchronous loading and parsing of CAD model information
 */

/*********************************************************************/

function processAssembly(url, workerID, data) {
    // All we really need to do is pass this back to the main thread
    self.postMessage({
        type: "rootLoad",
        url: url,
        data: data,
        workerID: workerID
    });
}

function processAnnotation(url, workerID, data) {
    var parts = url.split("/");
    // All we really need to do is pass this back to the main thread
    self.postMessage({
        type: "annotationLoad",
        url: url,
        file: parts[parts.length - 1],
        data: data,
        workerID: workerID
    });
}

/*********************************************************************/

function processShellXML(url, workerID, data) {
    var parts = url.split("/");
    // All we really need to do is pass this back to the main thread
    self.postMessage({
        type: "shellLoad",
        url: url,
        file: parts[parts.length - 1],
        data: data,
        workerID: workerID
    });
    // Signal that this worker is done
    self.postMessage({
        type: "workerFinish",
        workerID: workerID
    });
}

function unindexPoints(data) {
    var numPoints = data.pointsIndex.length;
    data.points = [];
    for (var i = 0; i < numPoints; i++) {
        var value = data.values[data.pointsIndex[i]];
        data.points.push(value);
    }
    delete data.pointsIndex;
}

function unindexNormals(data) {
    var numNormals = data.normalsIndex.length;
    data.normals = [];
    for (var i = 0; i < numNormals; i++) {
        var value = data.values[data.normalsIndex[i]];
        data.normals.push(value);
    }
    delete data.normalsIndex;
}

function unindexColors(data) {
    var numColors = data.colorsIndex.length;
    data.colors = [];
    for (var i = 0; i < numColors; i++) {
        var value = data.values[data.colorsIndex[i]];
        data.colors.push(value);
    }
    delete data.colorsIndex;
}

function uncompressColors(data) {
    data.colors = [];
    var numBlocks = data.colorsData.length;
    for (var i = 0; i < numBlocks; i++) {
        var block = data.colorsData[i];
        for (var j = 0; j < block.duration; j++) {
            data.colors.push(block.data[0]);
            data.colors.push(block.data[1]);
            data.colors.push(block.data[2]);
        }
    }
    delete data.colorsData;
}

function processShellJSON(url, workerID, dataJSON, signalFinish) {
    var parts = url.split("/");
    self.postMessage({
        type: "parseComplete",
        file: parts[parts.length - 1]
    });

    if (dataJSON.values && dataJSON.precision) {
        var factor = Math.pow(10, dataJSON.precision);
        var length = dataJSON.values.length;
        for (var i = 0; i < length; i++) {
            dataJSON.values[i] /= factor;
        }
    }
    if (dataJSON.pointsIndex) {
        unindexPoints(dataJSON);
    }
    if (dataJSON.normalsIndex) {
        unindexNormals(dataJSON);
    }
    if (dataJSON.colorsIndex) {
        unindexColors(dataJSON);
    }
    if (dataJSON.colorsData) {
        uncompressColors(dataJSON);
    }

    // Just copy the data into arrays
    var buffers = {
        position: new Float32Array(dataJSON.points),
        normals: new Float32Array(dataJSON.normals),
        colors: new Float32Array(dataJSON.colors)
    };
    self.postMessage({
        type: "shellLoad",
        data: buffers,
        id: dataJSON.id,
        workerID: workerID,
        file: parts[parts.length - 1]
    }, [buffers.position.buffer, buffers.normals.buffer, buffers.colors.buffer]);
    // Do we signal that we are all done
    if (signalFinish) {
        self.postMessage({
            type: "workerFinish",<commit_msg>Optimize client uncompress.<commit_after>/* <NAME> Copyright @2014
 * Asynchronous loading and parsing of CAD model information
 */

/*********************************************************************/

function processAssembly(url, workerID, data) {
    // All we really need to do is pass this back to the main thread
    self.postMessage({
        type: "rootLoad",
        url: url,
        data: data,
        workerID: workerID
    });
}

function processAnnotation(url, workerID, data) {
    var parts = url.split("/");
    // All we really need to do is pass this back to the main thread
    self.postMessage({
        type: "annotationLoad",
        url: url,
        file: parts[parts.length - 1],
        data: data,
        workerID: workerID
    });
}

/*********************************************************************/

function processShellXML(url, workerID, data) {
    var parts = url.split("/");
    // All we really need to do is pass this back to the main thread
    self.postMessage({
        type: "shellLoad",
        url: url,
        file: parts[parts.length - 1],
        data: data,
        workerID: workerID
    });
    // Signal that this worker is done
    self.postMessage({
        type: "workerFinish",
        workerID: workerID
    });
}

function unindexValues(data, buffers) {
    var numValues = data.pointsIndex.length;
    for (var i = 0; i < numValues; i++) {
        buffers.position[i] = data.values[data.pointsIndex[i]];
        buffers.normals[i] = data.values[data.normalsIndex[i]];
    }
    //delete data.pointsIndex;
    //delete data.normalsIndex;
}


function uncompressColors(data, colorsBuffer) {
    var index = 0;
    var numBlocks = data.colorsData.length;
    for (var i = 0; i < numBlocks; i++) {
        var block = data.colorsData[i];
        for (var j = 0; j < block.duration; j++) {
            colorsBuffer[index++] = block.data[0];
            colorsBuffer[index++] = block.data[1];
            colorsBuffer[index++] = block.data[2];
        }
    }
    //delete data.colorsData;
}

function processShellJSON(url, workerID, dataJSON, signalFinish) {
    var parts = url.split("/");
    self.postMessage({
        type: "parseComplete",
        file: parts[parts.length - 1]
    });

    // Just copy the data into arrays
    var buffers = {
        position: new Float32Array(dataJSON.pointsIndex.length),
        normals: new Float32Array(dataJSON.pointsIndex.length),
        colors: new Float32Array(dataJSON.pointsIndex.length)
    };

    if (dataJSON.values) {
        if (dataJSON.precision) {
            var factor = Math.pow(10, dataJSON.precision);
            var length = dataJSON.values.length;
            for (var i = 0; i < length; i++) {
                dataJSON.values[i] /= factor;
            }
        }
        unindexValues(dataJSON, buffers);
    }
    if (dataJSON.colorsData) {
        uncompressColors(dataJSON, buffers.colors);
    }

    self.postMessage({
        type: "shellLoad",
        data: buffers,
        id: dataJSON.id,
        workerID: workerID,
        file: parts[parts.length - 1]
    }, [buffers.position.buffer, buffers.normals.buffer, buffers.colors.buffer]);
    // Do we signal that we are all done
    if (signalFinish) {
        self.postMessage({
            type: "workerFinish",
{'fraction_non_alphanumeric': 0.15883260839062718, 'fraction_numerical': 0.0068752630840465834, 'mean_word_length': 2.3765987683562293, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2465319', 'n_tokens_mistral': 2151, 'n_tokens_neox': 2084, 'n_words': 548}