<commit_before>// Copyright (c) 2014, Ӱ
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 
// * Redistributions of source code must retain the above copyright notice, this
//   list of conditions and the following disclaimer.
// 
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "stdafx.h"
#include "SphereManager.h"

#define LOGICAL_TIME_SPAN (0.5)
#define UPDATE_TIME_SPAN (50)

#define EPSILON (1e-13)

SphereManager::SphereManager()
	: m_PrevUpdateTime(GetTickCount()), m_day(0)
{
	m_quadric = gluNewQuadric();
	gluQuadricDrawStyle(m_quadric, GLU_FILL);
}

SphereManager::~SphereManager()
{
	gluDeleteQuadric(m_quadric);
}

void SphereManager::AddSphere(const Sphere &s)
{
	m_Spheres.push_back(s);
	m_Spheres.back().CompileDisplayList(m_quadric);
}

void SphereManager::UpdateIfExpired()
{
	DWORD span = GetTickCount() - m_PrevUpdateTime;
	if (span >= UPDATE_TIME_SPAN)
	{
		DWORD count = span / UPDATE_TIME_SPAN;
		m_PrevUpdateTime += count * UPDATE_TIME_SPAN;

#ifndef _DEBUG
		for (DWORD q = 0; q < count; q++)
#endif
		{
			Run();
		}
	}
}

void SphereManager::Run()
{
	std::vector<Sphere> NewSpheres = m_Spheres;

	RunForce(NewSpheres);
	RunCollision(NewSpheres);

	m_Spheres = std::move(NewSpheres);
	m_day += LOGICAL_TIME_SPAN;
}

void SphereManager::RunForce(std::vector<Sphere> &NewSpheres)
{
	// η  (SystemOfUnits.md )
	const double G = 0.49813678080;

	#pragma omp parallel for
	for (int i = 0; static_cast<size_t>(i) < m_Spheres.size(); i++)
	{
		Sphere &newsp = NewSpheres[i];

		// շ
		std::array<double, 3> sum_f = { 0, 0, 0 };

		//  ü Ʈ
		std::vector<int> ContactingSpheres;

		for (int j = 0; static_cast<size_t>(j) < m_Spheres.size(); j++)
		{
			if (i == j)
				continue;

			Sphere &sp2 = m_Spheres[j];

			std::array<double, 3> f = {
				sp2.coord[0] - newsp.coord[0],
				sp2.coord[1] - newsp.coord[1],
				sp2.coord[2] - newsp.coord[2],
			};

			double length_2 = dot_product(f, f);
			// ߷  շ¿ Ѳ 
			// G*F1 + G*F2 + ... = G*(F1 + F2 + ...)
			double SizeOfForce = /*G * */ newsp.mass * sp2.mass / length_2;

			double length = sqrt(length_2);
			f[0] *= SizeOfForce / length;
			f[1] *= SizeOfForce / length;
			f[2] *= SizeOfForce / length;<commit_msg>remove unnecessary variable<commit_after>// Copyright (c) 2014, Ӱ
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 
// * Redistributions of source code must retain the above copyright notice, this
//   list of conditions and the following disclaimer.
// 
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "stdafx.h"
#include "SphereManager.h"

#define LOGICAL_TIME_SPAN (0.5)
#define UPDATE_TIME_SPAN (50)

#define EPSILON (1e-13)

SphereManager::SphereManager()
	: m_PrevUpdateTime(GetTickCount()), m_day(0)
{
	m_quadric = gluNewQuadric();
	gluQuadricDrawStyle(m_quadric, GLU_FILL);
}

SphereManager::~SphereManager()
{
	gluDeleteQuadric(m_quadric);
}

void SphereManager::AddSphere(const Sphere &s)
{
	m_Spheres.push_back(s);
	m_Spheres.back().CompileDisplayList(m_quadric);
}

void SphereManager::UpdateIfExpired()
{
	DWORD span = GetTickCount() - m_PrevUpdateTime;
	if (span >= UPDATE_TIME_SPAN)
	{
		DWORD count = span / UPDATE_TIME_SPAN;
		m_PrevUpdateTime += count * UPDATE_TIME_SPAN;

#ifndef _DEBUG
		for (DWORD q = 0; q < count; q++)
#endif
		{
			Run();
		}
	}
}

void SphereManager::Run()
{
	std::vector<Sphere> NewSpheres = m_Spheres;

	RunForce(NewSpheres);
	RunCollision(NewSpheres);

	m_Spheres = std::move(NewSpheres);
	m_day += LOGICAL_TIME_SPAN;
}

void SphereManager::RunForce(std::vector<Sphere> &NewSpheres)
{
	// η  (SystemOfUnits.md )
	const double G = 0.49813678080;

	#pragma omp parallel for
	for (int i = 0; static_cast<size_t>(i) < m_Spheres.size(); i++)
	{
		Sphere &newsp = NewSpheres[i];

		// շ
		std::array<double, 3> sum_f = { 0, 0, 0 };

		for (int j = 0; static_cast<size_t>(j) < m_Spheres.size(); j++)
		{
			if (i == j)
				continue;

			Sphere &sp2 = m_Spheres[j];

			std::array<double, 3> f = {
				sp2.coord[0] - newsp.coord[0],
				sp2.coord[1] - newsp.coord[1],
				sp2.coord[2] - newsp.coord[2],
			};

			double length_2 = dot_product(f, f);
			// ߷  շ¿ Ѳ 
			// G*F1 + G*F2 + ... = G*(F1 + F2 + ...)
			double SizeOfForce = /*G * */ newsp.mass * sp2.mass / length_2;

			double length = sqrt(length_2);
			f[0] *= SizeOfForce / length;
			f[1] *= SizeOfForce / length;
			f[2] *= SizeOfForce / length;
{'fraction_non_alphanumeric': 0.1223396110855918, 'fraction_numerical': 0.01623028632674935, 'mean_word_length': 3.903903903903904, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 18, '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': '4706328', 'n_tokens_mistral': 2522, 'n_tokens_neox': 2212, 'n_words': 683}