Example #1
0
    def test_distance(self):
        first = vec2(5, 3)
        second = vec2(7, 1)
        actual_distance = first.distance(second)
        expected_distance = first.copy.subtract(second).length

        self.assertEqual(actual_distance, expected_distance)
Example #2
0
    def test_subtract(self):
        first = vec2(5, 3)
        second = vec2(7, 1)
        actual_result = first.copy.subtract(second)

        expected_vector = vec2(first.x - second.x, first.y - second.y)
        self.__assert_vectors_equal(actual_result, expected_vector)
Example #3
0
    def test_add(self):
        first = vec2(1, 2)
        second = vec2(3, 4)
        actual_result = first.copy.add(second)

        expected_vector = vec2(first.x + second.x, first.y + second.y)
        self.__assert_vectors_equal(actual_result, expected_vector)
Example #4
0
    def test_line_line_intersect_no_intersection(self):
        expected_intersection = geometry.POINT_AT_INFINITY
        first_line = vec2(-10, -12), vec2(0, -5)
        second_line = vec2(15, 2), vec2(4, 3)

        are_intersected, intersection = geometry.line_line_intersect(
            first_line, second_line)
        self.assertFalse(are_intersected)
        self.assertEqual(intersection, expected_intersection)
Example #5
0
    def test_line_line_intersect(self):
        expected_intersection = vec2(0, 0)
        first_line = vec2(-1, 0), vec2(1, 0)
        second_line = vec2(0, -1), vec2(0, 1)

        are_intersected, intersection = geometry.line_line_intersect(
            first_line, second_line)
        self.assertTrue(are_intersected)
        self.assertTrue(expected_intersection.almost_equal(intersection))
Example #6
0
    def test_ray_intersect(self):
        result = geometry.ray_circle_intersect(
            (vec2(0, 0), vec2(0, 2)), (vec2(0, 3), 2))

        valid, actual_distance, actual_point = result

        expected_point = vec2(0, 1)
        expected_distance = 1
        self.assertTrue(valid)
        self.assertTrue(expected_point.almost_equal(actual_point))
        self.assertEqual(actual_distance, expected_distance)
Example #7
0
    def test_ray_intersect_not_intersected(self):
        result = geometry.ray_circle_intersect(
            (vec2(0, 0), vec2(2, 2)), (vec2(4, 10), 2))

        valid, actual_distance, actual_point = result

        expected_point = geometry.POINT_AT_INFINITY
        expected_distance = math.inf
        self.assertFalse(valid)
        self.assertEqual(actual_point, expected_point)
        self.assertEqual(actual_distance, expected_distance)
Example #8
0
    def test_circles_intersect_no_intersection(self):
        first_circle = vec2(5, 5), 3
        second_circle = vec2(-1, 4), 2

        self.assertFalse(geometry.circles_intersect(
            first_circle, second_circle))
Example #9
0
    def test_circles_intersect(self):
        first_circle = vec2(0, 1), 3
        second_circle = vec2(0, 4), 2

        self.assertTrue(geometry.circles_intersect(
            first_circle, second_circle))
Example #10
0
 def test_digestion(self, circle_intersect_mock):
     elements = [Food(vec2(1, 2), 1), ]
     digestion = Digestion(elements)
     circle_intersect_mock().return_value = True
Example #11
0
    def test_scale_to(self):
        vector = vec2(3, 4)
        actual_vector = vector.copy.scale_to(10)

        expected_vector = vec2(6, 8)
        self.__assert_vectors_equal(actual_vector, expected_vector)
Example #12
0
    def test_copy(self):
        vector = vec2(2, 3)
        copy = vector.copy

        self.__assert_vectors_equal(copy, vector)
Example #13
0
    def test_rotate(self):
        vector = vec2(3, 4)
        actual_vector = vector.copy.rotate(0.785398)

        expected_vector = vec2(-0.7071, 4.9497)
        self.__assert_vectors_equal(actual_vector, expected_vector)
Example #14
0
    def test_length(self):
        vector = vec2(3, 4)

        self.assertEqual(vector.length, 5)
Example #15
0
    def test_reverse(self):
        vector = vec2(5, 4)
        reversed_vector = vector.reverse

        expected_vector = vec2(-vector.x, -vector.y)
        self.__assert_vectors_equal(reversed_vector, expected_vector)