Ejemplo n.º 1
0
    def transform_coordinates(self):
        coord_aux = build_homogeneous_coordinates(self.coordinates)
        coord_aux = multiply_coordinates_by_transformations(
            coord_aux, self.window_transformations)
        for (code, params) in self.transformations_codes:
            t_aux = []
            if self.needs_translation(code):
                if code in ["rt"]:
                    if len(params[1]) > 0:
                        translate_x, translate_y, translate_z = normalize_point(
                            params[1], self.window_width / 2,
                            self.window_height / 2)
                    else:

                        (
                            translate_x,
                            translate_y,
                            translate_z,
                            _,
                        ) = calculate_object_center(coord_aux)
                    params = [params[0]] * 3
                else:
                    (
                        translate_x,
                        translate_y,
                        translate_z,
                        _,
                    ) = calculate_object_center(coord_aux)
                t_aux.append(transformations_functions_dict["tr"](
                    -translate_x, -translate_y, -translate_z))
                t_aux.append(transformations_functions_dict[code](*params))
                t_aux.append(transformations_functions_dict["tr"](translate_x,
                                                                  translate_y,
                                                                  translate_z))
            else:
                if code == "tr":
                    x_normalized, y_normalized, z_normalized = normalize_point(
                        params, self.window_width / 2, self.window_height / 2)
                    params = [x_normalized, y_normalized, z_normalized]
                t_aux.append(transformations_functions_dict[code](*params))

            composition_matrix = reduce(np.dot, t_aux)
            coord_aux = multiply_coordinates_by_transformations(
                coord_aux, composition_matrix)

        # self.center = calculate_object_center(coord_aux)
        # Remove last column and map the points to tuple
        self.transformed_coordinates = list(map(tuple, coord_aux[:, :-1]))
Ejemplo n.º 2
0
def test_point_normalization_over_boundaries():
    point = (X_MAX_TRANSLATED * 1000, Y_MAX_TRANSLATED * -1000)
    expected_result = (1, -1)
    normalized = normalize_point(point)
    assert normalized == expected_result
Ejemplo n.º 3
0
def test_point_normalization_min():
    point = (X_MIN_TRANSLATED, Y_MIN_TRANSLATED)
    expected_result = (-1, -1)
    normalized = normalize_point(point)
    assert normalized == expected_result
Ejemplo n.º 4
0
def test_point_normalization_max():
    point = (X_MAX_TRANSLATED, Y_MAX_TRANSLATED)
    expected_result = (1, 1)
    normalized = normalize_point(point)
    assert normalized == expected_result
Ejemplo n.º 5
0
def test_point_normalization_zeros():
    point = (0, 0)
    expected_result = (0, 0)
    normalized = normalize_point(point)
    assert normalized == expected_result