예제 #1
0
 def apply(boids, bj):
     pcj = Vector()
     for b in boids:
         if b != bj:
             pcj.sum(b.position)
     pcj = pcj.div(len(boids) - 1)
     return pcj.minus(bj.position).div(100)
예제 #2
0
 def apply(boids, bj):
     pvj = Vector()
     for b in boids:
         if b != bj:
             pvj.sum(b.velocity)
     pvj.div(len(boids) - 1)
     return pvj.minus(bj.velocity).div(8)
예제 #3
0
    def test_sum(self):
        # Given
        vector = Vector()
        vector_to_sum = Vector(2, 3)

        expected_x = vector.x + vector_to_sum.x
        expected_y = vector.y + vector_to_sum.y

        # When
        vector.sum(vector_to_sum)

        # Then
        self.assertEquals(vector.x, expected_x)
        self.assertEquals(vector.y, expected_y)
예제 #4
0
def test_vector_sum_checks_shapes():
    """Shape rule: the vectors must be the same size."""
    Vector.sum(v, w, m, y)
예제 #5
0
def test_vector_sum():
    """vector_sum can take any number of vectors and add them together."""
    assert Vector.sum(v, w, u, y, z) == Vector([12, 26, 35])