<commit_before>var Circle = require('../shapes/Circle')
,   Plane = require('../shapes/Plane')
,   Shape = require('../shapes/Shape')
,   Particle = require('../shapes/Particle')
,   Broadphase = require('../collision/Broadphase')
,   vec2 = require('../math/vec2')

module.exports = SAP1DBroadphase;

/**
 * Sweep and prune broadphase along one axis.
 *
 * @class SAP1DBroadphase
 * @constructor
 * @extends Broadphase
 */
function SAP1DBroadphase(world){
    Broadphase.apply(this);
    var axisList = this.axisList = world.bodies.slice(0);
    this.world = world;
    this.sortFunction = SAP1DBroadphase.sortAxisListX;

    world.on("addBody",function(e){
        axisList.push(e.body);
    }).on("removeBody",function(e){
        var idx = axisList.indexOf(e.body);
        if(idx !== -1)
            axisList.splice(idx,1);
    })
};
SAP1DBroadphase.prototype = new Broadphase();

SAP1DBroadphase.sortAxisListX = function(bodyA,bodyB){
    return (bodyA.position[0]-bodyA.boundingRadius) - (bodyB.position[0]-bodyB.boundingRadius);
};

/**
 * Get the colliding pairs
 * @method getCollisionPairs
 * @param  {World} world
 * @return {Array}
 */
SAP1DBroadphase.prototype.getCollisionPairs = function(world){
    var bodies = this.axisList,
        result = [];

    // Sort the list
    bodies.sort(this.sortFunction);

    // Look through the list
    for(var i=0, N=bodies.length; i!==N; i++){
        var bi = bodies[i];

        for(var j=i+1; j<N; j++){
            var bj = bodies[j],
                boundA1 = bi.position[0]-bi.boundingRadius,
                boundA2 = bi.position[0]+bi.boundingRadius,
                boundB1 = bj.position[0]-bj.boundingRadius,
                boundB2 = bj.position[0]+bj.boundingRadius;

            // Abort if we got gap til the next body
            if( boundB1 > boundA2 ){
                break;
            }

            // If we got overlap, add pair
            if(Broadphase.boundingRadiusCheck(bi,bj))
                result.push(bi,bj);
        }
    }

    return result;<commit_msg>ability to choose axis in SAP1DBroadphase<commit_after>var Circle = require('../shapes/Circle')
,   Plane = require('../shapes/Plane')
,   Shape = require('../shapes/Shape')
,   Particle = require('../shapes/Particle')
,   Broadphase = require('../collision/Broadphase')
,   vec2 = require('../math/vec2')

module.exports = SAP1DBroadphase;

/**
 * Sweep and prune broadphase along one axis.
 *
 * @class SAP1DBroadphase
 * @constructor
 * @extends Broadphase
 * @param {World} world
 */
function SAP1DBroadphase(world){
    Broadphase.apply(this);
    var axisList = this.axisList = world.bodies.slice(0);
    this.world = world;
    this.axisIndex = 0;

    world.on("addBody",function(e){
        axisList.push(e.body);
    }).on("removeBody",function(e){
        var idx = axisList.indexOf(e.body);
        if(idx !== -1)
            axisList.splice(idx,1);
    })
};
SAP1DBroadphase.prototype = new Broadphase();

SAP1DBroadphase.sortAxisListX = function(bodyA,bodyB){
    return (bodyA.position[0]-bodyA.boundingRadius) - (bodyB.position[0]-bodyB.boundingRadius);
};

SAP1DBroadphase.sortAxisListY = function(bodyA,bodyB){
    return (bodyA.position[1]-bodyA.boundingRadius) - (bodyB.position[1]-bodyB.boundingRadius);
};

/**
 * Get the colliding pairs
 * @method getCollisionPairs
 * @param  {World} world
 * @return {Array}
 */
SAP1DBroadphase.prototype.getCollisionPairs = function(world){
    var bodies = this.axisList,
        result = [],
        axisIndex = this.axisIndex;

    // Sort the list
    bodies.sort(axisIndex === 0 ? SAP1DBroadphase.sortAxisListX : SAP1DBroadphase.sortAxisListY );

    // Look through the list
    for(var i=0, N=bodies.length; i!==N; i++){
        var bi = bodies[i];

        for(var j=i+1; j<N; j++){
            var bj = bodies[j],
                boundA1 = bi.position[axisIndex]-bi.boundingRadius,
                boundA2 = bi.position[axisIndex]+bi.boundingRadius,
                boundB1 = bj.position[axisIndex]-bj.boundingRadius,
                boundB2 = bj.position[axisIndex]+bj.boundingRadius;

            // Abort if we got gap til the next body
            if( boundB1 > boundA2 ){
                break;
            }

            // If we got overlap, add pair
            if(Broadphase.boundingRadiusCheck(bi,bj))
                result.push(bi,bj);
        }
    }

    return result;
{'fraction_non_alphanumeric': 0.14334470989761092, 'fraction_numerical': 0.012514220705346985, 'mean_word_length': 2.571080422420796, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6866141', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1433, 'n_words': 269}