<commit_before>﻿BlockGrid = function(cols, rows)
{
	this.grid = [];
	this.tiles = new Tilemap(new Vector2i(16, 8), new Vector2i(cols, rows));
	this.blockImage = null;
	this.blockSwatches = [];
	this.tileSize = new Vector2f(this.tiles.tileWidth, this.tiles.tileHeight);

	var gridSize = cols * rows;

	for (var i = 0; i < gridSize; ++i)
	{
		this.grid.push(0);
	}

	this.localBounds = new RectF(0, 0, this.tiles.width, this.tiles.height);

	this.getPhases = function() { return this.blockSwatches.length; }
	this.getColumns = function() { return this.tiles.columns; }
	this.getRows = function() { return this.tiles.rows; }
	this.getGrid = function(col, row) { return this.grid[col + row * this.getColumns()]; }
	
	this.setGrid = function(col, row, value)
	{
		if (value < 0 || value > this.getPhases())
		{
			return;
		}

		var index = col + row * this.getColumns();

		if (this.grid[index] == value)
		{
			return;
		}

		this.grid[index] = value;

		if (value > 0)
		{
			this.tiles.setTile(col, row, this.blockImage, this.blockSwatches[value - 1]);
		}
		else
		{
			this.tiles.clearTile(col, row);
		}
	}

	this.isColliding = function(pos, phase)
	{
		var block = pos.toVector2i();
		var hit = false;

		if (pos.x >= 0 && pos.x < this.getColumns() && pos.y >= 0 && pos.y <= this.getRows())
		{
			var p = this.getGrid(Math.floor(pos.x), Math.floor(pos.y));
			phase = Math.max(p, phase);
			hit = p > 0;
		}

		return { hit : hit, block : block, phase : phase }
	}

	var contains = function(arr, value)
	{
		for (var i = 0; i < arr.length; ++i)
		{
			if (arr[i].equals(value)) return true;
		}

		return false;
	}

	this.checkForCollision = function(ball)
	{
		var hit = false;
		var normal = Vector2f.ZERO;
		var phase = 0;

		//if (!ball.bounds.intersects(this.bounds)) return false;

		var bounds = ball.bounds.subVector2f(this.position).divVector2f(this.tileSize);
		var collided = [];
		var collideRes;

		collideRes = this.isColliding(bounds.topLeft, phase);

		if (collideRes.hit)
		{
			hit = true;
			normal = normal.add(new Vector2f(1, -1));
			phase = collideRes.phase;

			if (!contains(collided, collideRes.block)) collided.push(collideRes.block);
		}

		collideRes = this.isColliding(bounds.topRight, phase);

		if (collideRes.hit)
		{
			hit = true;
			normal = normal.add(new Vector2f(-1, -1));<commit_msg>Using correct Rect operator names<commit_after>﻿BlockGrid = function(cols, rows)
{
	this.grid = [];
	this.tiles = new Tilemap(new Vector2i(16, 8), new Vector2i(cols, rows));
	this.blockImage = null;
	this.blockSwatches = [];
	this.tileSize = new Vector2f(this.tiles.tileWidth, this.tiles.tileHeight);

	var gridSize = cols * rows;

	for (var i = 0; i < gridSize; ++i)
	{
		this.grid.push(0);
	}

	this.localBounds = new RectF(0, 0, this.tiles.width, this.tiles.height);

	this.getPhases = function() { return this.blockSwatches.length; }
	this.getColumns = function() { return this.tiles.columns; }
	this.getRows = function() { return this.tiles.rows; }
	this.getGrid = function(col, row) { return this.grid[col + row * this.getColumns()]; }
	
	this.setGrid = function(col, row, value)
	{
		if (value < 0 || value > this.getPhases())
		{
			return;
		}

		var index = col + row * this.getColumns();

		if (this.grid[index] == value)
		{
			return;
		}

		this.grid[index] = value;

		if (value > 0)
		{
			this.tiles.setTile(col, row, this.blockImage, this.blockSwatches[value - 1]);
		}
		else
		{
			this.tiles.clearTile(col, row);
		}
	}

	this.isColliding = function(pos, phase)
	{
		var block = pos.toVector2i();
		var hit = false;

		if (pos.x >= 0 && pos.x < this.getColumns() && pos.y >= 0 && pos.y <= this.getRows())
		{
			var p = this.getGrid(Math.floor(pos.x), Math.floor(pos.y));
			phase = Math.max(p, phase);
			hit = p > 0;
		}

		return { hit : hit, block : block, phase : phase }
	}

	var contains = function(arr, value)
	{
		for (var i = 0; i < arr.length; ++i)
		{
			if (arr[i].equals(value)) return true;
		}

		return false;
	}

	this.checkForCollision = function(ball)
	{
		var hit = false;
		var normal = Vector2f.ZERO;
		var phase = 0;

		//if (!ball.bounds.intersects(this.bounds)) return false;

		var bounds = ball.bounds.sub(this.position).divVec(this.tileSize);
		var collided = [];
		var collideRes;

		collideRes = this.isColliding(bounds.topLeft, phase);

		if (collideRes.hit)
		{
			hit = true;
			normal = normal.add(new Vector2f(1, -1));
			phase = collideRes.phase;

			if (!contains(collided, collideRes.block)) collided.push(collideRes.block);
		}

		collideRes = this.isColliding(bounds.topRight, phase);

		if (collideRes.hit)
		{
			hit = true;
			normal = normal.add(new Vector2f(-1, -1));
{'fraction_non_alphanumeric': 0.16391332332117572, 'fraction_numerical': 0.011585496674533362, 'mean_word_length': 3.3047091412742384, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2825665', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1765, 'n_words': 383}