<commit_before>/****
 * BeamTrace2D v 1.0
 *
 * =======
 *
 * Copyright (C) 2014 <NAME>. Based on the very basic principles of beam tracing as presented in "Accelerated beam tracing algorithm" by <NAME>, <NAME>, <NAME>, and <NAME>.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * TLDR; Feel free to play with the code, as long as you mention this copyright notice if you publish it somewhere.
 *
 * =======
 *
 * This code is for testing different beam tracing techniques in a simplified 2D environment.
 * - BSP trees (in this case the splitting planes are not aligned) for accelerated ray tracing
 * - Beam trees with polygon ID's
 * - The optimization techniques are absent in this version, so it's not nearly as fast as it would be with them
 *
 */

var BeamTrace2D = {};

/* The class for a wall */
BeamTrace2D.Wall = function(p1,p2)
{
    this.p1 = p1;
    this.p2 = p2;
};
BeamTrace2D.Wall.prototype.draw = function(ctx)
{
    ctx.beginPath();
    ctx.moveTo(this.p1[0], this.p1[1]);
    ctx.lineTo(this.p2[0], this.p2[1]);
    ctx.stroke();
};

/* The class for the listener */
BeamTrace2D.Listener = function(p0)
{
    this.p0 = p0;
}
BeamTrace2D.Listener.prototype.draw = function(ctx)
{
    var old_fill = ctx.fillStyle;
    ctx.beginPath();
    ctx.arc(this.p0[0], this.p0[1], 10, 0, 2*Math.PI);
    ctx.fillStyle = 'yellow';
    ctx.fill();
    ctx.stroke();
    ctx.fillStyle = old_fill;
}

/* The class for the source */
BeamTrace2D.Source = function(p0)
{
    this.p0 = p0;
}
BeamTrace2D.Source.prototype.draw = function(ctx)
{
    var old_fill = ctx.fillStyle;
    ctx.beginPath();
    ctx.arc(this.p0[0],this.p0[1],10,0,2*Math.PI);
    ctx.fillStyle = 'red';
    ctx.fill();
    ctx.stroke();
    ctx.fillStyle = old_fill;
}

