Exemple #1
0
    def test_reflection_is_scaling_by_a_negative_value(self):
        transform = scaling(-1, 1, 1)
        point = Coordinates.point(2, 3, 4)

        result = transform * point

        assert result == Coordinates.point(-2, 3, 4)
Exemple #2
0
    def test_multiply_by_inverse_of_scaling_matrix(self):
        transform = scaling(2, 3, 4).inverse()
        vector = Coordinates.vector(-4, 6, 8)

        result = transform * vector

        assert result == Coordinates.vector(-2, 2, 2)
Exemple #3
0
    def test_scaling_matrix_applied_to_vector(self):
        transform = scaling(2, 3, 4)
        vector = Coordinates.vector(-4, 6, 8)

        result = transform * vector

        assert result == Coordinates.vector(-8, 18, 32)
Exemple #4
0
    def test_scaling_matrix_applied_to_point(self):
        transform = scaling(2, 3, 4)
        point = Coordinates.point(-4, 6, 8)

        result = transform * point

        assert result == Coordinates.point(-8, 18, 32)
Exemple #5
0
    def test_chaining_transformations_must_be_applied_in_reverse_order(self):
        point = Coordinates.point(1, 0, 1)
        rotate = rotation_x(radians(90))
        scale = scaling(5, 5, 5)
        translate = translation(10, 5, 7)

        transforms = translate * scale * rotate
        result = transforms * point

        assert result == Coordinates.point(15, 0, 7)
Exemple #6
0
    def test_individual_transformations_are_applied_in_sequence(self):
        point = Coordinates.point(1, 0, 1)
        rotate = rotation_x(radians(90))
        scale = scaling(5, 5, 5)
        translate = translation(10, 5, 7)

        rotated_point = rotate * point
        scaled_point = scale * rotated_point
        translated_point = translate * scaled_point

        assert rounded(rotated_point) == rounded(Coordinates.point(1, -1, 0))
        assert rounded(scaled_point) == rounded(Coordinates.point(5, -5, 0))
        assert translated_point == Coordinates.point(15, 0, 7)