Skip to content

Commit

Permalink
Fixes #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
olavolav committed Oct 9, 2020
1 parent af43093 commit 4ee3d70
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
22 changes: 22 additions & 0 deletions tests/unit/test_pixel_matrix.py
Expand Up @@ -131,6 +131,28 @@ def test_vertical_line():
np.testing.assert_array_equal(pixels, desired_pixels)


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)


def test_forward_line_with_steep_upward_slope():
pixels = render(
xs=np.array([1, 20]),
Expand Down
16 changes: 14 additions & 2 deletions uniplot/pixel_matrix.py
Expand Up @@ -45,6 +45,7 @@ def render(

if lines:
xys = np.column_stack((xs, ys))

# Compute all line segments as an array with entries of the shape:
# [
# [x_index_start, y_index_start],
Expand All @@ -60,7 +61,7 @@ def render(
xy_line_endpoints = xy_line_endpoints[
(
# At least one of the x coordinates of start and end need to be >= x_min
(xy_line_endpoints[:, 1, 0] < x_max)
(xy_line_endpoints[:, 1, 0] >= x_min)
| (xy_line_endpoints[:, 3, 0] >= x_min)
)
& (
Expand Down Expand Up @@ -122,7 +123,18 @@ def render(
step = 1
if y_index_stop < y_index_start:
step = -1
pixels[y_index_start:y_index_stop:step, x_index_start] = 1
# DEBUG
try:
pixels[y_index_start:y_index_stop:step, x_index_start] = 1
except:
print(
"PROBLEM: values:",
y_index_start,
y_index_stop,
step,
x_index_start,
)
raise
pixels_already_drawn = True
elif y_index_start == y_index_stop:
# That means it's a horizontal line
Expand Down

0 comments on commit 4ee3d70

Please sign in to comment.