<commit_before>var World = function() {
	// default values
	this.mBodies = []; // std::vector<Body*>
	this.mJoints = [];
	this.mParticleCannons = [];
	this.mRays = [];
	this._triggerFields = [];
	
	this.mWorldLimits = new AABB(); // AABB
	this.mWorldSize = new Vector2(0.0, 0.0); // Vector2
	this.mWorldGridStep = new Vector2(0.0, 0.0); // Vector2
		
	this.mPenetrationThreshold = 0.0; // float
	this.mPenetrationCount = 0; // int
	
	this.mCollisionList = []; //std::vector<BodyCollisionInfo>
	this.collisionPool = new ObjectPool(BodyCollisionInfo);

	this.contactManager = new ContactManager();

	this.setWorldLimits(new Vector2(-20,-20), new Vector2(20,20));
		
	this.mPenetrationThreshold = 0.3;
	this.mPenetrationCount = 0;
	
	this.gravitation = World.defaultGravitation.copy();
	var that = this;
	this.gravitationCallback = function() { that.applyGravitationTo.apply(that, arguments); };
};

World.defaultGravitation = new Vector2(0, -9.81);

World.prototype.setWorldLimits = function( min, max) { //  const Vector2& , const Vector2& 
	this.mWorldLimits = new AABB(min, max);
	this.mWorldSize = max.sub(min);
	this.mWorldGridStep = this.mWorldSize / 32;
		
	// update bitmasks for all bodies.
	for(var i = 0; i < this.mBodies.length; i++)
		this.updateBodyBitmask(this.mBodies[i]);
};

// Idea: Devide the world into a 32x32 grid
// determine in which grid spaces the object is present
// adjust its bitmask like this
World.prototype.updateBodyBitmask = function(body) { // Body* 
	var box = body.getAABB(); // AABB
	
	//var minX = Math.floor((box.Min.x - mWorldLimits.Min.x) / this.mWorldGridStep.x); // int
	//var maxX = Math.floor((box.Max.x - mWorldLimits.Min.x) / this.mWorldGridStep.x); // int
	
	//if (minX < 0) { minX = 0; } else if (minX > 31) { minX = 31; }
	//if (maxX < 0) { maxX = 0; } else if (maxX > 31) { maxX = 31; }
	
	// determine minimum and maximum grid 
	var minY = Math.floor((
		box.Min.y - 
		this.mWorldLimits.Min.y
	) / this.mWorldGridStep.y); // int
	var maxY = Math.floor((box.Max.y - this.mWorldLimits.Min.y) / this.mWorldGridStep.y); // int

	// Adjust if object have fallen out of the world
	if (minY < 0) { minY = 0; } else if (minY > 31) { minY = 31; };
	if (maxY < 0) { maxY = 0; } else if (maxY > 31) { maxY = 31; };
	
	
	//body->mBitMaskX.clear();
	//for (int i = minX; i <= maxX; i++)
	//	body->mBitMaskX.setOn(i);
	
	
	body.mBitMaskY.clear();
	for(var i = minY; i <= maxY; i++)
		body.mBitMaskY.setOn(i);
	
	//Console.WriteLine("Body bitmask: minX{0} maxX{1} minY{2} maxY{3}", minX, maxX, minY, minY, maxY);
};

World.prototype.addBody = function(b) { // Body
	DEBUG("addBody:", b);

	// check for already existing.
	var exists = false; // bool
	for(var i = 0; i < this.mBodies.length; i++)
		if(this.mBodies[i] == b) {
			exists = true;
			break;
		};
	
	// do not add an already existing body
	if (!exists) {
		this.mBodies.push(b);
		// TODO: introduce possibility to not be affected by gravity
		b.addExternalForce(this.gravitationCallback);
	}
};

World.prototype.removeBody = function(b) { // Body
	var index = this.mBodies.indexOf(b);
	if (index !== - 1) {
		this.mBodies.splice( index, 1 );
	}
};

World.prototype.addJoint = function(j) { // Joint
	DEBUG("addJoint:", j);

	// check for already existing.
	var exists = false; // bool
	for(var i = 0; i < this.mJoints.length; i++)
		if(this.mJoints[i] == j) {
			exists = true;
			break;
		};
	
	// do not add an already existing joint
	if (!exists) {
		this.mJoints.push(j);
	}
};

