Rectangle Decomposition Primer

Three strategies for handling overlapping 2D rectangles.

The Core Problem

When storing overlapping 2D rectangles, you must decide how to handle intersections. Three strategies exist with different trade-offs in insertion complexity, query complexity, and storage characteristics.

Strategy Comparison

Approach Insert Query Storage (example) Best for
LWW Simple Simple 2 ranges Single property only
Shallow Merge Complex Simple 4 ranges Properties always together
Spatial Join Simple Join 3 ranges (across 2 indexes) Independent properties

Strategy Details

1. Last-Writer-Wins (LWW)

New values replace old values in overlaps.

Use when: Single property per cell.

2. Shallow Merge

Merge object properties in overlaps using spread operator.

Use when: Properties always updated together.

3. Spatial Join

Separate index per property, combine at query time.

Use when: Properties updated independently.

Further Reading

Detailed strategy documentation: LWW, Shallow Merge, Spatial Join

This library: Implements LWW for single-property indexes. Multi-property use cases require Spatial Join pattern.

Implementation guides: README, PRODUCTION-GUIDE

Related Documentation

Academic basis: Rectangle decomposition (Guttman, 1984 R-trees), spatial join (Brinkhoff et al., 1993).