Skip to content

Commit

Permalink
Merge pull request #10 from HexDecimal/frontend
Browse files Browse the repository at this point in the history
Frontend improvements.
  • Loading branch information
ikarth committed Mar 5, 2022
2 parents cb80edd + 90a5d6c commit 4921afb
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 349 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you want direct control over running WFC, call `wfc_control.execute_wfc()`.

The arguments it accepts are:

- `filename`: path to the input image file
- `filename=None`: path to the input image file, this is mostly for internal use and should be left as `None`, set `image` instead.
- `tile_size=1`: size of the tiles it uses (1 is fine for pixel images, larger is for things like a Super Metroid map)
- `pattern_width=2`: size of the patterns; usually 2 or 3 because bigger gets slower and
- `rotations=8`: how many reflections and/or rotations to use with the patterns
Expand All @@ -23,13 +23,14 @@ The arguments it accepts are:
- `output_periodic=True`: the output wraps at the edges
- `input_periodic=True`: the input wraps at the edges
- `loc_heuristic="entropy"`: what location heuristic to use; `entropy` is the original WFC behavior. The heuristics that are implemented are `lexical`, `hilbert`, `spiral`, `entropy`, `anti-entropy`, `simple`, `random`, but when in doubt stick with `entropy`.
- `choice_heuristic="lexical"`: what choice heuristic to use; `weighted` is the original WFC behavior.
- `visualize=True`: write intermediate images to disk?
- `choice_heuristic="weighted"`: what choice heuristic to use; `weighted` is the original WFC behavior, other options are `random`, `rarest`, and `lexical`.
- `visualize=False`: write intermediate images to disk? requires `filename`.
- `global_constraint=False`: what global constraint to use. Currently the only one implemented is `allpatterns`
- `backtracking=False`: do we use backtracking if we run into a contradiction?
- `log_filename="log"`: what should the log file be named?
- `logging=True`: should we write to a log file?
- `logging=False`: should we write to a log file? requires `filename`.
- `log_stats_to_output=None`
- `image`: an array of pixel data, typically in the shape: (height, width, rgb)

## Test

Expand Down
48 changes: 0 additions & 48 deletions tests/test_wfc_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,51 +160,3 @@ def explode(wave: NDArray[np.bool_]) -> bool:
happy = True

assert happy


def _test_recurse_vs_loop(resources: Resources) -> None:
# FIXME: run_recurse or run_loop do not exist anymore
filename = resources.get_image("samples/Red Maze.png")
img = imageio.imread(filename)
tile_size = 1
pattern_width = 2
periodic = False
output_size = [84, 84]
direction_offsets = list(enumerate([(0, -1), (1, 0), (0, 1), (-1, 0)]))
_tile_catalog, tile_grid, _code_list, _unique_tiles = wfc_tiles.make_tile_catalog(img, tile_size)
pattern_catalog, pattern_weights, pattern_list, pattern_grid = wfc_patterns.make_pattern_catalog(
tile_grid, pattern_width, periodic
)
adjacency_relations = wfc_adjacency.adjacency_extraction(
pattern_grid, pattern_catalog, direction_offsets
)
number_of_patterns = len(pattern_weights)
decode_patterns = {x: i for i, x in enumerate(pattern_list)}
adjacency_list: Dict[Tuple[int, int], List[Set[int]]] = {}
for i, d in direction_offsets:
adjacency_list[d] = [set() for i in pattern_weights]
for adj, p1, p2 in adjacency_relations:
adjacency_list[adj][decode_patterns[p1]].add(decode_patterns[p2])
wave = wfc_solver.makeWave(number_of_patterns, output_size[0], output_size[1])
adjacency_matrix = wfc_solver.makeAdj(adjacency_list)
solution_loop = wfc_solver.run(
wave.copy(),
adjacency_matrix,
locationHeuristic=wfc_solver.lexicalLocationHeuristic,
patternHeuristic=wfc_solver.lexicalPatternHeuristic,
periodic=True,
backtracking=False,
onChoice=None,
onBacktrack=None,
)
solution_recurse = wfc_solver.run_recurse( # type: ignore
wave.copy(),
adjacency_matrix,
locationHeuristic=wfc_solver.lexicalLocationHeuristic,
patternHeuristic=wfc_solver.lexicalPatternHeuristic,
periodic=True,
backtracking=False,
onChoice=None,
onBacktrack=None,
)
assert numpy.array_equiv(solution_loop, solution_recurse)
Loading

0 comments on commit 4921afb

Please sign in to comment.