World.prototype.removeJoint = function(j) { // Joint
	var index = this.mJoints.indexOf(j);
	if (index !== - 1) {
		this.mJoints.splice( index, 1 );
	}
};

World.prototype.addParticleCannon = function(pc) { // ParticleCannon
	DEBUG("addParticleCannon:", pc);

	// check for already existing.
	var exists = false; // bool
	for(var i = 0; i < this.mParticleCannons.length; i++)
		if(this.mParticleCannons[i] == pc) {
			exists = true;
			break;
		};
	
	// do not add an already existing particle cannon
	if (!exists) {
		this.mParticleCannons.push(pc);
	}
};

World.prototype.addRay = function(r) { // Joint
	DEBUG("addRay:", r);

	// check for already existing.
	var exists = false; // bool
	for(var i = 0; i < this.mRays.length; i++)
		if(this.mRays[i] == r) {
			exists = true;
			break;
		};
	
	// do not add an already existing joint
	if (!exists) {
		this.mRays.push(r);
	}
};

World.prototype.addTriggerField = function(field) { // TriggerField
	DEBUG("addTriggerField:", field);

	// check for already existing.
	var exists = false; // bool
	for(var i = 0; i < this._triggerFields.length; i++)
		if(this._triggerFields[i] == field) {
			exists = true;
			break;
		};
	
	// do not add an already existing fields
	if (!exists) {
		this._triggerFields.push(field);
	}
};

World.prototype.removeTriggerField = function(field) { // TriggerField
	var index = this._triggerFields.indexOf(field);
	if (index !== - 1) {
		this._triggerFields.splice( index, 1 );
	}
};

World.prototype.getBodies = function() {
	return this.mBodies;
};

