updated code in a few files to make it more understandable, also used .join method at a place to increase the speed.

这个提交包含在:
Sai-Suraj-27
2023-06-23 20:08:13 +05:30
父节点 c0762cc112
当前提交 7e4a4fff34
共有 7 个文件被更改,包括 30 次插入40 次删除

查看文件

@@ -36,12 +36,11 @@ def generate_y(p1, p2, x):
def paint_y_axis(lines, pixels, x):
is_black = False
target_ys = list(map(lambda line: int(generate_y(line[0], line[1], x)), lines))
target_ys.sort()
target_ys = sorted(
map(lambda line: int(generate_y(line[0], line[1], x)), lines)
)
if len(target_ys) % 2:
distances = []
for i in range(len(target_ys) - 1):
distances.append(target_ys[i+1] - target_ys[i])
distances = [target_ys[i+1] - target_ys[i] for i in range(len(target_ys) - 1)]
# https://stackoverflow.com/a/17952763
min_idx = -min((x, -i) for i, x in enumerate(distances))[1]
del target_ys[min_idx]
@@ -54,7 +53,7 @@ def paint_y_axis(lines, pixels, x):
pixels[target_y][x] = True
is_black = not is_black
yi = target_y
assert is_black is False, 'an error has occured at x%s' % x
assert is_black is False, f'an error has occured at x{x}'
def generate_line_events(line_list):

查看文件

@@ -1,3 +1,4 @@
import itertools
import multiprocessing as mp
import sys
@@ -90,10 +91,7 @@ def triangle_to_intersecting_lines(triangle, height, pixels, lines):
y = int(same[0][1])
pixels[y][x] = True
else:
cross_lines = []
for a in above:
for b in below:
cross_lines.append((b, a))
cross_lines = [(b, a) for a, b in itertools.product(above, below)]
side1 = where_line_crosses_z(cross_lines[0][0], cross_lines[0][1], height)
side2 = where_line_crosses_z(cross_lines[1][0], cross_lines[1][1], height)
lines.append((side1, side2))