Fix : Height of building and better area taken by building

This commit is contained in:
NichiHachi
2024-06-23 05:47:12 +02:00
parent 5a4ca0a3f8
commit a9c0aceeb3
2 changed files with 30 additions and 13 deletions

View File

@@ -384,14 +384,16 @@ def rectangle_2D_to_3D(rectangle: list[tuple[tuple[int, int], tuple[int, int]]],
new_rectangle = []
for rect in rectangle:
start, end = rect
avg_height = 0
height = {}
for x in range(start[0], end[0]):
for y in range(start[1], end[1]):
avg_height += image.getpixel((x, y))
avg_height = int(
avg_height / ((end[0] - start[0]) * (end[1] - start[1]))) + 1
if image.getpixel((x, y)) not in height:
height[image.getpixel((x, y))] = 1
else:
height[image.getpixel((x, y))] += 1
max_height = max(height, key=height.get)
new_rectangle.append(
((start[0], avg_height, start[1]), (end[0], avg_height + randint(height_min, height_max), end[1])))
((start[0], max_height, start[1]), (end[0], max_height + randint(height_min, height_max), end[1])))
return new_rectangle