/* The solver */
BeamTrace2D.Solver = function(b_walls,b_source,reflection_order) {
    "use strict";
    this.MAX_ORDER = typeof reflection_order !== 'undefined' ? reflection_order - 2 : 4; //Max order of reflections, default 4

    //Private variables (if these are changed the solution will be invalid, source movement requires init)
    var walls = b_walls;
    var source = b_source;
    var bsp;
    var beams;

    /* SOME GENERAL FUNCTIONS */

    /* Returns the intersection point of two lines along with some additional information */
    /* This function is a modified version of: http://jsfiddle.net/justin_c_rounds/Gd2S2/light/ */
    function lineIntersection(x11, y11, x12, y12, x21, y21, x22, y22)
    {
        var denominator, a, b, numerator1, numerator2;
        var result = {
            x: null,
            y: null,
            onLine1: false,
            onLine2: false,
            onRay1: false,
            onRay2: false
        };
        denominator = ((y22 - y21) * (x12 - x11)) - ((x22 - x21) * (y12 - y11));
        if (denominator == 0) {
            return reult;
        }
        a = y11 - y21;
        b = x11 - x21;
        numerator1 = ((x22 - x21) * a) - ((y22 - y21) * b);
        numerator2 = ((x12 - x11) * a) - ((y12 - y11) * b);
        a = numerator1 / denominator;
        b = numerator2 / denominator;
        result.x = x11 + (a * (x12 - x11));
        result.y = y11 + (a * (y12 - y11));
        if (a > 0)
        {
            result.onRay1 = true;
            if(a < 1){
                result.onLine1 = true;
            }
        }
        if(b > 0){
            result.onRay2 = true;
            if(b < 1) {
                result.onLine2 = true;
            }<commit_msg>Fixed typo with previous commit<commit_after>/****
 * BeamTrace2D v 1.0
 *
 * =======
 *
 * Copyright (C) 2014 <NAME>. Based on the very basic principles of beam tracing as presented in "Accelerated beam tracing algorithm" by <NAME>, <NAME>, <NAME>, and <NAME>.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * TLDR; Feel free to play with the code, as long as you mention this copyright notice if you publish it somewhere.
 *
 * =======
 *
 * This code is for testing different beam tracing techniques in a simplified 2D environment.
 * - BSP trees (in this case the splitting planes are not aligned) for accelerated ray tracing
 * - Beam trees with polygon ID's
 * - The optimization techniques are absent in this version, so it's not nearly as fast as it would be with them
 *
 */

var BeamTrace2D = {};

/* The class for a wall */
BeamTrace2D.Wall = function(p1,p2)
{
    this.p1 = p1;
    this.p2 = p2;
};
BeamTrace2D.Wall.prototype.draw = function(ctx)
{
    ctx.beginPath();
    ctx.moveTo(this.p1[0], this.p1[1]);
    ctx.lineTo(this.p2[0], this.p2[1]);
    ctx.stroke();
};

/* The class for the listener */
BeamTrace2D.Listener = function(p0)
{
    this.p0 = p0;
}
BeamTrace2D.Listener.prototype.draw = function(ctx)
{
    var old_fill = ctx.fillStyle;
    ctx.beginPath();
    ctx.arc(this.p0[0], this.p0[1], 10, 0, 2*Math.PI);
    ctx.fillStyle = 'yellow';
    ctx.fill();
    ctx.stroke();
    ctx.fillStyle = old_fill;
}

/* The class for the source */
BeamTrace2D.Source = function(p0)
{
    this.p0 = p0;
}
BeamTrace2D.Source.prototype.draw = function(ctx)
{
    var old_fill = ctx.fillStyle;
    ctx.beginPath();
    ctx.arc(this.p0[0],this.p0[1],10,0,2*Math.PI);
    ctx.fillStyle = 'red';
    ctx.fill();
    ctx.stroke();
    ctx.fillStyle = old_fill;
}

/* The solver */
BeamTrace2D.Solver = function(b_walls,b_source,reflection_order) {
    "use strict";
    this.MAX_ORDER = typeof reflection_order !== 'undefined' ? reflection_order - 2 : 4; //Max order of reflections, default 4

    //Private variables (if these are changed the solution will be invalid, source movement requires init)
    var walls = b_walls;
    var source = b_source;
    var bsp;
    var beams;

    /* SOME GENERAL FUNCTIONS */

    /* Returns the intersection point of two lines along with some additional information */
    /* This function is a modified version of: http://jsfiddle.net/justin_c_rounds/Gd2S2/light/ */
    function lineIntersection(x11, y11, x12, y12, x21, y21, x22, y22)
    {
        var denominator, a, b, numerator1, numerator2;
        var result = {
            x: null,
            y: null,
            onLine1: false,
            onLine2: false,
            onRay1: false,
            onRay2: false
        };
        denominator = ((y22 - y21) * (x12 - x11)) - ((x22 - x21) * (y12 - y11));
        if (denominator == 0) {
            return result;
        }
        a = y11 - y21;
        b = x11 - x21;
        numerator1 = ((x22 - x21) * a) - ((y22 - y21) * b);
        numerator2 = ((x12 - x11) * a) - ((y12 - y11) * b);
        a = numerator1 / denominator;
        b = numerator2 / denominator;
        result.x = x11 + (a * (x12 - x11));
        result.y = y11 + (a * (y12 - y11));
        if (a > 0)
        {
            result.onRay1 = true;
            if(a < 1){
                result.onLine1 = true;
            }
        }
        if(b > 0){
            result.onRay2 = true;
            if(b < 1) {
                result.onLine2 = true;
            }
{'fraction_non_alphanumeric': 0.11206607880343789, 'fraction_numerical': 0.0321464449157272, 'mean_word_length': 2.602734217933253, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '2710033', 'n_tokens_mistral': 2939, 'n_tokens_neox': 2747, 'n_words': 1002}