The companion post, in German, is about what bubatzblick.de shows: the area, anywhere in Germany, where public cannabis consumption is banned because a school, playground, youth facility, sports ground or cultivation association can be seen from there. § 5 KCanG, the German cannabis act, makes 100 m the upper bound of "within sight". This post is about how that area is computed, including the method I built first and then threw away.
Shadow cones
The input for one facility is its outline, the source, and the buildings around it. The zone is everything within reach that can be seen from at least one point of the source; what the buildings hide from every point of the source is the umbra. To keep the geometry simple, the shadow-cone method replaced the source by its convex hull and split the buildings into convex pieces.
For an observer point p outside a convex obstacle O, take the two vertices of O that are tangent from p and build the cone behind them. My shadow() deliberately returned only a subset of that cone: the wedge between the tangent chord and the back of the obstacle is missing, but it lies inside the building anyway. A subset means a smaller umbra, a smaller umbra means a larger zone, and a larger zone is the safe direction. umbra() intersected those cones over the hull vertices of the source; visible_region() was the complement of the union over all obstacles.
For every step I had an argument that the zone could come out too big but never too small, and that is why the method looked right.
What is actually wrong with it is a quantifier. The construction only removes area that one single obstacle hides from the entire source. Around the playground I tested it on there were 112 buildings, and almost nothing qualified. A point behind a row of houses is typically hidden from one end of the playground by one house and from the other end by the next, so no single obstacle hides it from the whole source, and it stays in the zone. Splitting the buildings into convex pieces makes this worse, because each piece hides less than the whole building.
How I found out
I picked a street in Düsseldorf and set up an acceptance test for the program:
Let's pick some region, […], and you show me your current result of the program rendered in red. Then I take a painting program and draw in blue the area that is not supposed to be red.
In my picture only the narrow street corridors stayed red, in the shape of a star, and everything behind the houses was blue. At that time the program still computed out to 250 m, in seven bands, because the map had a slider for the distance. Measured on one playground of 685 m² over that whole reach, the zone came to 81,390 m² instead of 13,548 m², a factor of six. On other objects it went up to 8.7.
I measured two repairs before giving up on the method. Decomposing the source into finer, 2 m pieces took 11 s and still came out 1.98× too large. Eroding the obstacles gave factors between 3.5× and 13×, so it was no improvement.
The replacement
The construction I switched to is the one from Oliver Kleisch's bachelor's thesis („2D-Sichtbarkeit anhand von Gebäudekonturen aus Openstreetmaps", Heinrich-Heine-Universität Düsseldorf, June 2025, in German; I was the first examiner): put observer points along the whole contour of the object, compute an exact visibility polygon per point against the surrounding buildings, union them, and enlarge the result slightly outwards.

The thesis computes each polygon by triangular expansion after Bungiu, Hemmer, Hershberger, Huang and Kröller (2014), in its own implementation, which it benchmarked against the scikit-geometry library. I used a rotational sweep instead: sort the obstacle endpoints by angle, sweep the full circle with a distance-ordered set of active edges, O(n log n) per point. For many points in the same scene that was the simpler choice, and one I could check bit for bit against two independent reference implementations.
The switch has a price: I no longer have a proof that the zone is conservative. What I have instead is a test. At production spacing plus margin, the result has to cover the union computed at four times that density with no margin at all:
#[test]
fn zone_covers_four_times_denser_sampling() {
// Das Ergebnis bei Produktionsdichte (0,5 m + Marge) deckt die Vereinigung
// der Punktpolygone bei vierfacher Dichte OHNE Marge ab. Schranke relativ
// (1e-4), weil dichtere Punkte eine NEUE Punktmenge sind, keine Verfeinerung.
let cfg = cfg();
for name in ["mittel", "gross"] {
let (source, obstacles) = fixture(name);
let z = zone(&cfg, &source, &obstacles);
let dense_points = crate::sample::sample_contour(&source, 0.125, 128, 4096);
let rings: Vec<Vec<[f64; 2]>> = obstacles.iter().flatten().cloned().collect();
let b = bounds(&source);
let reach = cfg.effective_reach_m();
let dense = bubatzcore::visible_region(
&rings,
reach,
reach + (b[2] - b[0]).hypot(b[3] - b[1]),
&dense_points,
&source,
&free(&cfg, &source),
0.0,
bubatzcore::ROUND_STEP_QUAD_SEGS_16,
bubatzcore::DEFAULT_CHUNK,
);
let missed = area_outside(&dense, &z);
let limit = (1e-4 * shapes_area(&dense)).max(1.0);
assert!(
missed < limit,
"{name}: {missed:.3} m2 der dichteren Rechnung fehlen (Grenze {limit:.1})"
);
}
}Five more tests cover the rest: the zone contains its source and the building-free circle, the margin only grows it, additional obstacles never grow it, the output is deterministic to the byte, and it is invariant under rigid motion. The playground in the figure above, a different one from the paint test, is the anchor of the contract test: osm_id 29359108, 1,058 m², 281 observer points, 8,461 m² within 100 m, checked at every publish.
The Rust port
Two days after the method change I ported the pipeline, then still in Python, to Rust, with byte identity as the acceptance criterion. The first full zones run over Düsseldorf hit it: all 22,068 bands were identical to the Python output. Measured by wall-clock time it was barely faster, 122 s against Python's 131 s, but it ran as one process at 1.9 GB RSS where Python needed sixteen, and the binary was 15 MB, dynamically linked against the C runtime and nothing else. A later rebuild got the pipeline under 8 GB of memory, with the 39 million buildings in a file on disk instead of an in-memory R-tree, which is why it runs on a small server. Sweep rings now go into i_overlay directly rather than through Shapely's buffer(0), which used to drop one lobe of a ring that crosses itself.
I removed the Python pipeline on 14 September. What stayed is mainly sampling_ref.py, an independent reference implementation of the sweep that the Rust version is tested against. It is 108 times slower than the Python sweep that was checked against it in September, which does not matter for a reference. The code is AGPL-3.0-or-later and on GitHub.
What the model did, and what it did not
I built this with Claude, and every commit in the repository says so. The division of labour was sharp enough to be worth stating.
It was good at rebuilding something that already existed: the same computation expressed differently, the way one rewrites pandas into polars, or a loop into vectorised form. "Now do this in Rust" and "make it run in two gigabytes" are tasks of that kind, and both of them are in this post — the port that came out byte-identical on all 22,068 bands and ran as one process at 1.9 GB, and the later rebuild that put the 39 million buildings on disk so the whole pipeline fits in 8 GB. In each case I knew the thing was possible before I asked for it.
What it did not do is find the method. The shadow-cone construction and the quantifier that was wrong with it, the acceptance test with the paint program, the decision to take the thesis's geometry and to put a test where the proof had been — that part was mine, and it is the part this post is about. The same holds for the interface: on questions of style the model was no help, and the map looks the way it does because I decided it should.
Why it has its own domain
There is also a reason this runs on its own domain and its own small server rather than living as a page somewhere: I wanted the practice. A daily job pulls the Geofabrik diffs and recomputes only what changed. The tiles go out as a single PMTiles file that the browser reads by HTTP range requests. A release is held back when the anchor object's area moves by more than 2 %. The CI checks that rebuilding the generated pages produces no diff. The access log is condensed every night into a statistics page. Writing the algorithm and keeping it running every day on four vCPUs are different skills, and I had less of the second. The map's technical page spells the whole pipeline out, in German. Your browser can probably translate that just fine for you.
What it cost, and one external measure
The method change cost a factor of about ten in compute. The shadow-cone run over Germany had taken 5 h 51 min; the first projection for the new geometry, still in Python, was 54 to 62 hours. The Rust port and cutting back from seven bands up to 250 m to the single 100 m band the law names brought that to 1 h 56 min on 14 threads of a Ryzen 7 5700X, or 4 h 45 min on the server's four vCPUs. Daily updates do not pay that price: every zone carries a BLAKE2b key over its contour, the obstacles in range and the parameter version, and on a normal day about 0.1 % of objects need recomputing.

The one number here that does not come out of my own code is from the thesis. For Düsseldorf it reports 44.34 km² of visibility area against 57.41 km² for plain 100 m circles. My own objects are a different set, so the comparable quantity is the share rather than the area:
Düsseldorf | 100 m circles | method | share |
|---|---|---|---|
the thesis | 57.41 km² | 44.34 km² | 77.2 % |
my run, shadow cones | 62.20 km² | 50.97 km² | 81.9 % |
my run, visibility polygons | 62.20 km² | 41.51 km² | 66.7 % |
The factor of six from the paint test does not reappear here, and both are right: that was one object in dense housing, measured out to 250 m, while the table compares only what lies within 100 m, over the union of all objects in the city. Before the switch to a single band I used the share as a smoke test, with 60–80 % written down as plausible, about 82 % as the signature of shadow cones, and below about 55 % as a sign of zones too small to ship. I have not measured that share for Düsseldorf again since; for North Rhine-Westphalia it came out at 73.8 % under the current parameters. The zone area itself has been measured again, against the city's administrative area rather than against circles: 40 km² of Düsseldorf's 217 km², every spot counted once.
