def test_mul_dot_vector(self): v1 = Vector(2, 2) v2 = Vector(1, 3) self.assertEqual(Vector(4, 4), v1 * 2) # really, OMG! swig rocks self.assertEqual(8, v1 * v2) self.assertEqual(8, v1.dot(v2))
def isBeClicked(self, x, y): l = (self.boundCircle.pos - Vector(x, y)).length() if l < self.boundCircle.radius: # be clicked, set v to zero self.velocity = Vector(0, 0) self.boundCircle.pos.point = (x, y) self.setUnMovable() return True return False
def test_vector_normalize(self): v1 = Vector(6, 8) normalize_v1 = v1.normalize() print(normalize_v1) # why get 0.600xxxx 0.800xxxx self.assertTrue(v1 == normalize_v1 * 10)
def test_isCollision(self): c1 = Circle(0, 0, 3) c2 = Circle(1, 1, 1) self.assertEqual(True, c1.isCollision(c2)) self.assertEqual(Vector(4, 4), c2.pos)
def update(self): dt = 1 if self.selectedObj: x, y = pygame.mouse.get_pos() self.selectedObj.velocity = Vector(x - self.x, y - self.y) self.x, self.y = x, y self.env.update(dt)
def forceInside(self, obj): if (obj.boundCircle.pos['x'] - obj.boundCircle.radius) < self._boundRegion.x: obj.boundCircle.pos[ 'x'] = self._boundRegion.x + obj.boundCircle.radius obj.velocity = obj.velocity.reflect(Vector(1, 0)) if (obj.boundCircle.pos['x'] + obj.boundCircle.radius) > self._boundRegion.width: obj.boundCircle.pos[ 'x'] = self._boundRegion.width - obj.boundCircle.radius obj.velocity = obj.velocity.reflect(Vector(1, 0)) if (obj.boundCircle.pos['y'] - obj.boundCircle.radius) < self._boundRegion.y: obj.boundCircle.pos[ 'y'] = self._boundRegion.y + obj.boundCircle.radius obj.velocity = obj.velocity.reflect(Vector(0, 1)) if (obj.boundCircle.pos['y'] + obj.boundCircle.radius) > self._boundRegion.height: obj.boundCircle.pos[ 'y'] = self._boundRegion.height - obj.boundCircle.radius obj.velocity = obj.velocity.reflect(Vector(0, 1))
def test_momentum(self): p = Particle(3, 4, 3, 4, 15) self.assertEqual(p.momentum, Vector(3, 4))
def test_call_vactor(self): v = Vector(5.3, 2.2) # call will return int value self.assertEqual(5, v()[0]) self.assertEqual(2, v()[1])
def test_setitem_vector(self): v = Vector(0, 3) v['x'] = 5 self.assertEqual(5, v['x'])
def test_getitem_vector(self): v = Vector(2, 3) self.assertEqual(2, v['x'])
def test_vector_reflect(self): v1 = Vector(1, 1) n = Vector(0, 1) self.assertEqual(Vector(1, -1), v1.reflect(n))
def __init__(self, x=0, y=0, vx=0.0, vy=0.0, size=0, mass=1): self.velocity = Vector(vx, vy) self.mass = mass self.boundCircle = Circle(x, y, size)
def test_vector_length(self): v1 = Vector(3, 4) self.assertEqual(v1.length(), 5)
def test_declare_vector(self): v1 = Vector(2, 3, 4) self.assertEqual(v1.x, 2) self.assertEqual(v1.y, 3) self.assertEqual(v1.z, 4)
def test_div_vector(self): v1 = Vector(5, 5) v2 = v1 / 3 self.assertEqual(v1 / 3, v2)
def test_sub_vector(self): v1 = Vector(2, 3) v2 = Vector(3, 4) v3 = Vector(5, 7) self.assertEqual(v1, v3 - v2)
def test_add_vector(self): v1 = Vector(2, 3) v2 = Vector(3, 4) v3 = Vector(5, 7) self.assertEqual(v1 + v2, v3)
def test_vector_neg(self): v1 = Vector(1, 1) self.assertEqual(Vector(-1, -1), -v1)
def test_create_Circle(self): c = Circle(2, 2, 3) self.assertEqual(Vector(2, 2), c.pos) self.assertEqual(3, c.radius)