<commit_before>"use strict";


var vector = require("../common/vector");
var Loop = require("../common/loop");


// returns center point between first and second touch point
function getCenterPosition(vector, boundingBox, firstTouch, secondTouch) {
    vector.x = 0.5 * (secondTouch.pageX - firstTouch.pageX) + firstTouch.pageX - boundingBox.left;
    vector.y = 0.5 * (secondTouch.pageY - firstTouch.pageY) + firstTouch.pageY - boundingBox.top;
    vector.z = 0;
    return vector;
}

// returns distance between to touch-points
function getLengthOfLine(firstTouch, secondTouch) {
    var x = secondTouch.pageX - firstTouch.pageX;
    var y = secondTouch.pageY - firstTouch.pageY;
    return Math.sqrt(x*x + y*y);
}


function touch($element, boundingBox, onStart, onInput, onEnd) {
    var config = {
        activated: true
    };

    var currentTouches = 0;
    var currentPosition = vector.create();
    var previousPosition = vector.create();
    var inputVector = vector.create();

    var currentLength = 0;
    var previousLength = 0;


    var Processor = {

        currentEvent: null,

        start: function () {
            this.loopState = Loop.CONTINUE;
            Loop.add(this);
        },

        stop: function () {
            this.loopState = Loop.EXIT;
        },

        calculate: function () {
            var event = this.currentEvent;
            if (event == null) {
                return;
            }

            previousLength = currentLength;
            previousPosition.set(currentPosition);

            if (event.touches.length > 1) {
                currentLength = getLengthOfLine(event.touches[0], event.touches[1]);
                currentPosition = getCenterPosition(currentPosition, boundingBox, event.touches[0], event.touches[1]);

                inputVector.setDelta(currentPosition, previousPosition);
                // z = scale factor
                inputVector.z = previousLength === 0 ? 1 : currentLength / previousLength;

            } else {
                currentPosition.setValues(
                    event.touches[0].pageX - boundingBox.left,
                    event.touches[0].pageY - boundingBox.top,
                    0
                );
                inputVector.setDelta(currentPosition, previousPosition);
                inputVector.z = 1;
            }

            this.currentEvent = null;
            onInput(inputVector, currentPosition);
            return this.loopState;
        },

        render: Function.prototype
    };


    function startSingleTouch(touchItem) {
        currentLength = 0;
        previousLength = 0;
        currentPosition.setValues(touchItem.pageX - boundingBox.left, touchItem.pageY - boundingBox.top, 0);
        previousPosition.set(currentPosition);
    }

    function startDoubleTouch(firstTouch, secondTouch) {
        currentLength = getLengthOfLine(firstTouch, secondTouch);
        currentPosition = getCenterPosition(currentPosition, boundingBox, firstTouch, secondTouch);
        previousPosition.set(currentPosition);
    }

    function startTouch(event) {
        event.preventDefault();
        considerStart = false;
        currentTouches = event.touches.length;

        if (event.touches.length === 1) {
            startSingleTouch(event.touches[0]);

        } else {
            startDoubleTouch(event.touches[0], event.touches[1]);
        }

        Processor.start();
        onStart(currentPosition);
    }

    function endTouch(event) {
        // abort if inactive
        if (currentTouches === 0) {
            return;
        }

        // if touch remains, change mode
        if (event.touches.length === 1) {
            // reset
            startSingleTouch(event.touches[0]);
            onStart(currentPosition);
            return;
        }

        // else end input action
        considerStart = false;<commit_msg>Fix remove canceled event for a deactivated viewpane<commit_after>"use strict";


var vector = require("../common/vector");
var Loop = require("../common/loop");


// returns center point between first and second touch point
function getCenterPosition(vector, boundingBox, firstTouch, secondTouch) {
    vector.x = 0.5 * (secondTouch.pageX - firstTouch.pageX) + firstTouch.pageX - boundingBox.left;
    vector.y = 0.5 * (secondTouch.pageY - firstTouch.pageY) + firstTouch.pageY - boundingBox.top;
    vector.z = 0;
    return vector;
}

// returns distance between to touch-points
function getLengthOfLine(firstTouch, secondTouch) {
    var x = secondTouch.pageX - firstTouch.pageX;
    var y = secondTouch.pageY - firstTouch.pageY;
    return Math.sqrt(x*x + y*y);
}


function touch($element, boundingBox, onStart, onInput, onEnd) {
    var config = {
        activated: true
    };

    var currentTouches = 0;
    var currentPosition = vector.create();
    var previousPosition = vector.create();
    var inputVector = vector.create();

    var currentLength = 0;
    var previousLength = 0;


    var Processor = {

        currentEvent: null,

        start: function () {
            this.loopState = Loop.CONTINUE;
            Loop.add(this);
        },

        stop: function () {
            this.loopState = Loop.EXIT;
        },

        calculate: function () {
            var event = this.currentEvent;
            if (event == null) {
                return;
            }

            previousLength = currentLength;
            previousPosition.set(currentPosition);

            if (event.touches.length > 1) {
                currentLength = getLengthOfLine(event.touches[0], event.touches[1]);
                currentPosition = getCenterPosition(currentPosition, boundingBox, event.touches[0], event.touches[1]);

                inputVector.setDelta(currentPosition, previousPosition);
                // z = scale factor
                inputVector.z = previousLength === 0 ? 1 : currentLength / previousLength;

            } else {
                currentPosition.setValues(
                    event.touches[0].pageX - boundingBox.left,
                    event.touches[0].pageY - boundingBox.top,
                    0
                );
                inputVector.setDelta(currentPosition, previousPosition);
                inputVector.z = 1;
            }

            this.currentEvent = null;
            onInput(inputVector, currentPosition);
            return this.loopState;
        },

        render: Function.prototype
    };


    function startSingleTouch(touchItem) {
        currentLength = 0;
        previousLength = 0;
        currentPosition.setValues(touchItem.pageX - boundingBox.left, touchItem.pageY - boundingBox.top, 0);
        previousPosition.set(currentPosition);
    }

    function startDoubleTouch(firstTouch, secondTouch) {
        currentLength = getLengthOfLine(firstTouch, secondTouch);
        currentPosition = getCenterPosition(currentPosition, boundingBox, firstTouch, secondTouch);
        previousPosition.set(currentPosition);
    }

    function startTouch(event) {
        config.activated && event.preventDefault();
        considerStart = false;
        currentTouches = event.touches.length;

        if (event.touches.length === 1) {
            startSingleTouch(event.touches[0]);

        } else {
            startDoubleTouch(event.touches[0], event.touches[1]);
        }

        Processor.start();
        onStart(currentPosition);
    }

    function endTouch(event) {
        // abort if inactive
        if (currentTouches === 0) {
            return;
        }

        // if touch remains, change mode
        if (event.touches.length === 1) {
            // reset
            startSingleTouch(event.touches[0]);
            onStart(currentPosition);
            return;
        }

        // else end input action
        considerStart = false;
{'fraction_non_alphanumeric': 0.10252143862792781, 'fraction_numerical': 0.007423524894406758, 'mean_word_length': 2.0487709715177527, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2812298', 'n_tokens_mistral': 2198, 'n_tokens_neox': 2055, 'n_words': 443}