World.prototype.getBody = function(index) { // int, returns Body
	if ((index >= 0) && (index < this.mBodies.length))
		return this.mBodies[index];
	return undefined;<commit_msg>unabled debug print for the creation of world objects<commit_after>var World = function() {
	// default values
	this.mBodies = []; // std::vector<Body*>
	this.mJoints = [];
	this.mParticleCannons = [];
	this.mRays = [];
	this._triggerFields = [];
	
	this.mWorldLimits = new AABB(); // AABB
	this.mWorldSize = new Vector2(0.0, 0.0); // Vector2
	this.mWorldGridStep = new Vector2(0.0, 0.0); // Vector2
		
	this.mPenetrationThreshold = 0.0; // float
	this.mPenetrationCount = 0; // int
	
	this.mCollisionList = []; //std::vector<BodyCollisionInfo>
	this.collisionPool = new ObjectPool(BodyCollisionInfo);

	this.contactManager = new ContactManager();

	this.setWorldLimits(new Vector2(-20,-20), new Vector2(20,20));
		
	this.mPenetrationThreshold = 0.3;
	this.mPenetrationCount = 0;
	
	this.gravitation = World.defaultGravitation.copy();
	var that = this;
	this.gravitationCallback = function() { that.applyGravitationTo.apply(that, arguments); };
};

World.defaultGravitation = new Vector2(0, -9.81);

World.prototype.setWorldLimits = function( min, max) { //  const Vector2& , const Vector2& 
	this.mWorldLimits = new AABB(min, max);
	this.mWorldSize = max.sub(min);
	this.mWorldGridStep = this.mWorldSize / 32;
		
	// update bitmasks for all bodies.
	for(var i = 0; i < this.mBodies.length; i++)
		this.updateBodyBitmask(this.mBodies[i]);
};

// Idea: Devide the world into a 32x32 grid
// determine in which grid spaces the object is present
// adjust its bitmask like this
World.prototype.updateBodyBitmask = function(body) { // Body* 
	var box = body.getAABB(); // AABB
	
	//var minX = Math.floor((box.Min.x - mWorldLimits.Min.x) / this.mWorldGridStep.x); // int
	//var maxX = Math.floor((box.Max.x - mWorldLimits.Min.x) / this.mWorldGridStep.x); // int
	
	//if (minX < 0) { minX = 0; } else if (minX > 31) { minX = 31; }
	//if (maxX < 0) { maxX = 0; } else if (maxX > 31) { maxX = 31; }
	
	// determine minimum and maximum grid 
	var minY = Math.floor((
		box.Min.y - 
		this.mWorldLimits.Min.y
	) / this.mWorldGridStep.y); // int
	var maxY = Math.floor((box.Max.y - this.mWorldLimits.Min.y) / this.mWorldGridStep.y); // int

	// Adjust if object have fallen out of the world
	if (minY < 0) { minY = 0; } else if (minY > 31) { minY = 31; };
	if (maxY < 0) { maxY = 0; } else if (maxY > 31) { maxY = 31; };
	
	
	//body->mBitMaskX.clear();
	//for (int i = minX; i <= maxX; i++)
	//	body->mBitMaskX.setOn(i);
	
	
	body.mBitMaskY.clear();
	for(var i = minY; i <= maxY; i++)
		body.mBitMaskY.setOn(i);
	
	//Console.WriteLine("Body bitmask: minX{0} maxX{1} minY{2} maxY{3}", minX, maxX, minY, minY, maxY);
};

World.prototype.addBody = function(b) { // Body
	//DEBUG("addBody:", b);

	// check for already existing.
	var exists = false; // bool
	for(var i = 0; i < this.mBodies.length; i++)
		if(this.mBodies[i] == b) {
			exists = true;
			break;
		};
	
	// do not add an already existing body
	if (!exists) {
		this.mBodies.push(b);
		// TODO: introduce possibility to not be affected by gravity
		b.addExternalForce(this.gravitationCallback);
	}
};

World.prototype.removeBody = function(b) { // Body
	var index = this.mBodies.indexOf(b);
	if (index !== - 1) {
		this.mBodies.splice( index, 1 );
	}
};

World.prototype.addJoint = function(j) { // Joint
	//DEBUG("addJoint:", j);

	// check for already existing.
	var exists = false; // bool
	for(var i = 0; i < this.mJoints.length; i++)
		if(this.mJoints[i] == j) {
			exists = true;
			break;
		};
	
	// do not add an already existing joint
	if (!exists) {
		this.mJoints.push(j);
	}
};

World.prototype.removeJoint = function(j) { // Joint
	var index = this.mJoints.indexOf(j);
	if (index !== - 1) {
		this.mJoints.splice( index, 1 );
	}
};

World.prototype.addParticleCannon = function(pc) { // ParticleCannon
	//DEBUG("addParticleCannon:", pc);

	// check for already existing.
	var exists = false; // bool
	for(var i = 0; i < this.mParticleCannons.length; i++)
		if(this.mParticleCannons[i] == pc) {
			exists = true;
			break;
		};
	
	// do not add an already existing particle cannon
	if (!exists) {
		this.mParticleCannons.push(pc);
	}
};

World.prototype.addRay = function(r) { // Joint
	//DEBUG("addRay:", r);

	// check for already existing.
	var exists = false; // bool
	for(var i = 0; i < this.mRays.length; i++)
		if(this.mRays[i] == r) {
			exists = true;
			break;
		};
	
	// do not add an already existing joint
	if (!exists) {
		this.mRays.push(r);
	}
};

World.prototype.addTriggerField = function(field) { // TriggerField
	//DEBUG("addTriggerField:", field);

	// check for already existing.
	var exists = false; // bool
	for(var i = 0; i < this._triggerFields.length; i++)
		if(this._triggerFields[i] == field) {
			exists = true;
			break;
		};
	
	// do not add an already existing fields
	if (!exists) {
		this._triggerFields.push(field);
	}
};

World.prototype.removeTriggerField = function(field) { // TriggerField
	var index = this._triggerFields.indexOf(field);
	if (index !== - 1) {
		this._triggerFields.splice( index, 1 );
	}
};

World.prototype.getBodies = function() {
	return this.mBodies;
};

World.prototype.getBody = function(index) { // int, returns Body
	if ((index >= 0) && (index < this.mBodies.length))
		return this.mBodies[index];
	return undefined;
{'fraction_non_alphanumeric': 0.1669221924108854, 'fraction_numerical': 0.015714833269451896, 'mean_word_length': 3.282724661469019, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 21, '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': '470654', 'n_tokens_mistral': 4205, 'n_tokens_neox': 3851, 'n_words': 935}