示例#1
0
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
示例#2
0
def test_single_pixel():
    pixels = render(
        xs=np.array([0.5]),
        ys=np.array([0.5]),
        x_min=0,
        y_min=0,
        x_max=1,
        y_max=1,
        width=1,
        height=1,
    )

    desired_pixels = np.array([[1]])
    np.testing.assert_array_equal(pixels, desired_pixels)
示例#3
0
def test_empty_plot():
    pixels = render(
        xs=np.array([]),
        ys=np.array([]),
        x_min=0,
        y_min=0,
        x_max=1,
        y_max=1,
        width=2,
        height=1,
    )

    desired_pixels = np.array([[0, 0]])
    np.testing.assert_array_equal(pixels, desired_pixels)
示例#4
0
def test_diagonal():
    pixels = render(
        xs=np.array([1, 2]),
        ys=np.array([1, 2]),
        x_min=1,
        y_min=1,
        x_max=2.1,
        y_max=2.1,
        width=2,
        height=2,
    )

    desired_pixels = np.array([[0, 1], [1, 0]])
    np.testing.assert_array_equal(pixels, desired_pixels)
示例#5
0
def test_diagonal_in_bigger_window():
    pixels = render(
        xs=np.array([1, 2]),
        ys=np.array([1, 2]),
        x_min=1,
        y_min=1,
        x_max=2.1,
        y_max=2.1,
        width=5,
        height=3,
    )

    desired_pixels = np.array([[0, 0, 0, 0, 1], [0, 0, 0, 0, 0],
                               [1, 0, 0, 0, 0]])
    np.testing.assert_array_equal(pixels, desired_pixels)
示例#6
0
def test_backward_line_with_shallow_downward_slope():
    pixels = render(
        xs=np.flip(np.array([1, 20])),
        ys=np.flip(np.array([200, 1])),
        x_min=1,
        y_min=1,
        x_max=20.1,
        y_max=200.1,
        width=4,
        height=2,
        lines=True,
    )

    desired_pixels = np.array([[1, 1, 0, 0], [0, 0, 1, 1]])
    np.testing.assert_array_equal(pixels, desired_pixels)
示例#7
0
def test_backward_line_with_steep_upward_slope():
    pixels = render(
        xs=np.flip(np.array([1, 20])),
        ys=np.flip(np.array([1, 200])),
        x_min=1,
        y_min=1,
        x_max=20.1,
        y_max=200.1,
        width=2,
        height=4,
        lines=True,
    )

    desired_pixels = np.array([[0, 1], [0, 1], [1, 0], [1, 0]])
    np.testing.assert_array_equal(pixels, desired_pixels)
示例#8
0
def test_forward_line_with_shallow_upward_slope():
    pixels = render(
        xs=np.array([1, 20]),
        ys=np.array([1, 200]),
        x_min=1,
        y_min=1,
        x_max=20.1,
        y_max=200.1,
        width=4,
        height=2,
        lines=True,
    )

    desired_pixels = np.array([[0, 0, 1, 1], [1, 1, 0, 0]])
    np.testing.assert_array_equal(pixels, desired_pixels)
示例#9
0
def test_vertical_line():
    pixels = render(
        xs=np.array([1, 1]),
        ys=np.array([1, 2]),
        x_min=1,
        y_min=1,
        x_max=2.1,
        y_max=2.1,
        width=2,
        height=4,
        lines=True,
    )

    desired_pixels = np.array([[1, 0], [1, 0], [1, 0], [1, 0]])
    np.testing.assert_array_equal(pixels, desired_pixels)
示例#10
0
def test_horizontal_line():
    pixels = render(
        xs=np.array([1, 2]),
        ys=np.array([1, 1]),
        x_min=1,
        y_min=1,
        x_max=2.1,
        y_max=2.1,
        width=5,
        height=3,
        lines=True,
    )

    desired_pixels = np.array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0],
                               [1, 1, 1, 1, 1]])
    np.testing.assert_array_equal(pixels, desired_pixels)
示例#11
0
def test_lines_outside_of_the_field_of_view():
    pixels = render(
        xs=np.array([1, 3, 2, 1]),
        ys=np.array([1, 1, 2, 1]),
        x_min=1.9,
        y_min=1.5,
        x_max=2.1,
        y_max=1.51,
        width=5,
        height=3,
        lines=True,
    )

    desired_pixels = np.array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0],
                               [0, 0, 0, 0, 0]])
    np.testing.assert_array_equal(pixels, desired_pixels)
示例#12
0
def test_draw_triangular_line():
    pixels = render(
        xs=np.array([1, 3, 2, 1]),
        ys=np.array([1, 1, 2, 1]),
        x_min=1,
        y_min=1,
        x_max=3.01,
        y_max=2.01,
        width=5,
        height=3,
        lines=True,
    )

    desired_pixels = np.array([
        [0, 0, 1, 0, 0],
        [0, 1, 0, 1, 0],
        [1, 1, 1, 1, 1],
    ])
    np.testing.assert_array_equal(pixels, desired_pixels)
示例#13
0
def test_no_mysterious_extra_vertical_lines():
    """
    This test is to make sure that issue #2 is fixed.
    """
    width = 60
    height = 17
    pixels = render(
        xs=np.array([1, 1]),
        ys=np.array([0, 1]),
        x_min=3,
        y_min=0,
        x_max=6,
        y_max=1.1,
        width=width,
        height=height,
        lines=True,
    )

    desired_pixels = np.zeros((height, width), dtype=int)
    np.testing.assert_array_equal(pixels, desired_pixels)
示例#14
0
def test_lines_with_steep_ends_due_to_point_near_pixel_edges():
    pixels = render(
        xs=np.array([1.99, 3.01]),
        ys=np.array([1.01, 3.99]),
        x_min=0,
        y_min=0,
        x_max=5,
        y_max=5,
        width=5,
        height=5,
        lines=True,
    )

    # Despite the fact that we extend the lines to the end points (see issue #4), we
    # do not wish there to be extensions beyond the end points.
    desired_pixels = np.array([
        [0, 0, 0, 0, 0],
        [0, 0, 0, 1, 0],
        [0, 0, 1, 0, 0],
        [0, 1, 0, 0, 0],
        [0, 0, 0, 0, 0],
    ])
    np.testing.assert_array_equal(pixels, desired_pixels)