Exemplo n.º 1
0
    def test_coordinates_addition(self):
        coord_1 = Coordinates(x=3, y=-2, z=5, w=1)
        coord_2 = Coordinates(x=-2, y=3, z=1, w=0)

        result = coord_1 + coord_2

        assert result == Coordinates(x=1, y=1, z=6, w=1)
Exemplo n.º 2
0
    def test_matrix_multiplication_to_coordinate(self):
        matrix = Matrix([[1, 2, 3, 4], [2, 4, 4, 2], [8, 6, 4, 1],
                         [0, 0, 0, 1]])
        coord = Coordinates(1, 2, 3, 1)

        result = matrix * coord

        assert result == Coordinates(18, 24, 33, 1)
Exemplo n.º 3
0
    def test_initialization(self):
        coordinates = Coordinates(x=1, y=2, z=3, w=4)

        assert coordinates.x == 1
        assert coordinates.y == 2
        assert coordinates.z == 3
        assert coordinates.w == 4
Exemplo n.º 4
0
    def test_idenity_matrix_mul_by_coordinates(self):
        identity_matrix = Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],
                                  [0, 0, 0, 1]])
        coord = Coordinates(1, 2, 3, 4)

        result = identity_matrix * coord

        assert result == coord
Exemplo n.º 5
0
    def _mul_matrix_by_coordinates(self, coord):
        data = []
        for row in self.data:
            total = reduce(
                lambda prev, curr: prev + curr[0] * curr[1],
                zip(row, coord),
                0,
            )
            data.append(total)

        return Coordinates(*data)
Exemplo n.º 6
0
    def test_multiplying_coordinates_by_fraction(self):
        coord = Coordinates(1, -2, 3, -4)

        result = coord * 0.5

        assert result == Coordinates(0.5, -1.0, 1.5, -2.0)
Exemplo n.º 7
0
    def test_multiplying_coordinate_by_scalar(self):
        coord = Coordinates(1, -2, 3, -4)

        result = coord * 3.5

        assert result == Coordinates(3.5, -7.0, 10.5, -14.0)
Exemplo n.º 8
0
    def test_negating_coordinates(self):
        coord = Coordinates(x=1, y=-2, z=3, w=-4)

        result = -coord

        assert result == Coordinates(x=-1, y=2, z=-3, w=4)
Exemplo n.º 9
0
    def test_is_vector(self):
        coordinates = Coordinates(x=0, y=0, z=0, w=0)

        assert not coordinates.is_point()
        assert coordinates.is_vector()
Exemplo n.º 10
0
    def test_dividing_coordinates_by_scalar(self):
        coord = Coordinates(1, -2, 3, -4)

        result = coord / 2

        assert result == Coordinates(0.5, -1.0, 1.5, -2.0)