Skip to content

systems lab / 05

Spatial Query Explorer

Ask which objects sit inside a rectangle, then make the answer cheaper by refusing to look where the answer cannot be.

milestone 01 · the brute-force baseline

First, the version that does no thinking at all

A range query asks a simple question: which objects lie inside this rectangle? The simplest correct answer tests every object, every time - and it is genuinely fast enough here. That matters, because a structure that skips work is only interesting once you can see exactly how much work there was to skip.

The field is clustered rather than evenly spread, so density varies by region. Drag a rectangle over a dense cluster and then over an empty corner: brute force does identical work for both. The quadtree, arriving in the next milestone, will not.

This field needs Canvas support. The bounds inputs and results table below expose the same query as text.
Drag to draw a query rectangle. Filled dots are inside it. The dashed centre lines mark the first split a quadtree would make.

225 of 800 objects fall inside the region at 120, 140, sized 200 by 200.

The seed, object count, and region travel in the URL, so a shared link rebuilds the identical field.

experiment controls

Choose a region to query

Drag on the field, pick a preset, or type exact bounds. All three write the same query - the numbers below are the keyboard equivalent of the drag, not a separate mode.

The scatter is clustered, not uniform, so density varies by region.

Preset regions
Query bounds, in world units (0-1000)

measured · your browser

How long does the baseline actually take?

Unlike the counts beside this panel, these numbers come from your machine, so they change between runs, browsers, and devices. Nothing is measured until you ask - a benchmark that runs on every keystroke is a benchmark nobody should trust.

Not measured yet.

simulated · brute force

What the query found

Every count here is simulated: it is produced by this lab's own model and is exactly reproducible from the seed, on any machine. The wall-clock figures in the measurement panel are not - those come from your browser and will differ from mine.

Objects tested
800
Results found
225
Region
120, 140 · 200×200
Cells pruned
none - no tree yet

Brute force tests every object regardless of where the region sits. That is the baseline the quadtree has to beat.

Objects inside the query region, showing the first 50 of 225
Objectxy
#1157.5336.0
#2184.8267.8
#4270.1189.2
#7294.7292.3
#8289.5308.5
#10233.4169.1
#16136.2320.6
#25262.0198.0
#28279.2284.1
#31235.0309.6
#33125.8277.1
#34226.1167.5
#38195.6220.3
#45269.4305.7
#48292.6295.1
#52206.4221.8
#55261.7152.1
#57207.6205.4
#64209.3220.3
#67204.9230.1
#71135.2301.6
#77309.3202.1
#79287.3158.5
#83212.0255.6
#85274.1165.8
#89271.7328.5
#94221.6259.3
#95178.1176.1
#96268.9335.4
#101193.0226.5
#111179.3263.0
#112202.4228.4
#114144.9246.3
#115205.4158.2
#118254.1155.4
#131231.9284.4
#135169.6254.2
#139143.7161.2
#142207.1249.4
#143221.1227.4
#145250.7333.3
#146213.7321.4
#152188.8169.9
#153267.5177.7
#154165.3302.8
#158214.1307.0
#160130.4285.5
#163190.9223.0
#164225.6228.4
#166278.2302.1

Showing the first 50 of 225 results.

What arrives next

The quadtree itself: a tree of Cells, each responsible for a square Region, splitting into four children once it exceeds its Capacity. A range query then walks that tree and declines to open any Cell whose Region cannot intersect the rectangle - the pruning this lab exists to show. The measurement panel above already reports the baseline honestly, over a batch rather than a single run, because a single query here finishes far too fast to time truthfully. Once the tree can answer the same question, both go through that identical harness and the comparison means something.