PolyominoTools.jl - easy experimentation with polyominoes
PolyominoTools.jl is a lean and straightforward package to experiment with enumerating, joining, splitting and just playing around with these little blocks. Code and docs can be found on GitHub.
Origin story
I distilled this code from a research project, where I used polyominoes as a proxy for large, discrete search spaces. I realized that once the polyomino tooling was built, it is incredibly easy to start experimenting with different scenarios, so I built the core functionality into PolyominoTools.jl.
Philosophy
The package aims to be easy, lean and general-purpose, so anyone can pick it up. The only dependency is Makie, and it’s optional: you only need it for plotting.
Easy tooling
A polyomino can be built as follows:
using PolyominoTools
p = poly"""
###
"""
p1 = poly"""
##.
###
"""
You can then try to attach them to each other at a specified location and subsequently also split the result.
julia> attach(p, p1, (1, 2))
8-cell Polyomino (3×5):
..##.
..###
###..
Afterwards, you can find all unique splits up to symmetry:
julia> q = attach(p, p1, (1, 2));
julia> splits = unique_splits(q, symmetry = :full); # translation, rotation and mirroring
julia> length(splits)
10
julia> a, b, n = splits[1];
julia> b
7-cell Polyomino (3×4):
.##.
.###
##..
And visualizing your polyomino:
julia> using CairoMakie
julia> visualize_polyomino(q)
What could you use it for?
The package doesn’t assume a particular application, but provides the building blocks that keep coming back when working with polyominoes:
- Enumeration: generate fixed, one-sided or free n-ominoes, with canonical forms for reliable symmetry-aware comparison
- Attaching and splitting: join shapes at any offset, or list all unique ways to cut a shape into two connected parts, up to the symmetry you choose; handy for dissection problems or growth processes on the lattice
- Combinatorics and lattice animals: count shapes, classify them by symmetry, or sample them for statistical analysis
- Tiling and packing: use the shape operations as a base layer for tiling or packing problems
- Visualization: plot shapes and their decompositions with Makie
I’m curious what other people would do with it, so feel free to reply here with ideas, use cases or features you’d like to see. Issues and PRs on GitHub are very welcome too.
Installation
You can add PolyominoTools.jl to your project through the Julia package manager.
pkg> add PolyominoTools
