<commit_before>﻿using FastCollections;

namespace Lockstep
{
	/// <summary>
	/// Physics tool for
	/// </summary>
	public static class PhysicsTool
	{
		/// <summary>
		/// Finds all dynamic bodies touching a defined circle.
		/// </summary>
		/// <param name="radius">Radius.</param>
		/// <param name="output">Output.</param>
		public static void CircleCast(Vector2d position, long radius, FastList<LSBody> output)
		{
			long xMin = position.x - radius,
			xmax = position.x + radius;
			long yMin = position.y - radius,
			yMax = position.y + radius;

			//Find the partition tiles we have to search in first
			int gridXMin, gridXMax, gridYMin, gridYMax;
			Partition.GetGridBounds(xMin, xmax, yMin, yMax,
				out gridXMin, out gridXMax, out gridYMin, out gridYMax);


			for (int i = gridXMin; i <= gridXMax; i++)
			{
				for (int j = gridYMin; j <= gridYMax; j++)
				{
					PartitionNode node = Partition.GetNode(i, j);
					for (int k = node.ContainedDynamicObjects.Count; k >= 0; k--)
					{
						var body = PhysicsManager.SimObjects[node.ContainedDynamicObjects[k]];
						long minFastDist = body.Radius + radius;
						//unnormalized distance value for comparison
						minFastDist *= minFastDist;

						if (body.Position.FastDistance(position) <= minFastDist)
						{
							//Body touches circle!
							output.Add(body);
						}
					}
					for (int l = node.ContainedImmovableObjects.Count; l >= 0; l--)
					{
						var body = PhysicsManager.SimObjects[node.ContainedImmovableObjects[l]];
						long minFastDist = body.Radius + radius;
						//unnormalized distance value for comparison<commit_msg>Fix bug: Array index is out of range<commit_after>﻿using FastCollections;

namespace Lockstep
{
	/// <summary>
	/// Physics tool for
	/// </summary>
	public static class PhysicsTool
	{
		/// <summary>
		/// Finds all dynamic bodies touching a defined circle.
		/// </summary>
		/// <param name="radius">Radius.</param>
		/// <param name="output">Output.</param>
		public static void CircleCast(Vector2d position, long radius, FastList<LSBody> output)
		{
			long xMin = position.x - radius,
			xmax = position.x + radius;
			long yMin = position.y - radius,
			yMax = position.y + radius;

			//Find the partition tiles we have to search in first
			int gridXMin, gridXMax, gridYMin, gridYMax;
			Partition.GetGridBounds(xMin, xmax, yMin, yMax,
				out gridXMin, out gridXMax, out gridYMin, out gridYMax);


			for (int i = gridXMin; i <= gridXMax; i++)
			{
				for (int j = gridYMin; j <= gridYMax; j++)
				{
					PartitionNode node = Partition.GetNode(i, j);
					for (int k = node.ContainedDynamicObjects.Count - 1; k >= 0; --k)
					{
						var body = PhysicsManager.SimObjects[node.ContainedDynamicObjects[k]];
						long minFastDist = body.Radius + radius;
						//unnormalized distance value for comparison
						minFastDist *= minFastDist;

						if (body.Position.FastDistance(position) <= minFastDist)
						{
							//Body touches circle!
							output.Add(body);
						}
					}
					for (int l = node.ContainedImmovableObjects.Count - 1; l >= 0; l--)
					{
						var body = PhysicsManager.SimObjects[node.ContainedImmovableObjects[l]];
						long minFastDist = body.Radius + radius;
						//unnormalized distance value for comparison
{'fraction_non_alphanumeric': 0.1228177641653905, 'fraction_numerical': 0.002450229709035222, 'mean_word_length': 2.8696682464454977, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, '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': '3422636', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1016, 'n_words': 292}