from .vector import Vector

class Body(object):
	def __init__(self, m, p=Vector(), v=Vector()):
		assert m > 0
		self.m = m
		self.forces = []
		self.p = p
		self.v = v
		self.a = Vector()
		self.space = None

	def apply_force(self, force):
		self.forces.append(force)

	def reset_forces(self):
		self.forces = []

	def update(self, dt):
		total_force = sum(self.forces, Vector())
		a = total_force / self.m

		d = self.v * dt + 1.0 / 2 * a * dt * dt
		self.v += a * dt
		self.p += d

		self.reset_forces()

	def __str__(self):
		return "Body(p=" + str(self.p) + ", v=" + str(self.v) + ")"
