# Algorithms
## 1. FastGrid (default)
Goal: maximize speed while preserving fill quality.
Key ideas:
- maintain a sampled candidate position pool instead of scanning all pixels every iteration
- use integral image checks for O(1) rectangle availability against stable mask state
- keep incremental pending-rect collision checks between integral rebuilds
Best for:
- medium/large canvases
- larger word lists
- production default
## 2. SpiralGreedy
Goal: produce visually coherent center-out layouts.
Key ideas:
- start from mask centroid
- search candidate positions along a spiral trajectory
- prefer larger font sizes first, then fallback
Best for:
- stable visual structure
- center-focused compositions
## 3. RandomBaseline
Goal: simple baseline for comparison and regression.
Key ideas:
- random point sampling from currently available mask area
- descending font-size fit check at each sampled point
Best for:
- algorithm A/B baseline
- correctness and compatibility checks
## 4. MCTS
Goal: use Monte Carlo search to pick stronger placements each step.
Key ideas:
- sample multiple candidate placements as root children
- run UCB-based selection and rollout simulation for each child
- choose the child with best estimated reward (usable-area gain)
Best for:
- quality-oriented generation
- scenarios where runtime can be traded for better packing decisions
## 5. SimulatedAnnealing
Goal: stochastic optimization with probabilistic acceptance.
Key ideas:
- sample valid placement candidates
- score candidates by area gain and word weight
- accept worse moves with temperature-dependent probability
Best for:
- escaping strict greedy behavior
- obtaining diverse layout outcomes under fixed constraints
## Rotation Support
v0.2 supports `0` and `90` degrees through style rotations.