<commit_before>var mouseDown = false;
var lastMouse = null;
var lastPhi = 0.;
var lastTheta = 0.;
var activeIndex = 0;
getCanvasCoordinates = function(event) {
    var coordinates = {};
    var rect = core.canvas.getBoundingClientRect();
    coordinates.x = event.clientX - rect.left;
    coordinates.y = event.clientY - rect.top;
    return coordinates;
}
function handleMouseDown(event) {
    mouseDown = true;
    var canvasCoordinates = getCanvasCoordinates(event);

    var vpm = core.projectionMatrix[0].inverse();
    // var vm = core.viewProjectionMatrix[0].inverse();

    var solarCoordinates = vpm.multiply($V([ 2. * (canvasCoordinates.x / core.viewport.totalWidth - 0.5), 2. * (canvasCoordinates.y / core.viewport.totalWidth - 0.5), 0., 0. ]));
    var solarCoordinates3Dz = Math.sqrt(1 - solarCoordinates.dot(solarCoordinates));
    var solarCoordinates3D = solarCoordinates.dup();
    solarCoordinates3D.elements[2] = solarCoordinates3Dz;
    // var solarCoordinates3D = vm.multiply($V([ 2. * (canvasCoordinates.x /
    // core.viewport.totalWidth - 0.5), 2. * (canvasCoordinates.y /
    // core.viewport.totalWidth - 0.5), 0., 0. ]));
    // solarCoordinates3D = $V([ solarCoordinates3D.elements[0],
    // solarCoordinates3D.elements[1], solarCoordinates3D.elements[2] ]);
    document.getElementById("canvasCoordinates").innerHTML = "" + canvasCoordinates.x + " " + canvasCoordinates.x;
    document.getElementById("solarCoordinates").innerHTML = "" + solarCoordinates.elements[0] + " " + solarCoordinates.elements[1] + " " + solarCoordinates.elements[2] + " " + solarCoordinates.elements[3];
    document.getElementById("solarCoordinates3D").innerHTML = "" + solarCoordinates3D.elements[0] + " " + solarCoordinates3D.elements[1] + " " + solarCoordinates3D.elements[2];
    varsign = 1.;

    lastPhi = Math.atan(solarCoordinates3D.elements[0] / solarCoordinates3D.elements[2]);
    lastTheta = Math.acos(solarCoordinates3D.elements[1]) - Math.PI / 2.;
    document.getElementById("thetaPhi").innerHTML = "phi:" + (lastPhi + core.phi) * 180. / Math.PI + " theta:" + (lastTheta + core.theta) * 180. / Math.PI;
    document.getElementById("L0B0").innerHTML = "L0:" + (lastPhi + core.phi + core.L0) * 180. / Math.PI + " B0:" + (lastTheta + core.theta + core.B0) * 180. / Math.PI;

    lastMouse = solarCoordinates;

    var vcl = core.viewport.totalWidth / core.viewport.columns;
    var vrl = core.viewport.totalHeight / core.viewport.rows;
    var quit = false;

    for (var ll = 0; !quit && ll < core.viewport.columns; ll++) {
        for (var rr = 0; !quit && rr < core.viewport.rows; rr++) {
            if (canvasCoordinates.x >= ll * vcl && canvasCoordinates.x <= ll * vcl + vcl && canvasCoordinates.y >= rr * vrl && canvasCoordinates.y <= rr * vrl + vrl) {
                quit = true;
                activeIndex = core.viewport.columns * (core.viewport.rows - 1 - rr) + ll;
                console.log(activeIndex);
            }
        }
    }
}

function handleMouseUp(event) {
    mouseDown = false;
}

function handleMouseMove(event) {
    if (!mouseDown) {
        return;
    }
    if (core.mode)
        var canvasCoordinates = getCanvasCoordinates(event);
    var vpm = core.projectionMatrix[activeIndex].inverse();

    var solarCoordinates = vpm.multiply($V([ 2. * (canvasCoordinates.x / core.viewport.totalWidth - 0.5), 2. * (canvasCoordinates.y / core.viewport.totalWidth - 0.5), 0., 0. ]));
    var solarCoordinates3Dz = Math.sqrt(1 - solarCoordinates.dot(solarCoordinates));

    var solarCoordinates3D = solarCoordinates.dup();
    solarCoordinates3D.elements[2] = solarCoordinates3Dz;

    var deltaX = solarCoordinates.elements[0] - lastMouse.elements[0];
    var deltaY = -(solarCoordinates.elements[1] - lastMouse.elements[1]);
    phi = Math.atan(solarCoordinates3D.elements[0] / solarCoordinates3D.elements[2]);
    theta = Math.acos(solarCoordinates3D.elements[1]) - Math.PI / 2.;
    M1 = Matrix.Rotation((lastTheta - theta), $V([ 1, 0, 0 ]));
    M2 = Matrix.Rotation(-(lastPhi - phi), $V([ 0, 1, 0 ]));
    M = M2.x(M1);
    if (!(isNaN(phi) || isNaN(lastPhi) || isNaN(theta) || isNaN(lastTheta))) {
        core.theta += (lastTheta - theta);
        core.phi += (lastPhi - phi);
    }

    lastPhi = phi;
    lastTheta = theta;
}

