Skip to content

Commit

Permalink
add check for surrounding pixels in line crossing function
Browse files Browse the repository at this point in the history
  • Loading branch information
Alpaca-zip committed Dec 12, 2023
1 parent 762a0ad commit fad821e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Binary file modified map/vgraph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion scripts/vgraph_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def draw_lines_between_corners(self, image, corners):
return rgb_image

def check_line_crossing(self, image, start, end):
start_pixels = self.get_surrounding_pixels(start)
end_pixels = self.get_surrounding_pixels(end)
x0, y0 = start
x1, y1 = end
dx = abs(x1 - x0)
Expand All @@ -103,7 +105,7 @@ def check_line_crossing(self, image, start, end):
not_all_white = False
is_horizontal_or_vertical = x0 == x1 or y0 == y1
while True:
if (x, y) != start and (x, y) != end:
if (x, y) not in start_pixels and (x, y) not in end_pixels:
pixel = image.getpixel((x, y))
if pixel != 0:
not_all_black = True
Expand Down Expand Up @@ -136,6 +138,14 @@ def check_line_crossing(self, image, start, end):
if not is_horizontal_or_vertical:
not_all_black = True
return not_all_black and not_all_white

def get_surrounding_pixels(self, point):
x, y = point
pixels = []
for i in range(-1, 2):
for j in range(-1, 2):
pixels.append((x + i, y + j))
return pixels


def main():
Expand Down

0 comments on commit fad821e

Please sign in to comment.