<commit_before>from math import sqrt
from physical_object import *


G = 6.67300E-11


class PhysicsManager:
    def __init__(self):
        self.phyobjs = []

    def push(self, p):
        self.phyobjs.append(p)

    def calc_gravity_vector(self, pp):
        force = [0., 0.]
        for p in self.phyobjs:
            if p == pp:
                continue
            rdiff = [p.x - pp.x, p.y - pp.y]
            rdabs = sqrt(rdiff[0] ** 2 + rdiff[1] ** 2)
            runit = [r / rdabs for r in rdiff]
            coeff = G * p.mass * pp.mass / (rdabs ** 2)
            force[0] += -coeff * runit[0]
            force[1] += -coeff * runit[1]

    def tick(self):
        for p in self.phyobjs:
            p.forces['gravity'] = self.calc_gravity_vector(p)
        for p in self.phyobjs:
            tick(p)<commit_msg>updated physics manager : minimal working state<commit_after>from math import sqrt
from scipy.constants import gravitational_constant as G
from physical_object import *


"""
This entity contains and manages physical objects.
"""


class PhysicsManager:
    def __init__(self):
        """Initialize physics manager."""
        self.phyobjs = []

    def push(self, p):
        """
        Add a physical object to the model.

        :p: physical object
        """
        self.phyobjs.append(p)

    def calc_gravity_vector(self, pp):
        """
        Calculate the vector of gravity force for a particular physical object.

        :pp: physical object.

        :returns: force vector
        """
        force = [0., 0.]
        for p in self.phyobjs:
            if p == pp:
                continue
            r = [p.x - pp.x, p.y - pp.y]
            r_len = sqrt(r[0]*r[0] + r[1]*r[1])
            coeff = G * p.mass * pp.mass / (r_len ** 3)
            force[0] += coeff * r[0]
            force[1] += coeff * r[1]
        return force

    def tick(self):
        """Recomputing the forces and ticking all its elements."""
        for p in self.phyobjs:
            p.forces['gravity'] = self.calc_gravity_vector(p)
        for p in self.phyobjs:
            p.tick()
{'fraction_non_alphanumeric': 0.12066508313539193, 'fraction_numerical': 0.014251781472684086, 'mean_word_length': 1.7209302325581395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3182468', 'n_tokens_mistral': 700, 'n_tokens_neox': 659, 'n_words': 194}