sholloway / agents-playground

MIT License
4 stars 0 forks source link

BUG: HalfEdgeMesh.deep_copy() fails for some meshes #132

Closed sholloway closed 3 months ago

sholloway commented 4 months ago

Situation

On some meshes, deep_copy() fails due to exceeding recursion depth.

Recreate

The below code generates a randomized mesh that produces the issue.

import random
from agents_playground.spatial.coordinate import Coordinate

landscape_size_width: int = 10
landscape_size_length: int = 10
tiles: list[Coordinate] = []

# Distribute the tile elevations
tile_elevations: list[int] = random.choices(
  population=[0, 1, 2], 
  weights=[10,2,1], 
  k=landscape_size_width*landscape_size_length
)

tile_count = 0
for x in range(landscape_size_width):
  for z in range(landscape_size_length):
    tiles.append(Coordinate(x, tile_elevations[tile_count], z))
    tile_count += 1

for t in tiles:
  print(f'[{t[0]}, {t[1]}, {t[2]}, 3],')

This produces:

"tiles": [
    [0, 0, 0, 3],
    [0, 2, 1, 3],
    [0, 0, 2, 3],
    [0, 1, 3, 3],
    [0, 0, 4, 3],
    [0, 0, 5, 3],
    [0, 1, 6, 3],
    [0, 0, 7, 3],
    [0, 2, 8, 3],
    [0, 0, 9, 3],
    [1, 0, 0, 3],
    [1, 1, 1, 3],
    [1, 0, 2, 3],
    [1, 0, 3, 3],
    [1, 0, 4, 3],
    [1, 0, 5, 3],
    [1, 0, 6, 3],
    [1, 1, 7, 3],
    [1, 0, 8, 3],
    [1, 0, 9, 3],
    [2, 0, 0, 3],
    [2, 1, 1, 3],
    [2, 0, 2, 3],
    [2, 0, 3, 3],
    [2, 0, 4, 3],
    [2, 0, 5, 3],
    [2, 0, 6, 3],
    [2, 0, 7, 3],
    [2, 1, 8, 3],
    [2, 1, 9, 3],
    [3, 1, 0, 3],
    [3, 0, 1, 3],
    [3, 0, 2, 3],
    [3, 0, 3, 3],
    [3, 0, 4, 3],
    [3, 0, 5, 3],
    [3, 0, 6, 3],
    [3, 1, 7, 3],
    [3, 2, 8, 3],
    [3, 0, 9, 3],
    [4, 0, 0, 3],
    [4, 0, 1, 3],
    [4, 0, 2, 3],
    [4, 0, 3, 3],
    [4, 0, 4, 3],
    [4, 0, 5, 3],
    [4, 0, 6, 3],
    [4, 2, 7, 3],
    [4, 1, 8, 3],
    [4, 1, 9, 3],
    [5, 0, 0, 3],
    [5, 0, 1, 3],
    [5, 1, 2, 3],
    [5, 0, 3, 3],
    [5, 0, 4, 3],
    [5, 0, 5, 3],
    [5, 0, 6, 3],
    [5, 0, 7, 3],
    [5, 0, 8, 3],
    [5, 0, 9, 3],
    [6, 0, 0, 3],
    [6, 0, 1, 3],
    [6, 0, 2, 3],
    [6, 0, 3, 3],
    [6, 0, 4, 3],
    [6, 1, 5, 3],
    [6, 0, 6, 3],
    [6, 0, 7, 3],
    [6, 0, 8, 3],
    [6, 2, 9, 3],
    [7, 0, 0, 3],
    [7, 0, 1, 3],
    [7, 2, 2, 3],
    [7, 0, 3, 3],
    [7, 0, 4, 3],
    [7, 0, 5, 3],
    [7, 0, 6, 3],
    [7, 0, 7, 3],
    [7, 0, 8, 3],
    [7, 0, 9, 3]
  ]
sholloway commented 4 months ago

Possible Strategies