def render_points(xs: List[np.array], ys: List[np.array], options: Options) -> np.array: for i in range(len(ys)): next_matrix = (i + 1) * pixel_matrix.render( xs=xs[i], ys=ys[i], x_min=options.x_min, x_max=options.x_max, y_min=options.y_min, y_max=options.y_max, # Unicode super-resolution :-) width=2 * options.width, height=2 * options.height, lines=options.lines[i], ) if i == 0: matrix = next_matrix else: matrix = pixel_matrix.merge_on_top( low_layer=matrix, high_layer=next_matrix, width=2 * options.width, height=2 * options.height, ) pixels = _init_character_matrix(width=options.width, height=options.height) for row in range(options.height): for col in range(options.width): pixels[row, col] = elements.character_for_2by2_pixels( matrix[2 * row:2 * row + 2, 2 * col:2 * col + 2], color_mode=options.color, ) return pixels
def test_merge_two_empty_pixel_matrices(): blank_pixels = np.array([[0, 0, 0], [0, 0, 0]]) result = merge_on_top(low_layer=blank_pixels, high_layer=blank_pixels, width=3, height=2) np.testing.assert_array_equal(result, blank_pixels)
def test_merge_with_empty_lower_layer(): some_pixels = np.array([[1, 0, 2], [0, 3, 4]]) blank_pixels = np.array([[0, 0, 0], [0, 0, 0]]) result = merge_on_top(low_layer=blank_pixels, high_layer=some_pixels, width=3, height=2) np.testing.assert_array_equal(result, some_pixels)
def test_merge_with_effective_shadow_small_patch(): high_layer = np.array([[2, 0, 0], [0, 0, 0]]) low_layer = np.array([[1, 1, 1], [1, 1, 1]]) desired_layer = np.array([[2, 0, 1], [0, 0, 1]]) result = merge_on_top(low_layer=low_layer, high_layer=high_layer, width=3, height=2, with_shadow=True) np.testing.assert_array_equal(result, desired_layer)
def test_merge_without_shadow_bigger_patch(): high_layer = np.array([ [0, 2, 0], [2, 0, 0], [0, 0, 0], ]) low_layer = np.array([ [0, 0, 1], [0, 1, 1], [1, 1, 1], ]) desired_layer = np.array([ [0, 2, 1], [2, 1, 1], [1, 1, 1], ]) result = merge_on_top(low_layer=low_layer, high_layer=high_layer, width=3, height=3, with_shadow=False) np.testing.assert_array_equal(result, desired_layer)