<commit_before>/*
 * app/src/libworker.js
 *
 *
 * Copyright (C) 2015  <NAME> <<EMAIL>>
 *
 * License in LICENSE file at the root of the repository.
 *
 */


var workerContext = self;

//< OL3 helpers
workerContext.window = {
    'location' : workerContext.location
};
workerContext.window.document = {
    'implementation':{
        'createDocument': function () { return true; }
    }
};
workerContext.document = workerContext.window.document;
workerContext.Image = function Image() {};
//> END OF OL3 helpers

var underscore = require('underscore'),
    Geometry = require('../lib/Geometry'),
    Transform = require('../lib/Transform'),
    BaseSource = require('./BaseSource'),
    Text = require('./Text'),
    Projection = require('proj4');

var Proj3857 = Projection('EPSG:3857');

var polygonProject = function (coordinates) {
    for (var i = 0; i < coordinates.length; i++) {
        var ringLength = coordinates[i].length;
        for (var ii = 0; ii < ringLength; ii++) {
            coordinates[i][ii] = Proj3857.forward(coordinates[i][ii]);
        }
    }
    return coordinates;
};

var lineProject = function (coordinates) {
    for (var i = 0; i < coordinates.length; i++) {
        coordinates[i] = Proj3857.forward(coordinates[i]);
    }
    return coordinates;
};


var polygonTransform = function (T, coordinates) {
    for (var i = 0; i < coordinates.length; i++) {
        var ringLength = coordinates[i].length;
        for (var ii = 0; ii < ringLength; ii++) {
            coordinates[i][ii] = T.mapVec2(coordinates[i][ii]);
        }
    }
    return coordinates;
};

var lineTransform = function (T, coordinates) {
    for (var i = 0; i < coordinates.length; i++) {
        coordinates[i] = T.mapVec2(coordinates[i]);
    }
    return coordinates;
};


var dataSource;
var renderId;

function GeomItem (data) {
    underscore.extend(this, data);
}

GeomItem.prototype.getGeometry = function () {
    return (new Geometry.Geometry(this.geom));
};

function initData (data) {
    dataSource = new BaseSource();
    for (var i = 0; i < data.length; i++) {
        var item = new GeomItem(data[i]);
        dataSource.addFeature(item);
    }
}

function updateView (startedWith, opt_extent, opt_matrix) {
    if ('startFrame' in workerContext.waend) {
        workerContext.waend.startFrame(startedWith, opt_extent, opt_matrix);
    }
    var T = new Transform(opt_matrix);
    var rf = function (feature) {
        var geom = feature.getGeometry(),
            geomType = geom.getType().toLowerCase(),
            props = feature.properties,
            coordinates = geom.getCoordinates();
        if (geomType && (geomType in workerContext.waend)) {
            // var rid = args[0];
            // console.log('worker', renderId, rid, name);
            workerContext.waend[geomType].call(workerContext, coordinates, props, opt_matrix);
        }
    };

    var features = dataSource.getFeatures(opt_extent);

    var renderBatch = function (start, stop) {
        if (renderId !== startedWith) {
            return;
        }
        for (var j = start; j < stop; j++) {
            if (features[j]) {
                rf(features[j]);
            }
            else {
                return;
            }
        }
    };

    var batchLength = 512;
    if (renderId === startedWith) {
        for (var i = 0; i < features.length; i += batchLength) {
            var stop = Math.min(features.length, i + batchLength);
            if (!features[i] || !features[stop - 1]) {
                break;
            }
            underscore.defer(renderBatch, i, stop);
        }
    }
}


function messageHandler (event) {
    var data = event.data,
        name = data.name,<commit_msg>better startframe<commit_after>/*
 * app/src/libworker.js
 *
 *
 * Copyright (C) 2015  <NAME> <<EMAIL>>
 *
 * License in LICENSE file at the root of the repository.
 *
 */


var workerContext = self;

//< OL3 helpers
workerContext.window = {
    'location' : workerContext.location
};
workerContext.window.document = {
    'implementation':{
        'createDocument': function () { return true; }
    }
};
workerContext.document = workerContext.window.document;
workerContext.Image = function Image() {};
//> END OF OL3 helpers

var underscore = require('underscore'),
    Geometry = require('../lib/Geometry'),
    Transform = require('../lib/Transform'),
    BaseSource = require('./BaseSource'),
    Text = require('./Text'),
    Projection = require('proj4');

var Proj3857 = Projection('EPSG:3857');

var polygonProject = function (coordinates) {
    for (var i = 0; i < coordinates.length; i++) {
        var ringLength = coordinates[i].length;
        for (var ii = 0; ii < ringLength; ii++) {
            coordinates[i][ii] = Proj3857.forward(coordinates[i][ii]);
        }
    }
    return coordinates;
};

var lineProject = function (coordinates) {
    for (var i = 0; i < coordinates.length; i++) {
        coordinates[i] = Proj3857.forward(coordinates[i]);
    }
    return coordinates;
};


var polygonTransform = function (T, coordinates) {
    for (var i = 0; i < coordinates.length; i++) {
        var ringLength = coordinates[i].length;
        for (var ii = 0; ii < ringLength; ii++) {
            coordinates[i][ii] = T.mapVec2(coordinates[i][ii]);
        }
    }
    return coordinates;
};

var lineTransform = function (T, coordinates) {
    for (var i = 0; i < coordinates.length; i++) {
        coordinates[i] = T.mapVec2(coordinates[i]);
    }
    return coordinates;
};


var dataSource;
var renderId;

function GeomItem (data) {
    underscore.extend(this, data);
}

GeomItem.prototype.getGeometry = function () {
    return (new Geometry.Geometry(this.geom));
};

function initData (data) {
    dataSource = new BaseSource();
    for (var i = 0; i < data.length; i++) {
        var item = new GeomItem(data[i]);
        dataSource.addFeature(item);
    }
}

function updateView (startedWith, opt_extent, opt_matrix) {
    var features = dataSource.getFeatures(opt_extent);
    if ('startFrame' in workerContext.waend) {
        workerContext.waend.startFrame(startedWith, opt_extent, opt_matrix, features);
    }
    var T = new Transform(opt_matrix);
    var rf = function (feature) {
        var geom = feature.getGeometry(),
            geomType = geom.getType().toLowerCase(),
            props = feature.properties,
            coordinates = geom.getCoordinates();
        if (geomType && (geomType in workerContext.waend)) {
            // var rid = args[0];
            // console.log('worker', renderId, rid, name);
            workerContext.waend[geomType].call(workerContext, coordinates, props, opt_matrix);
        }
    };


    var renderBatch = function (start, stop) {
        if (renderId !== startedWith) {
            return;
        }
        for (var j = start; j < stop; j++) {
            if (features[j]) {
                rf(features[j]);
            }
            else {
                return;
            }
        }
    };

    var batchLength = 512;
    if (renderId === startedWith) {
        for (var i = 0; i < features.length; i += batchLength) {
            var stop = Math.min(features.length, i + batchLength);
            if (!features[i] || !features[stop - 1]) {
                break;
            }
            underscore.defer(renderBatch, i, stop);
        }
    }
}


function messageHandler (event) {
    var data = event.data,
        name = data.name,
{'fraction_non_alphanumeric': 0.13995697768217263, 'fraction_numerical': 0.010217800484001076, 'mean_word_length': 2.410820724438331, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 11, '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': '5245537', 'n_tokens_mistral': 2314, 'n_tokens_neox': 2226, 'n_words': 549}