<commit_before>(function () {
    TRAFFICSIM_APP.utils = TRAFFICSIM_APP.utils || {};
    TRAFFICSIM_APP.utils.math = TRAFFICSIM_APP.utils.math || {};

    var self = TRAFFICSIM_APP.utils.math;

    TRAFFICSIM_APP.utils.math.distance = function (x1, y1, z1, x2, y2, z2) {
        return Math.sqrt(
            Math.pow(Math.abs(x1 - x2), 2)
            + Math.pow(Math.abs(y1 - y2), 2)
            + Math.pow(Math.abs(z1 - z2), 2)
        );
    };

    TRAFFICSIM_APP.utils.math.radians = function (degrees) {
        return degrees * Math.PI / 180;
    };

    TRAFFICSIM_APP.utils.math.degrees = function (radians) {
        return radians * 180 / Math.PI;
    };

    /** Returns random value between inclusive min and inclusive max.*/
    TRAFFICSIM_APP.utils.math.randomValue = function (min, max) {
        return Math.floor(Math.random() * (max + 1 - min) + min);
    };

    /** Returns a new polygon in which y and z have been swapped.*/
    TRAFFICSIM_APP.utils.math.swapPolygonZAndY = function (polygon) {
        var newPolygon = [];

        polygon.forEach(function(point) {
            newPolygon.push(
                {
                    "x": point.x,
                    "y": point.z,
                    "z": point.y
                })
        });

        return newPolygon;
    };

    /** Returns a new array of points in which y and z have been swapped.*/
    TRAFFICSIM_APP.utils.math.swapPointsZAndY = function (points) {
        var newPoints = [];

        points.forEach(function(point) {
            newPoints.push(
                {
                    "x": point.x,
                    "y": point.z,
                    "z": point.y
                })
        });

        return newPoints;
    };

    /* Uses Separating Axis Theorem (SAT) to find collision between to convex polygons.
     * Polygon points are presented simply as an array in which is item is a map of x and y positions.
     * Polygon edges are created in order.
     * Method explanation for example: http://www.sevenson.com.au/actionscript/sat/ */
    TRAFFICSIM_APP.utils.math.polygonCollision = function (polygon1, polygon2) {
        // TODO
    };

    /** Returns a new collision mask which is rotated around center. */
    TRAFFICSIM_APP.utils.math.rotateCollisionMask = function (collisionMask, newAngle) {
        var newCollisionMask = [];

        collisionMask.forEach(function (point) {
            var defaultAngle = self.angleBetweenPointsWhenYIncreasesDown(point.x, point.y, 0, 0);
            var distanceBetweenPointAndCenter = self.distance(point.x, point.y, 0, 0, 0, 0);

            newCollisionMask.push({
               "x": Math.cos(defaultAngle + newAngle) * distanceBetweenPointAndCenter,
               "y": Math.sin(defaultAngle + newAngle) * distanceBetweenPointAndCenter
            });
        });

        return newCollisionMask;
    };

    /** Returns the positive angle between given points in radians. */
    TRAFFICSIM_APP.utils.math.angleBetweenPoints = function (x1, y1, x2, y2) {
        var radians = Math.atan2(y2 - y1, x2 - x1);

        // No negative angles<commit_msg>Fix problems in math.js.<commit_after>(function () {
    TRAFFICSIM_APP.utils = TRAFFICSIM_APP.utils || {};
    TRAFFICSIM_APP.utils.math = TRAFFICSIM_APP.utils.math || {};

    var self = TRAFFICSIM_APP.utils.math;

    TRAFFICSIM_APP.utils.math.distance = function (x1, y1, z1, x2, y2, z2) {
        return Math.sqrt(
            Math.pow(Math.abs(x1 - x2), 2)
            + Math.pow(Math.abs(y1 - y2), 2)
            + Math.pow(Math.abs(z1 - z2), 2)
        );
    };

    TRAFFICSIM_APP.utils.math.radians = function (degrees) {
        return degrees * Math.PI / 180;
    };

    TRAFFICSIM_APP.utils.math.degrees = function (radians) {
        return radians * 180 / Math.PI;
    };

    /** Returns random value between inclusive min and inclusive max.*/
    TRAFFICSIM_APP.utils.math.randomValue = function (min, max) {
        return Math.floor(Math.random() * (max + 1 - min) + min);
    };

    /** Returns a new polygon in which y and z have been swapped.*/
    TRAFFICSIM_APP.utils.math.swapPolygonZAndY = function (polygon) {
        var newPolygon = [];

        polygon.forEach(function(point) {
            newPolygon.push(
                {
                    "x": point.x,
                    "y": point.z,
                    "z": point.y
                })
        });

        return newPolygon;
    };

    /** Returns a new array of points in which y and z have been swapped.*/
    TRAFFICSIM_APP.utils.math.swapPointsZAndY = function (points) {
        var newPoints = [];

        points.forEach(function(point) {
            newPoints.push(
                {
                    "x": point.x,
                    "y": point.z,
                    "z": point.y
                })
        });

        return newPoints;
    };

    /* Uses Separating Axis Theorem (SAT) to find collision between to convex polygons.
     * Polygon points are presented simply as an array in which is item is a map of x and y positions.
     * Polygon edges are created in order.
     * Method explanation for example: http://www.sevenson.com.au/actionscript/sat/ */
    TRAFFICSIM_APP.utils.math.polygonCollision = function (polygon1, polygon2) {
        // TODO
    };

    /** Returns a new collision mask which is rotated around center. */
    TRAFFICSIM_APP.utils.math.rotateCollisionMask = function (collisionMask, newAngle) {
        var newCollisionMask = [];

        collisionMask.forEach(function (point) {
            var defaultAngle = self.angleBetweenPointsWhenYIncreasesDown(0, 0, point.x, point.y);
            var distanceBetweenPointAndCenter = self.distance(0, 0, 0, point.x, point.y, 0);

            var finalAngle = defaultAngle + newAngle;

            // No more than 360 degrees
            while (finalAngle > Math.PI * 2) {
                finalAngle -= Math.PI * 2;
            }

            newCollisionMask.push({
               "x": Math.cos(finalAngle) * distanceBetweenPointAndCenter,
               "y": Math.sin(finalAngle) * distanceBetweenPointAndCenter
            });
        });

        return newCollisionMask;
    };

    /** Returns the positive angle between given points in radians. */
    TRAFFICSIM_APP.utils.math.angleBetweenPoints = function (x1, y1, x2, y2) {
        var radians = Math.atan2(y2 - y1, x2 - x1);

        // No negative angles
{'fraction_non_alphanumeric': 0.11353371748948762, 'fraction_numerical': 0.01292633546176608, 'mean_word_length': 1.9351005484460695, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1726924', 'n_tokens_mistral': 2080, 'n_tokens_neox': 1911, 'n_words': 478}