Remove duplicate pack_rectangles
|
Before Width: | Height: | Size: 89 B After Width: | Height: | Size: 255 B |
|
Before Width: | Height: | Size: 114 B After Width: | Height: | Size: 311 B |
|
Before Width: | Height: | Size: 191 B After Width: | Height: | Size: 972 B |
|
Before Width: | Height: | Size: 563 B After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 77 B After Width: | Height: | Size: 269 B |
|
Before Width: | Height: | Size: 746 B After Width: | Height: | Size: 825 B |
|
Before Width: | Height: | Size: 89 B After Width: | Height: | Size: 604 B |
|
Before Width: | Height: | Size: 107 B After Width: | Height: | Size: 540 B |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 89 B After Width: | Height: | Size: 292 B |
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 569 B After Width: | Height: | Size: 354 B |
|
Before Width: | Height: | Size: 637 B After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 857 B After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 7.8 KiB |
|
Before Width: | Height: | Size: 120 B After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 376 B After Width: | Height: | Size: 101 B |
@@ -57,25 +57,6 @@ class Bin:
|
|||||||
self.grid[rect_y][rect_x] = False
|
self.grid[rect_y][rect_x] = False
|
||||||
|
|
||||||
|
|
||||||
def pack_rectangles(rectangles, grid):
|
|
||||||
rectangles = sorted(
|
|
||||||
rectangles, key=lambda r: r.width * r.height, reverse=True)
|
|
||||||
bins = [Bin(grid)]
|
|
||||||
|
|
||||||
for rectangle in rectangles:
|
|
||||||
for bin in bins:
|
|
||||||
if bin.place_rectangle(rectangle):
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
new_bin = Bin(grid)
|
|
||||||
if new_bin.place_rectangle(rectangle):
|
|
||||||
bins.append(new_bin)
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def generate_rectangle(min_width: int = 10, max_width: int = 25):
|
def generate_rectangle(min_width: int = 10, max_width: int = 25):
|
||||||
width = randint(min_width, max_width)
|
width = randint(min_width, max_width)
|
||||||
height = randint(min_width, max_width)
|
height = randint(min_width, max_width)
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ def world_maker():
|
|||||||
filter_smooth(
|
filter_smooth(
|
||||||
'./world_maker/data/heightmap_with_building.png', 2).save('./world_maker/data/heightmap_smooth.png')
|
'./world_maker/data/heightmap_with_building.png', 2).save('./world_maker/data/heightmap_smooth.png')
|
||||||
|
|
||||||
for i in range(5):
|
for i in range(10):
|
||||||
overide_map('./world_maker/data/heightmap_with_building.png',
|
overide_map('./world_maker/data/heightmap_with_building.png',
|
||||||
'./world_maker/data/building_moutain.png').save('./world_maker/data/heightmap_with_building.png')
|
'./world_maker/data/building_moutain.png').save('./world_maker/data/heightmap_with_building.png')
|
||||||
overide_map('./world_maker/data/heightmap_with_building.png',
|
overide_map('./world_maker/data/heightmap_with_building.png',
|
||||||
|
|||||||