handleMouseWheel = function(event) {

    var target = event.target || event.srcElement;
    var rect = target.getBoundingClientRect();<commit_msg>update mouse interaction<commit_after>var mouseDown = false;
var lastMouse = null;
var lastPhi = 0.;
var lastTheta = 0.;
var activeIndex = 0;
getCanvasCoordinates = function(event) {
    var coordinates = {};
    var rect = core.canvas.getBoundingClientRect();
    coordinates.x = event.clientX - rect.left;
    coordinates.y = event.clientY - rect.top;
    return coordinates;
}
function handleMouseDown(event) {
    mouseDown = true;
    var canvasCoordinates = getCanvasCoordinates(event);

    var vpm = core.projectionMatrix[0].inverse();
    // var vm = core.viewProjectionMatrix[0].inverse();

    var solarCoordinates = vpm.multiply($V([ 2. * (canvasCoordinates.x / core.viewport.totalWidth - 0.5), 2. * (canvasCoordinates.y / core.viewport.totalWidth - 0.5), 0., 0. ]));
    var solarCoordinates3Dz = Math.sqrt(1 - solarCoordinates.dot(solarCoordinates));
    var solarCoordinates3D = solarCoordinates.dup();
    solarCoordinates3D.elements[2] = solarCoordinates3Dz;
    // var solarCoordinates3D = vm.multiply($V([ 2. * (canvasCoordinates.x /
    // core.viewport.totalWidth - 0.5), 2. * (canvasCoordinates.y /
    // core.viewport.totalWidth - 0.5), 0., 0. ]));
    // solarCoordinates3D = $V([ solarCoordinates3D.elements[0],
    // solarCoordinates3D.elements[1], solarCoordinates3D.elements[2] ]);
    document.getElementById("canvasCoordinates").innerHTML = "" + canvasCoordinates.x + " " + canvasCoordinates.x;
    document.getElementById("solarCoordinates").innerHTML = "" + solarCoordinates.elements[0] + " " + solarCoordinates.elements[1] + " " + solarCoordinates.elements[2] + " " + solarCoordinates.elements[3];
    document.getElementById("solarCoordinates3D").innerHTML = "" + solarCoordinates3D.elements[0] + " " + solarCoordinates3D.elements[1] + " " + solarCoordinates3D.elements[2];
    varsign = 1.;

    lastPhi = Math.atan(solarCoordinates3D.elements[0] / solarCoordinates3D.elements[2]);
    lastTheta = Math.acos(solarCoordinates3D.elements[1]) - Math.PI / 2.;
    document.getElementById("thetaPhi").innerHTML = "phi:" + (lastPhi + core.phi) * 180. / Math.PI + " theta:" + (lastTheta + core.theta) * 180. / Math.PI;
    document.getElementById("L0B0").innerHTML = "L0:" + (lastPhi + core.phi + core.L0) * 180. / Math.PI + " B0:" + (lastTheta + core.theta + core.B0) * 180. / Math.PI;

    lastMouse = solarCoordinates;

    var vcl = core.viewport.totalWidth / core.viewport.columns;
    var vrl = core.viewport.totalHeight / core.viewport.rows;
    var quit = false;

    for (var ll = 0; !quit && ll < core.viewport.columns; ll++) {
        for (var rr = 0; !quit && rr < core.viewport.rows; rr++) {
            if (canvasCoordinates.x >= ll * vcl && canvasCoordinates.x <= ll * vcl + vcl && canvasCoordinates.y >= rr * vrl && canvasCoordinates.y <= rr * vrl + vrl) {
                quit = true;
                activeIndex = core.viewport.columns * (core.viewport.rows - 1 - rr) + ll;
                console.log(activeIndex);
            }
        }
    }
}

function handleMouseUp(event) {
    mouseDown = false;
}

function handleMouseMove(event) {
    if (!mouseDown) {
        return;
    }
    if (core.viewport.modes[activeIndex] === '3D') {
        handelMouseMove3D(event);
    }
}

function handelMouseMove3D(event) {
    var canvasCoordinates = getCanvasCoordinates(event);
    var vpm = core.projectionMatrix[activeIndex].inverse();

    var solarCoordinates = vpm.multiply($V([ 2. * (canvasCoordinates.x / core.viewport.totalWidth - 0.5), 2. * (canvasCoordinates.y / core.viewport.totalWidth - 0.5), 0., 0. ]));
    var solarCoordinates3Dz = Math.sqrt(1 - solarCoordinates.dot(solarCoordinates));

    var solarCoordinates3D = solarCoordinates.dup();
    solarCoordinates3D.elements[2] = solarCoordinates3Dz;

    var deltaX = solarCoordinates.elements[0] - lastMouse.elements[0];
    var deltaY = -(solarCoordinates.elements[1] - lastMouse.elements[1]);
    phi = Math.atan(solarCoordinates3D.elements[0] / solarCoordinates3D.elements[2]);
    theta = Math.acos(solarCoordinates3D.elements[1]) - Math.PI / 2.;
    M1 = Matrix.Rotation((lastTheta - theta), $V([ 1, 0, 0 ]));
    M2 = Matrix.Rotation(-(lastPhi - phi), $V([ 0, 1, 0 ]));
    M = M2.x(M1);
    if (!(isNaN(phi) || isNaN(lastPhi) || isNaN(theta) || isNaN(lastTheta))) {
        core.theta += (lastTheta - theta);
        core.phi += (lastPhi - phi);
    }

    lastPhi = phi;
    lastTheta = theta;
}

handleMouseWheel = function(event) {

    var target = event.target || event.srcElement;
    var rect = target.getBoundingClientRect();
{'fraction_non_alphanumeric': 0.15356347438752785, 'fraction_numerical': 0.024832962138084634, 'mean_word_length': 3.338647342995169, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '72835', 'n_tokens_mistral': 3097, 'n_tokens_neox': 2961, 'n_words': 555}